staging: wilc1000: merge 'if' statements that test the same condition
PATCH 1/1 staging: wilc1000: merge 'if' statements that test the same condition
Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.
--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +3 -5
@@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); +memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len);kfree (priv->wilc_ptk[key_index]->seq); -if (params->seq_len >0 ) +if (params->seq_len >0 ) { priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL ); - -memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len); - -if (params->seq_len >0 )memcpy (priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); + } priv->wilc_ptk[key_index]->cipher = params->cipher; priv->wilc_ptk[key_index]->key_len = params->key_len;
Signature · 1 line
2.7.4
Quoted 14 lines · Dafna Hirschfeld
Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.
Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +0
-0
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, · line 966
Quoted 5 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +1
-0@@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); +memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len);kfree (priv->wilc_ptk[key_index]->seq);
How about moving the memcpy up a line to be next to the kmalloc, and to be separated by a blank line from the kfree, which is on a different location.
These kmallocs should also have null tests to check for failure. That could be the first patch in the series with this patch being the second one. The missing null checks represent a small bug, and a bug should not depend on a cleanup.
julia
Quoted 23 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +2
-6-if (params->seq_len >0 ) +if (params->seq_len >0 ) { priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL ); - -memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len); - -if (params->seq_len >0 )memcpy (priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); + } priv->wilc_ptk[key_index]->cipher = params->cipher; priv->wilc_ptk[key_index]->key_len = params->key_len; --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224074733.GA6487%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 28 lines · Julia Lawall
Quoted 14 lines · Dafna Hirschfeld
Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.
Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +0
-0drivers/staging/wilc1000/wilc_wfi_cfgoperations.c static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, · line 966
Quoted 5 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +1
-0@@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); +memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len);kfree (priv->wilc_ptk[key_index]->seq);How about moving the memcpy up a line to be next to the kmalloc, and to be separated by a blank line from the kfree, which is on a different location.
Quoted 7 lines
These kmallocs should also have null tests to check for failure. That could be the first patch in the series with this patch being the second one. The missing null checks represent a small bug, and a bug should not depend on a cleanup.
julia
Hi, the file has about 17 calls to kmalloc that are not tested for null. Wouldn't it be better to fix all of them in a different patch?
Dafna
Quoted 23 lines
Quoted 23 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +2
-6-if (params->seq_len >0 ) +if (params->seq_len >0 ) { priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL ); - -memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len); - -if (params->seq_len >0 )memcpy (priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); + } priv->wilc_ptk[key_index]->cipher = params->cipher; priv->wilc_ptk[key_index]->key_len = params->key_len; --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224074733.GA6487%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 34 lines · Dafna Hirschfeld
Quoted 33 lines · Julia Lawall
Quoted 14 lines · Dafna Hirschfeld
Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.
Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +0
-0drivers/staging/wilc1000/wilc_wfi_cfgoperations.c static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, · line 966
Quoted 5 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +1
-0@@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); +memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len);kfree (priv->wilc_ptk[key_index]->seq);How about moving the memcpy up a line to be next to the kmalloc, and to be separated by a blank line from the kfree, which is on a different location.
These kmallocs should also have null tests to check for failure. That could be the first patch in the series with this patch being the second one. The missing null checks represent a small bug, and a bug should not depend on a cleanup.
Quoted 4 lines
Quoted 2 lines
julia
Hi, the file has about 17 calls to kmalloc that are not tested for null. Wouldn't it be better to fix all of them in a different patch?
Sure. It's just that your choices are either to wait for Greg to take one patch before taking the next, or put them in a series.
But maybe it would be just as well to get this one out of the way. The degree of difficulty is quite different, because to add error handlig code, you have to figure out how to handle the error. So that needs to be done slowly and carefully.
julia
Quoted 27 lines
Dafna
Quoted 23 lines
Quoted 23 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +2
-6-if (params->seq_len >0 ) +if (params->seq_len >0 ) { priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL ); - -memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len); - -if (params->seq_len >0 )memcpy (priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); + } priv->wilc_ptk[key_index]->cipher = params->cipher; priv->wilc_ptk[key_index]->key_len = params->key_len; --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224074733.GA6487%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 43 lines · Julia Lawall
Quoted 34 lines · Dafna Hirschfeld
Quoted 33 lines · Julia Lawall
Quoted 14 lines · Dafna Hirschfeld
Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.
Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +0
-0drivers/staging/wilc1000/wilc_wfi_cfgoperations.c static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, · line 966
Quoted 5 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +1
-0@@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); +memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len);kfree (priv->wilc_ptk[key_index]->seq);How about moving the memcpy up a line to be next to the kmalloc, and to be separated by a blank line from the kfree, which is on a different location.
These kmallocs should also have null tests to check for failure. That could be the first patch in the series with this patch being the second one. The missing null checks represent a small bug, and a bug should not depend on a cleanup.
Quoted 4 lines
Quoted 2 lines
julia
Hi, the file has about 17 calls to kmalloc that are not tested for null. Wouldn't it be better to fix all of them in a different patch?
Quoted 8 lines
Sure. It's just that your choices are either to wait for Greg to take one patch before taking the next, or put them in a series.
But maybe it would be just as well to get this one out of the way. The degree of difficulty is quite different, because to add error handlig code, you have to figure out how to handle the error. So that needs to be done slowly and carefully.
Hi, regarding adding null checks to kmalloc calls.
I wonder if it is possible to do it without deeply know the whole picture of what the code does and with what other code it interacts.
I saw that there are kmalloc calls from a function 'add_network_to_shadow' which is part of a code that enters a working queue. The other calls are from functions that implement callbacks of 'struct cfg80211_ops'.
I saw that other drivers that implemets these callbacks return -ENOMEM. In case of kmalloc returning null, is it enough to free everything else that was allocated in the function and return -ENOMEM?
Dafna
Quoted 29 lines
julia
Quoted 27 lines
Dafna
Quoted 23 lines
Quoted 23 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +2
-6-if (params->seq_len >0 ) +if (params->seq_len >0 ) { priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL ); - -memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len); - -if (params->seq_len >0 )memcpy (priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len); + } priv->wilc_ptk[key_index]->cipher = params->cipher; priv->wilc_ptk[key_index]->key_len = params->key_len; --2.7.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224074733.GA6487%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 52 lines · Dafna Hirschfeld
Quoted 43 lines · Julia Lawall
Quoted 34 lines · Dafna Hirschfeld
Quoted 33 lines · Julia Lawall
Quoted 14 lines · Dafna Hirschfeld
Merge the instructions of two 'if' statements that test the same condition and move a 'memcpy' instruction related to a different variable. Issue found with coccicheck.
Signed-off-by Dafna Hirschfeld <[email protected]>--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +0
-0drivers/staging/wilc1000/wilc_wfi_cfgoperations.c static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, · line 966
Quoted 5 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +1
-0@@ -962,15 +962,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); +memcpy (priv->wilc_ptk[key_index]->key, params->key, params->key_len);kfree (priv->wilc_ptk[key_index]->seq);How about moving the memcpy up a line to be next to the kmalloc, and to be separated by a blank line from the kfree, which is on a different location.
These kmallocs should also have null tests to check for failure. That could be the first patch in the series with this patch being the second one. The missing null checks represent a small bug, and a bug should not depend on a cleanup.
Quoted 4 lines
Quoted 2 lines
julia
Hi, the file has about 17 calls to kmalloc that are not tested for null. Wouldn't it be better to fix all of them in a different patch?
Quoted 8 lines
Sure. It's just that your choices are either to wait for Greg to take one patch before taking the next, or put them in a series.
But maybe it would be just as well to get this one out of the way. The degree of difficulty is quite different, because to add error handlig code, you have to figure out how to handle the error. So that needs to be done slowly and carefully.
Quoted 9 lines
Hi, regarding adding null checks to kmalloc calls.
I wonder if it is possible to do it without deeply know the whole picture of what the code does and with what other code it interacts.
I saw that there are kmalloc calls from a function 'add_network_to_shadow' which is part of a code that enters a working queue. The other calls are from functions that implement callbacks of 'structcfg80211_ops'.
I saw that other drivers that implemets these callbacks return-ENOMEM. In case of kmalloc returning null, is it enough to free everything else that was allocated in the function and return-ENOMEM?
-ENOMEM is very standard for kmalloc, so it is probably fine. Maybe look around elsewhere in the function to see what frees are done, to see what would be adapted to each situation. If it looks like each case will be different, don't feel obliged to do them all. Indeed, unless they are all quite the same, it might be better to do them one by one. Then if a mistake is found later in one of them, it will be possible to revert that patch without reverting all of them.
Your commit message should carefully explain your reasoning in each case.
julia