net: wireless: add brcm80211 drivers
Hi Arend,
This code is not really new, but I thought I would email you anyway because I know you are responsive. :)
The patch 5b435de0d786: "net: wireless: add brcm80211 drivers" from Oct 5, 2011, leads to the following Smatch complaint:
drivers/net/wireless/brcm80211/brcmsmac/ampdu.c:741 brcms_c_sendampdu()
warn: variable dereferenced before check 'p' (see line 739)
drivers/net/wireless/brcm80211/brcmsmac/ampdu.c
733 /*
734 * check to see if the next pkt is
735 * a candidate for aggregation
736 */
737 p = pktq_ppeek(&qi->q, prec);
738 /* tx_info must be checked with current p */
739 tx_info = IEEE80211_SKB_CB(p);
^^^^^^^^^^^^^^^^"p" is dereferenced inside the call to IEEE80211_SKB_CB().
740
741 if (p) {
^^^Checked too late.
742 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
743 ((u8) (p->priority) == tid)) {regards,
dan carpenter
Quoted 4 lines · Dan Carpenter
Hi Arend,
This code is not really new, but I thought I would email you anyway because I know you are responsive. :)
Dito ;-)
Quoted 20 lines
The patch
5b435de0d786: "net: wireless: add brcm80211 drivers" from Oct 5, 2011, leads to the following Smatch complaint:
drivers/net/wireless/brcm80211/brcmsmac/ampdu.c:741brcms_c_sendampdu()
warn: variable dereferenced before check 'p' (see line 739)
drivers/net/wireless/brcm80211/brcmsmac/ampdu.c
733 /*734 * check to see if the next pkt is 735 * a candidate for aggregation 736 */ 737 p = pktq_ppeek(&qi->q, prec); 738 /* tx_info must be checked with current p */ 739 tx_info = IEEE80211_SKB_CB(p); ^^^^^^^^^^^^^^^^"p" is dereferenced inside the call to
IEEE80211_SKB_CB().740 741 if (p) { ^^^
Quoted 9 lines
Checked too late.
742 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && 743 ((u8) (p->priority) == tid)) {regards,
dan carpenter
Thanks for running smatch. I will look in the current code base and fix this. Just out of curiosity: Another static checker used regularly is Coccinelle. What are the pros and cons of smatch compared to Coccinelle?
Gr. AvS
Quoted 5 lines · Arend van Spriel
Thanks for running smatch. I will look in the current code base and fix this. Just out of curiosity: Another static checker used regularly is Coccinelle. What are the pros and cons of smatch compared to Coccinelle?
Gr. AvS
That's a tricky question because of my obvious bias as the author of Smatch, and I'm not an expert on Coccinelle. ;)
Smatch works on the preprocessed code and Coccinelle works on .c code. So some things are easier to check for in Coccinelle. I've generally found hacks to get the information I need in Smatch but sometimes it's gnarly. So a one liner in Coccinelle is twenty lines of code in Smatch which require in depth knowledge of Smatch and Sparse.
Smatch doesn't fix the bugs it finds.
The other advantage for Coccinelle is that you can run it on other architecture's code without setting up a cross compile environment.
What Smatch does that Coccinelle doesn't is that it tries to track the values of all the variables. This means you can detect array overflows, for example. Smatch tries to track values across function calls as well, with the recent database work.
That's really the long term goal of Smatch, to track the value of every variable in the kernel. But there is still a lot of work to do. :P
regards,
dan carpenter
Quoted 9 lines · Dan Carpenter
Quoted 5 lines · Arend van Spriel
Thanks for running smatch. I will look in the current code base and fix this. Just out of curiosity: Another static checker used regularly is Coccinelle. What are the pros and cons of smatch compared to Coccinelle?
Gr. AvS
That's a tricky question because of my obvious bias as the author of Smatch, and I'm not an expert on Coccinelle. ;)
;-)
Quoted 8 lines
Smatch works on the preprocessed code and Coccinelle works on .c code. So some things are easier to check for in Coccinelle. I've generally found hacks to get the information I need in Smatch but sometimes it's gnarly. So a one liner in Coccinelle is twenty lines of code in Smatch which require in depth knowledge of Smatch and Sparse.
Smatch doesn't fix the bugs it finds.
+1 for Coccinelle.
Quoted 7 lines
The other advantage for Coccinelle is that you can run it on other architecture's code without setting up a cross compile environment.
What Smatch does that Coccinelle doesn't is that it tries to track the values of all the variables. This means you can detect array overflows, for example. Smatch tries to track values across function calls as well, with the recent database work.
I guess Oracle knows a thing or two about databases.
Quoted 3 lines
That's really the long term goal of Smatch, to track the value of every variable in the kernel. But there is still a lot of work to do. :P
Enjoy and thanks for taking time to explain.
Gr. AvS
Quoted 8 lines · Arend van Spriel
Quoted 5 lines · Dan Carpenter
On Mon, May 14, 2012 at 09:07:55AM +0200, Arend van Spriel wrote:
What Smatch does that Coccinelle doesn't is that it tries to track the values of all the variables. This means you can detect array overflows, for example. Smatch tries to track values across function calls as well, with the recent database work.I guess Oracle knows a thing or two about databases.
Uh... It just puts all the information of how the functions are called into an sqlite3 database. Arg 3 is a number 0-9.
regards,
dan carpenter
Quoted 22 lines · Dan Carpenter
Quoted 5 lines · Arend van Spriel
Thanks for running smatch. I will look in the current code base and fix this. Just out of curiosity: Another static checker used regularly is Coccinelle. What are the pros and cons of smatch compared to Coccinelle?
Gr. AvS
That's a tricky question because of my obvious bias as the author of Smatch, and I'm not an expert on Coccinelle. ;)
Smatch works on the preprocessed code and Coccinelle works on .c code. So some things are easier to check for in Coccinelle. I've generally found hacks to get the information I need in Smatch but sometimes it's gnarly. So a one liner in Coccinelle is twenty lines of code in Smatch which require in depth knowledge of Smatch and Sparse.
Smatch doesn't fix the bugs it finds.
The other advantage for Coccinelle is that you can run it on other architecture's code without setting up a cross compile environment.
Quoted 8 lines
What Smatch does that Coccinelle doesn't is that it tries to track the values of all the variables. This means you can detect array overflows, for example. Smatch tries to track values across function calls as well, with the recent database work.
That's really the long term goal of Smatch, to track the value of every variable in the kernel. But there is still a lot of work to do. :P
That all seems accurate to me :)
julia