Page MenuHomeFreeBSD

Static analysis: Remove unnecessary check in IPv6 PKTOPT_EXTHDRCPY() macro
ClosedPublic

Authored by jtl on May 26 2017, 5:01 PM.
Tags
None
Referenced Files
F157559532: D10942.id.diff
Fri, May 22, 8:08 PM
Unknown Object (File)
Thu, May 21, 7:14 PM
Unknown Object (File)
Thu, May 21, 7:56 AM
Unknown Object (File)
Sat, May 16, 11:05 PM
Unknown Object (File)
Sat, May 2, 10:11 AM
Unknown Object (File)
Tue, Apr 28, 1:21 PM
Unknown Object (File)
Apr 15 2026, 7:56 PM
Unknown Object (File)
Apr 11 2026, 12:45 AM
Subscribers

Details

Summary

I ran clang's static analyzer over the kernel sources. It alerted on a check in the PKTOPT_EXTHDRCPY macro.

This macro allocates memory and, if malloc does not return NULL, copies data into the new memory. However, it doesn't just check that malloc did not return NULL, it also checks that we called malloc with M_NOWAIT. That is not necessary.

While it may be that malloc() will only return NULL when the M_NOWAIT flag is set, we don't need to check for this when checking the return value. Further, in this case, the check was not completely accurate, since it checked for flags == M_NOWAIT, rather than treating it as a bit field and checking for (flags & M_NOWAIT).

Therefore, this commit changes the check to simply check for whether malloc() returns NULL.

Sponsored by: Netflix
MFC after: 2 weeks

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable