linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] iwlwifi: lib: Use struct_size() helper
@ 2019-04-03 15:59 Gustavo A. R. Silva
  2019-05-14  5:16 ` Luciano Coelho
  0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2019-04-03 15:59 UTC (permalink / raw)
  To: Johannes Berg, Emmanuel Grumbach, Luca Coelho,
	Intel Linux Wireless, Kalle Valo, David S. Miller
  Cc: linux-wireless, netdev, linux-kernel, Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes, in particular in the
context in which this code is being used.

So, change the following form:

sizeof(*pattern_cmd) +
               wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern)

 to :

struct_size(pattern_cmd, patterns, wowlan->n_patterns)

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 drivers/net/wireless/intel/iwlwifi/dvm/lib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/lib.c b/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
index b2f172d4f78a..cae9cd438697 100644
--- a/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
+++ b/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
@@ -1022,8 +1022,7 @@ int iwlagn_send_patterns(struct iwl_priv *priv,
 	if (!wowlan->n_patterns)
 		return 0;
 
-	cmd.len[0] = sizeof(*pattern_cmd) +
-		wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
+	cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns);
 
 	pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
 	if (!pattern_cmd)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH][next] iwlwifi: lib: Use struct_size() helper
  2019-04-03 15:59 [PATCH][next] iwlwifi: lib: Use struct_size() helper Gustavo A. R. Silva
@ 2019-05-14  5:16 ` Luciano Coelho
  0 siblings, 0 replies; 2+ messages in thread
From: Luciano Coelho @ 2019-05-14  5:16 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Johannes Berg, Emmanuel Grumbach,
	Intel Linux Wireless, Kalle Valo, David S. Miller
  Cc: linux-wireless, netdev, linux-kernel

On Wed, 2019-04-03 at 10:59 -0500, Gustavo A. R. Silva wrote:
> Make use of the struct_size() helper instead of an open-coded version
> in order to avoid any potential type mistakes, in particular in the
> context in which this code is being used.
> 
> So, change the following form:
> 
> sizeof(*pattern_cmd) +
>                wowlan->n_patterns * sizeof(struct
> iwlagn_wowlan_pattern)
> 
>  to :
> 
> struct_size(pattern_cmd, patterns, wowlan->n_patterns)
> 
> This code was detected with the help of Coccinelle.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/net/wireless/intel/iwlwifi/dvm/lib.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
> b/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
> index b2f172d4f78a..cae9cd438697 100644
> --- a/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
> +++ b/drivers/net/wireless/intel/iwlwifi/dvm/lib.c
> @@ -1022,8 +1022,7 @@ int iwlagn_send_patterns(struct iwl_priv *priv,
>  	if (!wowlan->n_patterns)
>  		return 0;
>  
> -	cmd.len[0] = sizeof(*pattern_cmd) +
> -		wowlan->n_patterns * sizeof(struct
> iwlagn_wowlan_pattern);
> +	cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan-
> >n_patterns);
>  
>  	pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
>  	if (!pattern_cmd)

Thanks! Applied to our internal tree and it will reach the mainline
following our normal upstreaming process.

--
Cheers,
Luca.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-14  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-03 15:59 [PATCH][next] iwlwifi: lib: Use struct_size() helper Gustavo A. R. Silva
2019-05-14  5:16 ` Luciano Coelho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).