Page MenuHomeFreeBSD

Add missing function attributes and assert for refcount_acquire_if_not_zero() and refcount_acquire_if_not_last()
ClosedPublic

Authored by hselasky on Oct 19 2018, 1:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 2, 9:44 PM
Unknown Object (File)
Thu, May 2, 9:43 PM
Unknown Object (File)
Thu, May 2, 9:43 PM
Unknown Object (File)
Thu, May 2, 9:43 PM
Unknown Object (File)
Thu, May 2, 9:42 PM
Unknown Object (File)
Thu, May 2, 9:42 PM
Unknown Object (File)
Thu, May 2, 9:42 PM
Unknown Object (File)
Thu, May 2, 9:42 PM
Subscribers

Details

Summary

Make sure returned value is checked and assert a valid refcount.
While at it fix a print: Unsigned types cannot be negative.

MFC after: 1 week
Sponsored by: Mellanox Technologies

Diff Detail

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

Event Timeline

Make sure return value is checked.

there is already refcount_acquire_if_not_zero in the file

hselasky retitled this revision from Implement a refcount helper function which only increments the refcount when it is not zero. to Add missing function attributes and assert for refcount_acquire_if_not_zero().
hselasky edited the summary of this revision. (Show Details)

Update as per @mjg 's suggestion

sys/sys/refcount.h
85 ↗(On Diff #49312)

If acquire_if_nz gets the warning on unused result, then release_if_not_last should too ?

sys/sys/refcount.h
85 ↗(On Diff #49312)

agreed, some for the assertion. Somewhat related, would be good to do a test build with the annotation added to refcount_release. There are probably very few places where it makes sense to do it without checking and those can be covered with an extra variant (or perhaps a (void) cast will take care of it).

I think the return value of refcount_release() should also be checked, but I see many users in the kernel which don't check it.

hselasky retitled this revision from Add missing function attributes and assert for refcount_acquire_if_not_zero() to Add missing function attributes and assert for refcount_acquire_if_not_zero() and refcount_acquire_if_not_last().Oct 20 2018, 7:44 AM

So both you and mjg mentioned that there are a lot of consumers which do not check the result from release_if_not_last. How is it handled ?

sys/sys/refcount.h
107 ↗(On Diff #49327)

"zero refcount %p"

Update assert message, suggested by @kib .

@kib : Only refcount_release() can be called w/o checking the returned result, so I didn't add an attribute for that function. The others should be fine from what I can see.

sys/sys/refcount.h
107 ↗(On Diff #49327)

old cannot be negative. refcounts are unsigned.

This revision is now accepted and ready to land.Oct 22 2018, 10:21 AM
This revision was automatically updated to reflect the committed changes.