16-bit Checksum function in C
Since this checksum function is only used for TCP packets, there is no need for supporting packets larger than 65535 bytes. Rather than adding needless overflow checks, you should restrict the bytes parameter by making that a uint16_t.

Note that both the original code and your improvement only work on big endian implementations, unless some outside code byteswapped the whole TCP packet, in which case the code only works on little endian implementations. The + 1 for accessing the last byte makes the latter more probable. This + 1 was not present in the original code, so chances are high that you introduced a bug. Did you test with odd-sized packet length?

You should make the spacing of the code consistent, either by removing all spaces around binary operators (not recommended) or inserting spaces at the appropriate places. Currently it is a mixture of both.

Since you don't modify the incoming buffer, you should declare that. Make the data const void *.

You don't need to write 1 == bytes, since any decent compiler will emit a warning if you would ever accidentally use a single = here. You should write the natural bytes == 1 instead, or if you fear typos, bytes &gt; 0.

The bytes -= 1 is unnecessary and can be left out.