[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] ARM/vgic: Fix variable shadowing in vgic_to_sgi()


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Wed, 28 Aug 2024 09:06:19 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+8Lfp2CZBbUQ8ONYYPoWKGUcOuXsHmRawUQ0jh6cAG0=; b=QPMOOIj3MLFJbgxzt9nMpdRxGrfPFyJu12gZI0rZXCQdLKpj/4TvauigfQDHroRC6IJAs0nZqC5FYTafNTCXJMXLgytI3fS7mhMJERWsJ8nFtU5DxSgqn1bVRjnNqIt9thoPSlYRsFWwnRUgbLKufOi7TO0THlFZy/wNsQB8J/3IpvFXl9b72Pf+YKUHcHzNtgJouRxPP/4vHMbowHU0qa/+E1Qn3A7VBdQI3Tb1j3I5RVwxT2ET4p5VWU74/pUhfSjy36bcb0A4Afi2htevQ38klMxZ4zbjVvj0h8rsAcezVrOsfa3dryvrulwGaB5fzXhoVgd19im0FKtVgwibuQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QZfV3ZRIigscPBHDin/nx6qzTyIbYMuKWjZVcA83/TNICfolaajhY88zcQjkEtCzAHG71N0b18/egkdoqwOh+BZ8kEWPkXX9W6NyD9LOLs2bQckSHvdLEdsZ5x0v9CF9mgyy5s0fLDPS7IDlxY8OFIXtJEBUc5EMJCssuIeQ5g1AkTZcpO7y59UYDN0rNPUr8MGnavNcgaGpSCLbyfjsYO2PCLHpOWK4VbBfTZd+83qBWlMb839pvWfVz4se/lpoqH/lzAn/K3SaLq3IQNgK5LsqmRPHpnM3SuR6NGKL2WYq8wU3TRIE6coXVayzAeRvihN6AADiBRrDlkZ7w9+r4g==
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Wed, 28 Aug 2024 07:06:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 28/08/2024 01:45, Andrew Cooper wrote:
> 
> 
> for_each_set_bit() allocates its own variable intentionally as loop-scope
> only.  Unfortunately, this causes the inner 'i' to shadow the outer 'i'.
NIT: I'd mention it violates MISRA R5.3

> 
> Drop the outermost 'i' and 'vcpuid' variables, moving them into a more narrow
> scope and correcting them to be unsigned which they should have been all
> along.
> 
> Fixes: 9429f1a6c475 ("ARM/vgic: Use for_each_set_bit() in vgic_to_sgi()")
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Stefano Stabellini <sstabellini@xxxxxxxxxx>
> CC: Julien Grall <julien@xxxxxxx>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
> CC: Bertrand Marquis <bertrand.marquis@xxxxxxx>
> CC: Michal Orzel <michal.orzel@xxxxxxx>
> ---
>  xen/arch/arm/vgic.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c
> index 8ffe099bcb5f..6ecd9146511c 100644
> --- a/xen/arch/arm/vgic.c
> +++ b/xen/arch/arm/vgic.c
> @@ -468,8 +468,6 @@ bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum 
> gic_sgi_mode irqmode,
>                   int virq, const struct sgi_target *target)
>  {
>      struct domain *d = v->domain;
> -    int vcpuid;
> -    int i;
>      unsigned int base, bitmap;
> 
>      ASSERT( virq < 16 );
> @@ -483,7 +481,8 @@ bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum 
> gic_sgi_mode irqmode,
> 
>          for_each_set_bit ( i, bitmap )
>          {
> -            vcpuid = base + i;
> +            unsigned int vcpuid = base + i;
With this change you should replace the printk specifier from %d to %u for 
vcpuid.

Apart from that:
Reviewed-by: Michal Orzel <michal.orzel@xxxxxxx>

~Michal



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.