Use ARRAY_SIZE macro
Subsystems (2)
cover Use ARRAY_SIZE macro
Used ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) Coccinelle is used to make the changes-
@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
Shraddha Barke (2):
Staging: sm750fb: Use ARRAY_SIZE macro
Staging: speakup: Use ARRAY_SIZE macro
drivers/staging/sm750fb/ddk750_chip.c | 4 ++-- drivers/staging/speakup/i18n.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/2 Staging: sm750fb: Use ARRAY_SIZE macro
ARRAY_SIZE is more concise to use when the size of an array is divided by the size of its type or the size of its first element.
Change made using Coccinelle-
@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
--- drivers/staging/sm750fb/ddk750_chip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/sm750fb/ddk750_chip.c +2 -2
@@ -391,10 +391,10 @@ unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)if (pll->clockType !=MXCLK_PLL ) { xparm = &xparm_PIXEL[0 ]; - xcnt =sizeof (xparm_PIXEL)/sizeof (xparm_PIXEL[0 ]); + xcnt =ARRAY_SIZE (xparm_PIXEL); }else { xparm = &xparm_MXCLK[0 ]; - xcnt =sizeof (xparm_MXCLK)/sizeof (xparm_MXCLK[0 ]); + xcnt =ARRAY_SIZE (xparm_MXCLK); }
Signature · 1 line
2.1.4
Re: [Outreachy kernel] [PATCH 1/2] Staging: sm750fb: Use ARRAY_SIZE macro
Quoted 5 lines · Shraddha Barke
ARRAY_SIZEis more concise to use when the size of an array is divided by the size of its type or the size of its first element.Change made using Coccinelle-
Quoted 7 lines
@@
type T;
T[] E;
@@- (sizeof(E)/sizeof(T))
+ARRAY_SIZE(E)
This semantic patch doesn't have a pattern for the size of the first element. You don't have to put the complete semantic patch in the commit message whn it does multiple things. But it would be better to put the part of the semantic patch that actually relates to the transformation that is made. Then someone can understand the transformation that was made better.
julia
Quoted 32 lines
Signed-off-by Shraddha Barke <[email protected]>--- drivers/staging/sm750fb/ddk750_chip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/sm750fb/ddk750_chip.c +2
-3@@ -391,10 +391,10 @@ unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)if (pll->clockType !=MXCLK_PLL ) { xparm = &xparm_PIXEL[0 ]; - xcnt =sizeof (xparm_PIXEL)/sizeof (xparm_PIXEL[0 ]); + xcnt =ARRAY_SIZE (xparm_PIXEL); }else { xparm = &xparm_MXCLK[0 ]; - xcnt =sizeof (xparm_MXCLK)/sizeof (xparm_MXCLK[0 ]); + xcnt =ARRAY_SIZE (xparm_MXCLK); } --2.1.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/1444222177-11153-2-git-send-email-shraddha.6596%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Greg KH
maintainerRe: [Outreachy kernel] [PATCH 1/2] Staging: sm750fb: Use ARRAY_SIZE macro
In reply to Shraddha BarkeQuoted 10 lines · Shraddha Barke
ARRAY_SIZEis more concise to use when the size of an array is divided by the size of its type or the size of its first element.Change made using Coccinelle-
@@
type T;
T[] E;
@@
Quoted 7 lines
- (sizeof(E)/sizeof(T))
+ARRAY_SIZE(E)Signed-off-by Shraddha Barke <[email protected]>--- drivers/staging/sm750fb/ddk750_chip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Doesn't apply to my tree :(
Re: [Outreachy kernel] [PATCH 1/2] Staging: sm750fb: Use ARRAY_SIZE macro
Quoted 14 lines · Greg KH
Quoted 13 lines · Shraddha Barke
ARRAY_SIZEis more concise to use when the size of an array is divided by the size of its type or the size of its first element.Change made using Coccinelle-
@@
type T;
T[] E;
@@- (sizeof(E)/sizeof(T))
+ARRAY_SIZE(E)
Quoted 6 lines
Quoted 4 lines
Signed-off-by Shraddha Barke <[email protected]>--- drivers/staging/sm750fb/ddk750_chip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Doesn't apply to my tree :(
Umm, it applied when I tried it. A change was made recently to this file https://git.kernel.org/cgit/linux/kernel/git/gregkh/staging.git/commit/?h=staging-testing&id=31418e37019ec188f4201587c7234bfb463e7bf4
before this patch was applied. Do you think it's because of that?. I'm trying to understand how this works.
Anyways, I'll resend it with suggestions made by Julia.
Thanks,
Shraddha
Quoted 1 line
PATCH 2/2 Staging: speakup: Use ARRAY_SIZE macro
In reply to Shraddha BarkeARRAY_SIZE is more concise to use when the size of an array is divided by the size of its type or the size of its first element.
Changes made using Coccinelle-
@@
type T;
T[] E;
@@
- (sizeof(E)/sizeof(T))
+ ARRAY_SIZE(E)
--- drivers/staging/speakup/i18n.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/speakup/i18n.c +1 -1
@@ -389,7 +389,7 @@ static struct msg_group_t all_groups[] = { }, }; -static const int num_groups =sizeof (all_groups) /sizeof (struct msg_group_t ); +static const int num_groups =ARRAY_SIZE (all_groups);char *spk_msg_get (enum msg_index_t index) {
Signature · 1 line
2.1.4