All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Cédric Le Goater" <clg@kaod.org>
Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>,
	 qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
	 Daniel Henrique Barboza <danielhb413@gmail.com>,
	David Gibson <david@gibson.dropbear.id.au>,
	 Nicholas Piggin <npiggin@gmail.com>
Subject: Re: [PATCH 2/8] pnv/psi: Clean up local variable shadowing
Date: Fri, 29 Sep 2023 07:30:25 +0200	[thread overview]
Message-ID: <874jjdlf66.fsf@pond.sub.org> (raw)
In-Reply-To: <752e55c4-0a81-3f7e-905e-53f89674dfdd@kaod.org> ("Cédric Le Goater"'s message of "Tue, 19 Sep 2023 11:03:11 +0200")

Cédric Le Goater <clg@kaod.org> writes:

> On 9/19/23 08:57, Harsh Prateek Bora wrote:
>> On 9/18/23 20:28, Cédric Le Goater wrote:
>>> to fix :
>>>
>>>    ../hw/ppc/pnv_psi.c: In function ‘pnv_psi_p9_mmio_write’:
>>>    ../hw/ppc/pnv_psi.c:741:24: warning: declaration of ‘addr’ shadows a parameter [-Wshadow=compatible-local]
>>>      741 |                 hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
>>>          |                        ^~~~
>>>    ../hw/ppc/pnv_psi.c:702:56: note: shadowed declaration is here
>>>      702 | static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
>>>          |                                                 ~~~~~~~^~~~
>>>
>>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>>> ---
>>>   hw/ppc/pnv_psi.c | 5 +++--
>>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/hw/ppc/pnv_psi.c b/hw/ppc/pnv_psi.c
>>> index daaa2f0575fd..26460d210deb 100644
>>> --- a/hw/ppc/pnv_psi.c
>>> +++ b/hw/ppc/pnv_psi.c
>>> @@ -738,8 +738,9 @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr,
>>>               }
>>>           } else {
>>>               if (!(psi->regs[reg] & PSIHB9_ESB_CI_VALID)) {
>>> -                hwaddr addr = val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
>>> -                memory_region_add_subregion(sysmem, addr,
>>> +                hwaddr esb_addr =
>>
>> While at it, we may want to move the declaration to the beginning of the function. 
>
> I am more in favor of declaring the variables where they are needed.
> I think it is better pratice since it identifies a functional block
> which could be move in a external routine at some point if it becomes
> too complex.

I'm old-fashioned and prefer my declarations in one place, where I can
find them easily, except perhaps for for-loop counters.  I suspect when
a function is big enough so that moving declarations to inner blocks
improves it, factoring out these inner blocks would improve it more.

My other reason is the risk for accidental shadowing, but us enabling
-Wshadow=local will render that point moot.

Maintainers get to decide such matters of taste, and I'm not the
maintainer here :)

>> Anyways,
>> Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
>
>
> Thanks,
>
> C.
>
>
>> 
>>> +                    val & ~(PSIHB9_ESB_CI_VALID | PSIHB10_ESB_CI_64K);
>>> +                memory_region_add_subregion(sysmem, esb_addr,
>>>                                               &psi9->source.esb_mmio);
>>>               }
>>>           }

  reply	other threads:[~2023-09-29  5:31 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 14:58 [PATCH 0/8] ppc: Clean up local variable shadowing Cédric Le Goater
2023-09-18 14:58 ` [PATCH 1/8] hw/ppc: Clean up local variable shadowing in _FDT helper routine Cédric Le Goater
2023-09-19  6:53   ` Harsh Prateek Bora
2023-09-18 14:58 ` [PATCH 2/8] pnv/psi: Clean up local variable shadowing Cédric Le Goater
2023-09-19  6:57   ` Harsh Prateek Bora
2023-09-19  9:03     ` Cédric Le Goater
2023-09-29  5:30       ` Markus Armbruster [this message]
2023-09-29  6:13         ` Cédric Le Goater
2023-09-18 14:58 ` [PATCH 3/8] spapr: Clean up local variable shadowing in spapr_dt_cpus() Cédric Le Goater
2023-09-19  7:28   ` Harsh Prateek Bora
2023-09-19 11:05     ` Cédric Le Goater
2023-09-19 13:04       ` Harsh Prateek Bora
2023-09-19 14:59         ` Harsh Prateek Bora
2023-09-19 15:05           ` Cédric Le Goater
2023-09-18 14:58 ` [PATCH 4/8] spapr: Clean up local variable shadowing in spapr_init_cpus() Cédric Le Goater
2023-09-19  7:30   ` Harsh Prateek Bora
2023-09-18 14:58 ` [PATCH 5/8] spapr: Clean up local variable shadowing in spapr_get_fw_dev_path() Cédric Le Goater
2023-09-18 15:29   ` Philippe Mathieu-Daudé
2023-09-19  8:23   ` Harsh Prateek Bora
2023-09-19 11:54     ` Cédric Le Goater
2023-09-18 14:58 ` [PATCH 6/8] spapr/drc: Clean up local variable shadowing in rtas_ibm_configure_connector() Cédric Le Goater
2023-09-19  8:29   ` Harsh Prateek Bora
2023-09-19 12:02     ` Cédric Le Goater
2023-09-19 13:01       ` Harsh Prateek Bora
2023-09-29  5:34         ` Markus Armbruster
2023-09-29  5:43           ` Harsh Prateek Bora
2023-09-18 14:58 ` [PATCH 7/8] spapr/pci: Clean up local variable shadowing in spapr_phb_realize() Cédric Le Goater
2023-09-19  8:38   ` Harsh Prateek Bora
2023-09-19 12:04     ` Cédric Le Goater
2023-09-18 14:58 ` [PATCH 8/8] spapr/drc: Clean up local variable shadowing in prop_get_fdt() Cédric Le Goater
2023-09-18 15:30   ` Philippe Mathieu-Daudé
2023-09-19  8:48   ` Harsh Prateek Bora
2023-09-19 12:07     ` Cédric Le Goater
2023-09-19 12:55       ` Harsh Prateek Bora
2023-09-29  5:39         ` Markus Armbruster
2023-09-29  6:07           ` Cédric Le Goater
2023-09-29  6:18             ` Harsh Prateek Bora
2023-10-04 10:26 ` [PATCH 0/8] ppc: Clean up local variable shadowing Markus Armbruster
2023-10-04 11:56   ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jjdlf66.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=clg@kaod.org \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=harshpb@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.