* Re: [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() [not found] <466b4c6d-032f-fbcc-58ac-75f6f39d734f@web.de> @ 2020-12-10 15:10 ` Alexandre Belloni [not found] ` <ec71d7b8-a36b-04f5-77a8-22874ac241e1@web.de> 2020-12-11 8:37 ` [PATCH] " Dan Carpenter 0 siblings, 2 replies; 9+ messages in thread From: Alexandre Belloni @ 2020-12-10 15:10 UTC (permalink / raw) To: Markus Elfring Cc: linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors Hello, On 10/12/2020 16:01:44+0100, Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Thu, 10 Dec 2020 15:56:13 +0100 > > A local variable was used only within an if branch. > Thus move the definition for the variable “slot” into the corresponding > code block. > What is the improvement here? This makes the code harder to read. > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > drivers/mmc/host/atmel-mci.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c > index 444bd3a0a922..6a0d999ee82e 100644 > --- a/drivers/mmc/host/atmel-mci.c > +++ b/drivers/mmc/host/atmel-mci.c > @@ -1558,7 +1558,6 @@ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq) > __releases(&host->lock) > __acquires(&host->lock) > { > - struct atmel_mci_slot *slot = NULL; > struct mmc_host *prev_mmc = host->cur_slot->mmc; > > WARN_ON(host->cmd || host->data); > @@ -1579,8 +1578,9 @@ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq) > host->cur_slot->mrq = NULL; > host->mrq = NULL; > if (!list_empty(&host->queue)) { > - slot = list_entry(host->queue.next, > - struct atmel_mci_slot, queue_node); > + struct atmel_mci_slot *slot = list_entry(host->queue.next, > + struct atmel_mci_slot, > + queue_node); > list_del(&slot->queue_node); > dev_vdbg(&host->pdev->dev, "list not empty: %s is next\n", > mmc_hostname(slot->mmc)); > -- > 2.29.2 > -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <ec71d7b8-a36b-04f5-77a8-22874ac241e1@web.de>]
* Re: [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() [not found] ` <ec71d7b8-a36b-04f5-77a8-22874ac241e1@web.de> @ 2020-12-10 17:07 ` Alexandre Belloni [not found] ` <2667790c-fad2-aaa9-36e8-6be66949ac8d@web.de> 0 siblings, 1 reply; 9+ messages in thread From: Alexandre Belloni @ 2020-12-10 17:07 UTC (permalink / raw) To: Markus Elfring Cc: linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors On 10/12/2020 17:35:31+0100, Markus Elfring wrote: > >> A local variable was used only within an if branch. > >> Thus move the definition for the variable “slot” into the corresponding > >> code block. > >> > > > > What is the improvement here? > > A possible refactoring. > https://refactoring.com/catalog/reduceScopeOfVariable.html > I quote: "Since declarations of variables in many cases costs computational cycles, you may end up wasting time for nothing." This is false, it doesn't. I also quote: "When I'm writing new code I find I don't scope my temps any less than method scope. This is because I keep my methods short, so reducing scope any further doesn't add much value. The value of this refactoring is in breaking up a large method." Is that function large? It is not. > > > This makes the code harder to read. > > Can the extra null pointer initialisation trigger a source code analysis warning > like “Addresses-Coverity: ("Unused value")” for this function implementation? > Did you check, does it? It doesn't. Are you wasting maintainer and reviewer's time? Yes you are. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <2667790c-fad2-aaa9-36e8-6be66949ac8d@web.de>]
* Re: [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() [not found] ` <2667790c-fad2-aaa9-36e8-6be66949ac8d@web.de> @ 2020-12-10 18:21 ` Alexandre Belloni [not found] ` <4c0d8efe-de25-f168-8b8d-b7f1ede6c6b1@web.de> 0 siblings, 1 reply; 9+ messages in thread From: Alexandre Belloni @ 2020-12-10 18:21 UTC (permalink / raw) To: Markus Elfring Cc: linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors, Colin Ian King On 10/12/2020 18:23:05+0100, Markus Elfring wrote: > >> Can the extra null pointer initialisation trigger a source code analysis warning > >> like “Addresses-Coverity: ("Unused value")” for this function implementation? > >> > > > > Did you check, does it? It doesn't. > > > > Are you wasting maintainer and reviewer's time? Yes you are. > > How do you think about a patch like “staging: speakup: remove redundant initialization > of pointer p_key” for comparison? > https://lore.kernel.org/patchwork/patch/1199128/ > https://lore.kernel.org/driverdev-devel/20200223153954.420731-1-colin.king@canonical.com/ > > Would you tolerate to omit the initialisation for the variable “slot”? > If you were able to provide one good technical reason. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <4c0d8efe-de25-f168-8b8d-b7f1ede6c6b1@web.de>]
* Re: mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() [not found] ` <4c0d8efe-de25-f168-8b8d-b7f1ede6c6b1@web.de> @ 2020-12-11 8:03 ` Alexandre Belloni 2020-12-12 9:16 ` Joe Perches 0 siblings, 1 reply; 9+ messages in thread From: Alexandre Belloni @ 2020-12-11 8:03 UTC (permalink / raw) To: Markus Elfring Cc: linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors, Colin Ian King, Dan Carpenter On 11/12/2020 07:34:41+0100, Markus Elfring wrote: > >> How do you think about a patch like “staging: speakup: remove redundant initialization > >> of pointer p_key” for comparison? > >> https://lore.kernel.org/patchwork/patch/1199128/ > >> https://lore.kernel.org/driverdev-devel/20200223153954.420731-1-colin.king@canonical.com/ > >> > >> Would you tolerate to omit the initialisation for the variable “slot”? > > > > If you were able to provide one good technical reason. > > I find that the positions of variable definitions (and similar assignments) influence > the generation of executable code. > And you are wrong, it doesn't. Before: c044a0f0 <atmci_request_end>: { c044a0f0: e92d4070 push {r4, r5, r6, lr} c044a0f4: e1a04000 mov r4, r0 WARN_ON(host->cmd || host->data); c044a0f8: e5902024 ldr r2, [r0, #36] ; 0x24 { c044a0fc: e1a06001 mov r6, r1 struct mmc_host *prev_mmc = host->cur_slot->mmc; c044a100: e590301c ldr r3, [r0, #28] WARN_ON(host->cmd || host->data); c044a104: e3520000 cmp r2, #0 struct mmc_host *prev_mmc = host->cur_slot->mmc; c044a108: e5935000 ldr r5, [r3] WARN_ON(host->cmd || host->data); c044a10c: 0a00002d beq c044a1c8 <atmci_request_end+0xd8> c044a110: e3000000 movw r0, #0 c044a110: R_ARM_MOVW_ABS_NC .LC0 c044a114: e3a03000 mov r3, #0 c044a118: e3400000 movt r0, #0 c044a118: R_ARM_MOVT_ABS .LC0 c044a11c: e3a02009 mov r2, #9 c044a120: e300161c movw r1, #1564 ; 0x61c c044a124: ebfffffe bl 0 <warn_slowpath_fmt> c044a124: R_ARM_CALL warn_slowpath_fmt del_timer(&host->timer); c044a128: e28400a4 add r0, r4, #164 ; 0xa4 c044a12c: ebfffffe bl 0 <del_timer> c044a12c: R_ARM_CALL del_timer if (host->need_clock_update) { c044a130: e5d430a0 ldrb r3, [r4, #160] ; 0xa0 c044a134: e3530000 cmp r3, #0 c044a138: 0a000005 beq c044a154 <atmci_request_end+0x64> atmci_writel(host, ATMCI_MR, host->mode_reg); c044a13c: e59420b8 ldr r2, [r4, #184] ; 0xb8 c044a140: e5943000 ldr r3, [r4] asm volatile("str %1, %0" c044a144: e5832004 str r2, [r3, #4] if (host->caps.has_cfg_reg) c044a148: e5d420da ldrb r2, [r4, #218] ; 0xda c044a14c: e3520000 cmp r2, #0 c044a150: 1a000019 bne c044a1bc <atmci_request_end+0xcc> host->cur_slot->mrq = NULL; c044a154: e594101c ldr r1, [r4, #28] return READ_ONCE(head->next) == head; c044a158: e1a03004 mov r3, r4 c044a15c: e3a02000 mov r2, #0 c044a160: e5812010 str r2, [r1, #16] host->mrq = NULL; c044a164: e5842020 str r2, [r4, #32] c044a168: e5b31098 ldr r1, [r3, #152]! ; 0x98 if (!list_empty(&host->queue)) { c044a16c: e1510003 cmp r1, r3 host->state = STATE_IDLE; c044a170: 05842094 streq r2, [r4, #148] ; 0x94 if (!list_empty(&host->queue)) { c044a174: 0a00000c beq c044a1ac <atmci_request_end+0xbc> slot = list_entry(host->queue.next, c044a178: e5943098 ldr r3, [r4, #152] ; 0x98 After: c044a0f0 <atmci_request_end>: { c044a0f0: e92d4070 push {r4, r5, r6, lr} c044a0f4: e1a04000 mov r4, r0 WARN_ON(host->cmd || host->data); c044a0f8: e5902024 ldr r2, [r0, #36] ; 0x24 { c044a0fc: e1a06001 mov r6, r1 struct mmc_host *prev_mmc = host->cur_slot->mmc; c044a100: e590301c ldr r3, [r0, #28] WARN_ON(host->cmd || host->data); c044a104: e3520000 cmp r2, #0 struct mmc_host *prev_mmc = host->cur_slot->mmc; c044a108: e5935000 ldr r5, [r3] WARN_ON(host->cmd || host->data); c044a10c: 0a00002d beq c044a1c8 <atmci_request_end+0xd8> c044a110: e3000000 movw r0, #0 c044a110: R_ARM_MOVW_ABS_NC .LC0 c044a114: e3a03000 mov r3, #0 c044a118: e3400000 movt r0, #0 c044a118: R_ARM_MOVT_ABS .LC0 c044a11c: e3a02009 mov r2, #9 c044a120: e300161b movw r1, #1563 ; 0x61b c044a124: ebfffffe bl 0 <warn_slowpath_fmt> c044a124: R_ARM_CALL warn_slowpath_fmt del_timer(&host->timer); c044a128: e28400a4 add r0, r4, #164 ; 0xa4 c044a12c: ebfffffe bl 0 <del_timer> c044a12c: R_ARM_CALL del_timer if (host->need_clock_update) { c044a130: e5d430a0 ldrb r3, [r4, #160] ; 0xa0 c044a134: e3530000 cmp r3, #0 c044a138: 0a000005 beq c044a154 <atmci_request_end+0x64> atmci_writel(host, ATMCI_MR, host->mode_reg); c044a13c: e59420b8 ldr r2, [r4, #184] ; 0xb8 c044a140: e5943000 ldr r3, [r4] asm volatile("str %1, %0" c044a144: e5832004 str r2, [r3, #4] if (host->caps.has_cfg_reg) c044a148: e5d420da ldrb r2, [r4, #218] ; 0xda c044a14c: e3520000 cmp r2, #0 c044a150: 1a000019 bne c044a1bc <atmci_request_end+0xcc> host->cur_slot->mrq = NULL; c044a154: e594101c ldr r1, [r4, #28] return READ_ONCE(head->next) == head; c044a158: e1a03004 mov r3, r4 c044a15c: e3a02000 mov r2, #0 c044a160: e5812010 str r2, [r1, #16] host->mrq = NULL; c044a164: e5842020 str r2, [r4, #32] c044a168: e5b31098 ldr r1, [r3, #152]! ; 0x98 if (!list_empty(&host->queue)) { c044a16c: e1510003 cmp r1, r3 host->state = STATE_IDLE; c044a170: 05842094 streq r2, [r4, #148] ; 0x94 if (!list_empty(&host->queue)) { c044a174: 0a00000c beq c044a1ac <atmci_request_end+0xbc> struct atmel_mci_slot *slot = list_entry(host->queue.next, c044a178: e5943098 ldr r3, [r4, #152] ; 0x98 Do you realize your patch is just unnecessary churn now? Is it too difficult for you to actually compile the driver and look at the changes before submitting patches? -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() 2020-12-11 8:03 ` Alexandre Belloni @ 2020-12-12 9:16 ` Joe Perches 2020-12-12 13:17 ` Alexandre Belloni 0 siblings, 1 reply; 9+ messages in thread From: Joe Perches @ 2020-12-12 9:16 UTC (permalink / raw) To: Alexandre Belloni, Markus Elfring Cc: linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors, Colin Ian King, Dan Carpenter On Fri, 2020-12-11 at 09:03 +0100, Alexandre Belloni wrote: > On 11/12/2020 07:34:41+0100, Markus Elfring wrote: > > > > How do you think about a patch like “staging: speakup: remove redundant initialization > > > > of pointer p_key” for comparison? > > > > https://lore.kernel.org/patchwork/patch/1199128/ > > > > https://lore.kernel.org/driverdev-devel/20200223153954.420731-1-colin.king@canonical.com/ > > > > > > > > Would you tolerate to omit the initialisation for the variable “slot”? > > > > > > If you were able to provide one good technical reason. > > > > I find that the positions of variable definitions (and similar assignments) influence > > the generation of executable code. > > > And you are wrong, it doesn't. I rarely reply or read any Markus' emails as everything from Markus goes into a 'don't read' folder but I was cc'd directly on one from someone else recently so I think I should reply to this one too. In this case Alexandre it seems true, but in the generic case it may be false. It may depend on stack size and location. For instance, with large structs declared either at the top of a function or in separate branches within the function: $ cat t_structs.c struct a { int a[2000]; int b[4000]; }; struct b { char a[100]; char b[10000]; }; void foo1(struct a *a); void foo2(struct b *b); void foo(int index) { if (index) { struct a ai = {}; ai.a[index] = index; foo1(&ai); } else { struct b bi = {}; bi.b[0] = 1; foo2(&bi); } } void bar(int index) { struct a ai = {}; struct b bi = {}; if (index) { ai.a[index] = index; foo1(&ai); } else { bi.b[0] = 1; foo2(&bi); } } $ newer gcc versions are smart enough to minimize stack use in foo() but not bar() so ai and bi start at the same address in foo() so the total stack used is smaller. older gcc versions like 4.8 use separate addresses for ai and bi in foo() so the total stack used is larger. $ gcc-4.8 -Wframe-larger-than=1000 -c t_structs.c t_structs.c: In function ‘foo’: t_structs.c:27:1: warning: the frame size of 34116 bytes is larger than 1000 bytes [-Wframe-larger-than=] } ^ t_structs.c: In function ‘bar’: t_structs.c:41:1: warning: the frame size of 34116 bytes is larger than 1000 bytes [-Wframe-larger-than=] } ^ $ gcc-5 -Wframe-larger-than=1000 -c t_structs.c t_structs.c: In function ‘foo’: t_structs.c:27:1: warning: the frame size of 24032 bytes is larger than 1000 bytes [-Wframe-larger-than=] } ^ t_structs.c: In function ‘bar’: t_structs.c:41:1: warning: the frame size of 34144 bytes is larger than 1000 bytes [-Wframe-larger-than=] } ^ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() 2020-12-12 9:16 ` Joe Perches @ 2020-12-12 13:17 ` Alexandre Belloni 2020-12-12 18:48 ` Joe Perches 0 siblings, 1 reply; 9+ messages in thread From: Alexandre Belloni @ 2020-12-12 13:17 UTC (permalink / raw) To: Joe Perches Cc: Markus Elfring, linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors, Colin Ian King, Dan Carpenter On 12/12/2020 01:16:39-0800, Joe Perches wrote: > On Fri, 2020-12-11 at 09:03 +0100, Alexandre Belloni wrote: > > On 11/12/2020 07:34:41+0100, Markus Elfring wrote: > > > > > How do you think about a patch like “staging: speakup: remove redundant initialization > > > > > of pointer p_key” for comparison? > > > > > https://lore.kernel.org/patchwork/patch/1199128/ > > > > > https://lore.kernel.org/driverdev-devel/20200223153954.420731-1-colin.king@canonical.com/ > > > > > > > > > > Would you tolerate to omit the initialisation for the variable “slot”? > > > > > > > > If you were able to provide one good technical reason. > > > > > > I find that the positions of variable definitions (and similar assignments) influence > > > the generation of executable code. > > > > > And you are wrong, it doesn't. > > I rarely reply or read any Markus' emails as everything > from Markus goes into a 'don't read' folder but I was cc'd > directly on one from someone else recently so I think I > should reply to this one too. > > In this case Alexandre it seems true, but in the generic case > it may be false. It may depend on stack size and location. > > For instance, with large structs declared either at the top > of a function or in separate branches within the function: > I think you realize your example is way more complicated than initializing basic type variable to 0 or NULL which has probably been optimized forever. This patch is just unnecessary churn that was generated without giving any thought. It was easy to check whether the patch actually improved anything. It doesn't and makes readability worse. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() 2020-12-12 13:17 ` Alexandre Belloni @ 2020-12-12 18:48 ` Joe Perches 0 siblings, 0 replies; 9+ messages in thread From: Joe Perches @ 2020-12-12 18:48 UTC (permalink / raw) To: Alexandre Belloni Cc: Markus Elfring, linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors, Colin Ian King, Dan Carpenter On Sat, 2020-12-12 at 14:17 +0100, Alexandre Belloni wrote: > On 12/12/2020 01:16:39-0800, Joe Perches wrote: > > In this case Alexandre it seems true, but in the generic case > > it may be false. It may depend on stack size and location. > > > > For instance, with large structs declared either at the top > > of a function or in separate branches within the function: > > I think you realize your example is way more complicated than > initializing basic type variable to 0 or NULL which has probably been > optimized forever. Maybe. Markus does a lot of what most (or perhaps some) consider thoughtless. A generic point might be maximizing the local scope of declarations. Maximizing the local scope can make reading easier as the type of an automatic used for a temporary purpose can be found closer to the code that uses it. This is especially true for long line-count functions. IMO: it's a reasonable goal though in this instance perhaps unnecessary. cheers, Joe ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() 2020-12-10 15:10 ` [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() Alexandre Belloni [not found] ` <ec71d7b8-a36b-04f5-77a8-22874ac241e1@web.de> @ 2020-12-11 8:37 ` Dan Carpenter [not found] ` <e7910b04-4c4a-567b-d87d-d12352a48cfc@web.de> 1 sibling, 1 reply; 9+ messages in thread From: Dan Carpenter @ 2020-12-11 8:37 UTC (permalink / raw) To: Alexandre Belloni Cc: Markus Elfring, linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, kernel-janitors Markus was banned from vger at the end of July after ignoring repeated warnings. This makes it hard to review any patches or follow discussion... regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <e7910b04-4c4a-567b-d87d-d12352a48cfc@web.de>]
* Re: mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() [not found] ` <e7910b04-4c4a-567b-d87d-d12352a48cfc@web.de> @ 2020-12-14 7:05 ` Dan Carpenter 0 siblings, 0 replies; 9+ messages in thread From: Dan Carpenter @ 2020-12-14 7:05 UTC (permalink / raw) To: Markus Elfring Cc: kernel-janitors, linux-mmc, linux-arm-kernel, Ludovic Desroches, Nicolas Ferre, Ulf Hansson, LKML, Alexandre Belloni, Colin Ian King On Fri, Dec 11, 2020 at 10:08:54AM +0100, Markus Elfring wrote: > > This makes it hard to review any patches or follow discussion... > > You shared also special software development opinions about extra variable > initialisations occasionally, didn't you? I generally put everything at the top of the function... I don't have a well developed philosophy for when variables should be declared with a smaller scope. int ret; <-- this should always be function scope Probably the other people are right that making scopes shorter is more important when the function is very long. regards, dan carpenter ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-12-14 7:09 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <466b4c6d-032f-fbcc-58ac-75f6f39d734f@web.de> 2020-12-10 15:10 ` [PATCH] mmc: atmel-mci: Reduce scope for the variable “slot” in atmci_request_end() Alexandre Belloni [not found] ` <ec71d7b8-a36b-04f5-77a8-22874ac241e1@web.de> 2020-12-10 17:07 ` Alexandre Belloni [not found] ` <2667790c-fad2-aaa9-36e8-6be66949ac8d@web.de> 2020-12-10 18:21 ` Alexandre Belloni [not found] ` <4c0d8efe-de25-f168-8b8d-b7f1ede6c6b1@web.de> 2020-12-11 8:03 ` Alexandre Belloni 2020-12-12 9:16 ` Joe Perches 2020-12-12 13:17 ` Alexandre Belloni 2020-12-12 18:48 ` Joe Perches 2020-12-11 8:37 ` [PATCH] " Dan Carpenter [not found] ` <e7910b04-4c4a-567b-d87d-d12352a48cfc@web.de> 2020-12-14 7:05 ` Dan Carpenter
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).