-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libkmod: Simplify lookup_builtin_file() #233
Conversation
Tl:Dr: Longer version:
Objectively looking our On the subjective side - it's sad and annoying to remove a really cool feature. Personally, if Plus there is nothing blocking us from re-introducing it later on when scan-build gets wiser. |
I'm still of the opinion that scan-build needs to get wiser or we need to convince it of a proper way to understand it. Because it seems they are already even checking for improper use of the cleanup attribute. How the heck they don't understand what the attribute does? You are creating a chicken and egg situation: it doesn't get used more because of X and X doesn't improve because it's not used enough. When something is that dumb, I prefer to simply disable it and use something smarter to cover the same thing. We can simply disable the unix.Malloc check and rely on valgrind for that. Another alternative: try to convince the analyzer to stop bothering us with those false positives |
1fe52ac
to
b640350
Compare
I added a commit to shut up clang-analyzer on those specific case. I didn't finish moving the assignments to the declarations because I think I didn't try hard to convince clang-analyzer to shut up. Anyway, this seems better than "let's not use this and hope some day clang-analyzer will understand a 10+ year old feature". |
b640350
to
709fd1f
Compare
@evelikov not sure how useful those checks for leak are with clang-analyzer. Example of one place not using the attribute:
Basically it doesn't seem clang-analyzer understands the ownership transfer when we append to a list. |
Fully agree that clang-analyze should get wiser - yet again I'm just the messenger here. The chicken and egg seems valid if clang devs see kmod (plus other users like systemd) as moderate-high interest/priority project. Hope I don't sound like a cold-hearted a** here - trying to be realistic. Thanks for the At a glance it seems that the allocation needs to be annotated, not the variable declaration. While moving the assignment/allocation on declaration works, we cannot reliably use it where we don't know the size early "enough" since we explicitly ban declaration after statements. If we remove |
See the last commit with the fixup where I return it to where it was. The problem is, like I said, even with those it seems like the leak check in clang-analyzer is not smart enough and has other problems. To the point I think we'd be better off turning off that specific check. |
Move to macro.h where other attributes are located. The inline helper function can also move along as we don't need to keep it separate. Signed-off-by: Lucas De Marchi <[email protected]>
That attribute allows us to instruct the Clang Static Analyzer to stop giving some false positives. However when building the code (with gcc and clang) they warn that the attribute is ignored. Just ignore as we know what the attribute is for. Signed-off-by: Lucas De Marchi <[email protected]>
Apologies - had the reply written on the day before and didn't refresh/check before posting 🙇 Looking at the 23 mem leak reports we have:
Suspect we could "fix" the kmod_list ones although it'll be alot of churn. Plus there is a 10+ year old issue about the cleanup attribute with limited activity. So despite the legitimate catches, the noise is too much to have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thumbs up for reintroducing the _cleanup_free_
instance. The clang/suppress patch can be deferred for a day when the false-positives are fewer.
709fd1f
to
be0ca62
Compare
@evelikov I added a few more compat to attribute handling. I gave it a quick check on list of reported leaks with the clang-analyzer in my machine and I think this clears/hides all the cleanup-attribute-related ones. |
be0ca62
to
956a855
Compare
There are a few more, but I wouldn't worry about handling them all atm. As long as you mind a way to appease clang (ironically it clang 14 chokes on |
Yeah, I think I will just check for running with clang_analyzer and remove the attribute check. |
When using the cleanup attribute we know we are not leaking that allocation. Most of the time the assignment is together with the declaration, so we can simplify additional clang annotations by making the cleanup attribute imply clang::suppress. In cases declaration and assignment are not together, provide _clang_suppress_alloc_ to annotate the code. That is only defined for clang analyzer. Signed-off-by: Lucas De Marchi <[email protected]>
Use cleanup attribute. Signed-off-by: Lucas De Marchi <[email protected]>
Add the clang::suppress attribute to places where allocation is done and that rely on the cleanup attribute. Clang analyzer doesn't handle those (yet), so keep it from giving us false positive. Signed-off-by: Lucas De Marchi <[email protected]>
956a855
to
14ef049
Compare
Move to macro.h where other attributes are located. The inline helper function can also move along as we don't need to keep it separate. Signed-off-by: Lucas De Marchi <[email protected]> Link: #233
That attribute allows us to instruct the Clang Static Analyzer to stop giving some false positives. However when building the code (with gcc and clang) they warn that the attribute is ignored. Just ignore as we know what the attribute is for. Signed-off-by: Lucas De Marchi <[email protected]> Link: #233
When using the cleanup attribute we know we are not leaking that allocation. Most of the time the assignment is together with the declaration, so we can simplify additional clang annotations by making the cleanup attribute imply clang::suppress. In cases declaration and assignment are not together, provide _clang_suppress_alloc_ to annotate the code. That is only defined for clang analyzer. Signed-off-by: Lucas De Marchi <[email protected]> Link: #233
Use cleanup attribute. Signed-off-by: Lucas De Marchi <[email protected]> Link: #233
Add the clang::suppress attribute to places where allocation is done and that rely on the cleanup attribute. Clang analyzer doesn't handle those (yet), so keep it from giving us false positive. Signed-off-by: Lucas De Marchi <[email protected]> Link: #233
Applied, thanks |
Use cleanup attribute.