netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipv6: sr: Use ARRAY_SIZE macro
@ 2017-08-31 14:18 Thomas Meyer
  2017-09-02  1:35 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Meyer @ 2017-08-31 14:18 UTC (permalink / raw)
  To: davem, netdev, linux-kernel; +Cc: Thomas Meyer

Grepping for "sizeof\(.+\) / sizeof\(" found this as one of the first
candidates.
Maybe a coccinelle can catch all of those.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
---
 net/ipv6/seg6_hmac.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c
index f950cb53d5e3..33fb35cbfac1 100644
--- a/net/ipv6/seg6_hmac.c
+++ b/net/ipv6/seg6_hmac.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/socket.h>
 #include <linux/sockios.h>
@@ -110,7 +111,7 @@ static struct seg6_hmac_algo *__hmac_get_algo(u8 alg_id)
 	struct seg6_hmac_algo *algo;
 	int i, alg_count;
 
-	alg_count = sizeof(hmac_algos) / sizeof(struct seg6_hmac_algo);
+	alg_count = ARRAY_SIZE(hmac_algos);
 	for (i = 0; i < alg_count; i++) {
 		algo = &hmac_algos[i];
 		if (algo->alg_id == alg_id)
@@ -360,7 +361,7 @@ static int seg6_hmac_init_algo(void)
 	struct shash_desc *shash;
 	int i, alg_count, cpu;
 
-	alg_count = sizeof(hmac_algos) / sizeof(struct seg6_hmac_algo);
+	alg_count = ARRAY_SIZE(hmac_algos);
 
 	for (i = 0; i < alg_count; i++) {
 		struct crypto_shash **p_tfm;
@@ -421,7 +422,7 @@ void seg6_hmac_exit(void)
 	struct seg6_hmac_algo *algo = NULL;
 	int i, alg_count, cpu;
 
-	alg_count = sizeof(hmac_algos) / sizeof(struct seg6_hmac_algo);
+	alg_count = ARRAY_SIZE(hmac_algos);
 	for (i = 0; i < alg_count; i++) {
 		algo = &hmac_algos[i];
 		for_each_possible_cpu(cpu) {
-- 
2.11.0

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

* Re: [PATCH] ipv6: sr: Use ARRAY_SIZE macro
  2017-08-31 14:18 [PATCH] ipv6: sr: Use ARRAY_SIZE macro Thomas Meyer
@ 2017-09-02  1:35 ` David Miller
  2017-09-02  3:51   ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2017-09-02  1:35 UTC (permalink / raw)
  To: thomas; +Cc: netdev, linux-kernel

From: Thomas Meyer <thomas@m3y3r.de>
Date: Thu, 31 Aug 2017 16:18:15 +0200

> Grepping for "sizeof\(.+\) / sizeof\(" found this as one of the first
> candidates.
> Maybe a coccinelle can catch all of those.
> 
> Signed-off-by: Thomas Meyer <thomas@m3y3r.de>

Applied, thanks.

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

* Re: [PATCH] ipv6: sr: Use ARRAY_SIZE macro
  2017-09-02  1:35 ` David Miller
@ 2017-09-02  3:51   ` Joe Perches
  2017-09-02  6:24     ` Thomas Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-09-02  3:51 UTC (permalink / raw)
  To: David Miller, thomas; +Cc: netdev, linux-kernel

On Fri, 2017-09-01 at 18:35 -0700, David Miller wrote:
> From: Thomas Meyer <thomas@m3y3r.de>
> Date: Thu, 31 Aug 2017 16:18:15 +0200
> 
> > Grepping for "sizeof\(.+\) / sizeof\(" found this as one of the first
> > candidates.
> > Maybe a coccinelle can catch all of those.

Umm: try scripts/coccinelle/misc/array_size.cocci

Until then, maybe a perl script?

$ git grep --name-only sizeof.*/.*sizeof drivers/net | \
  xargs perl -p -i -e 's/\bsizeof\s*\(\s*(\w+)\s*\)\s*\/\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\)/ARRAY_SIZE(\1)/g'

gives:

$ git diff --stat drivers/net
 drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c                   |   2 +-
 drivers/net/ethernet/mellanox/mlx4/fw.c                         |   4 +--
 drivers/net/ethernet/mellanox/mlx4/main.c                       |   8 +++---
 drivers/net/wireless/ath/ath9k/ar9003_eeprom.c                  |   2 +-
 drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phytbl_n.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------------
 5 files changed, 101 insertions(+), 101 deletions(-)

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

* Re: [PATCH] ipv6: sr: Use ARRAY_SIZE macro
  2017-09-02  3:51   ` Joe Perches
@ 2017-09-02  6:24     ` Thomas Meyer
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Meyer @ 2017-09-02  6:24 UTC (permalink / raw)
  To: Joe Perches; +Cc: David Miller, netdev, linux-kernel

On Fri, Sep 01, 2017 at 08:51:55PM -0700, Joe Perches wrote:
> On Fri, 2017-09-01 at 18:35 -0700, David Miller wrote:
> > From: Thomas Meyer <thomas@m3y3r.de>
> > Date: Thu, 31 Aug 2017 16:18:15 +0200
> > 
> > > Grepping for "sizeof\(.+\) / sizeof\(" found this as one of the first
> > > candidates.
> > > Maybe a coccinelle can catch all of those.
> 
Hi,

> Umm: try scripts/coccinelle/misc/array_size.cocci

Yes, I found out/remembered after I submitted above patch... I used to
run most of the cocci spatches (some just run too long) after each rc1 release, but lost interest/time. nobody seems to
do this regularly, at least for existing spatches.

See 6 patches with Message-ID 20170901212907.5662-1-thomas@m3y3r.de

> Until then, maybe a perl script?
> 
> $ git grep --name-only sizeof.*/.*sizeof drivers/net | \
>   xargs perl -p -i -e 's/\bsizeof\s*\(\s*(\w+)\s*\)\s*\/\s*sizeof\s*\(\s*\1\s*\[\s*0\s*\]\s*\)/ARRAY_SIZE(\1)/g'
> 
> gives:
> 
> $ git diff --stat drivers/net
>  drivers/net/ethernet/intel/ixgbe/ixgbe_x550.c                   |   2 +-
>  drivers/net/ethernet/mellanox/mlx4/fw.c                         |   4 +--
>  drivers/net/ethernet/mellanox/mlx4/main.c                       |   8 +++---
>  drivers/net/wireless/ath/ath9k/ar9003_eeprom.c                  |   2 +-
>  drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phytbl_n.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------------
>  5 files changed, 101 insertions(+), 101 deletions(-)

Which makes me wonder why cocci didn't found above places...
Also cocci includes linux/kernel.h if not already present.

I will give above regex a try for the whole kernel tree and check for
false positives.

with kind regards
thomas

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

end of thread, other threads:[~2017-09-02  6:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31 14:18 [PATCH] ipv6: sr: Use ARRAY_SIZE macro Thomas Meyer
2017-09-02  1:35 ` David Miller
2017-09-02  3:51   ` Joe Perches
2017-09-02  6:24     ` Thomas Meyer

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).