* [PATCH v2] staging: wilc1000: merge 'if' statements that test the same condition
@ 2018-02-24 10:27 Dafna Hirschfeld
2018-02-24 14:46 ` [Outreachy kernel] " Julia Lawall
0 siblings, 1 reply; 2+ messages in thread
From: Dafna Hirschfeld @ 2018-02-24 10:27 UTC (permalink / raw)
To: aditya.shankar, ganesh.krishna, gregkh; +Cc: outreachy-kernel
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 <dafna3@gmail.com>
---
Changes in v2:
Grouping instructions that relate to the same variables.
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 621810d..557ab99 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -959,18 +959,14 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
}
kfree(priv->wilc_ptk[key_index]->key);
-
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;
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Outreachy kernel] [PATCH v2] staging: wilc1000: merge 'if' statements that test the same condition
2018-02-24 10:27 [PATCH v2] staging: wilc1000: merge 'if' statements that test the same condition Dafna Hirschfeld
@ 2018-02-24 14:46 ` Julia Lawall
0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2018-02-24 14:46 UTC (permalink / raw)
To: Dafna Hirschfeld; +Cc: aditya.shankar, ganesh.krishna, gregkh, outreachy-kernel
On Sat, 24 Feb 2018, Dafna Hirschfeld wrote:
> 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 <dafna3@gmail.com>
OK, on a wide screen, the code looks nice...
This code is under an if, that is pushing it off to the right. But just
below there is another sequences of lines of code that is in a { } for no
reason at all. Perhaps that could be removed, moving all the code in the
block left by one tab space.
julia
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
> ---
>
> Changes in v2:
> Grouping instructions that relate to the same variables.
>
> drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> index 621810d..557ab99 100644
> --- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> +++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
> @@ -959,18 +959,14 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
> }
>
> kfree(priv->wilc_ptk[key_index]->key);
> -
> 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;
> --
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20180224102722.GA11743%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-02-24 14:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-24 10:27 [PATCH v2] staging: wilc1000: merge 'if' statements that test the same condition Dafna Hirschfeld
2018-02-24 14:46 ` [Outreachy kernel] " Julia Lawall
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.