qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/pci: Add parenthesis to PCI_BUILD_BDF macro
@ 2024-11-01 21:59 Roque Arcudia Hernandez
  2024-11-03 11:47 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: Roque Arcudia Hernandez @ 2024-11-01 21:59 UTC (permalink / raw)
  To: nabihestefan, mst, marcel.apfelbaum; +Cc: qemu-devel, Roque Arcudia Hernandez

The bus parameter in the macro PCI_BUILD_BDF is not surrounded by
parenthesis. This can create a compile error when warnings are
treated as errors or can potentially create runtime errors due to the
operator precedence.

For instance:

 file.c:x:32: error: suggest parentheses around '-' inside '<<'
 [-Werror=parentheses]
   171 | uint16_t bdf = PCI_BUILD_BDF(a - b, sdev->devfn);
       |                              ~~^~~
 include/hw/pci/pci.h:19:41: note: in definition of macro
 'PCI_BUILD_BDF'
    19 | #define PCI_BUILD_BDF(bus, devfn)     ((bus << 8) | (devfn))
       |                                         ^~~
 cc1: all warnings being treated as errors

Signed-off-by: Roque Arcudia Hernandez <roqueh@google.com>
Reviewed-by: Nabih Estefan <nabihestefan@google.com>
---
 include/hw/pci/pci.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 35d4fe0bbf..1daec974da 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -16,7 +16,7 @@ extern bool pci_available;
 #define PCI_BUS_NUM(x)          (((x) >> 8) & 0xff)
 #define PCI_SLOT(devfn)         (((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn)         ((devfn) & 0x07)
-#define PCI_BUILD_BDF(bus, devfn)     ((bus << 8) | (devfn))
+#define PCI_BUILD_BDF(bus, devfn)     (((bus) << 8) | (devfn))
 #define PCI_BDF_TO_DEVFN(x)     ((x) & 0xff)
 #define PCI_BUS_MAX             256
 #define PCI_DEVFN_MAX           256
-- 
2.47.0.163.g1226f6d8fa-goog



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

* Re: [PATCH] hw/pci: Add parenthesis to PCI_BUILD_BDF macro
  2024-11-01 21:59 [PATCH] hw/pci: Add parenthesis to PCI_BUILD_BDF macro Roque Arcudia Hernandez
@ 2024-11-03 11:47 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-11-03 11:47 UTC (permalink / raw)
  To: Roque Arcudia Hernandez, nabihestefan, mst, marcel.apfelbaum
  Cc: qemu-devel, QEMU Trivial

On 1/11/24 18:59, Roque Arcudia Hernandez wrote:
> The bus parameter in the macro PCI_BUILD_BDF is not surrounded by
> parenthesis. This can create a compile error when warnings are
> treated as errors or can potentially create runtime errors due to the
> operator precedence.
> 
> For instance:
> 
>   file.c:x:32: error: suggest parentheses around '-' inside '<<'
>   [-Werror=parentheses]
>     171 | uint16_t bdf = PCI_BUILD_BDF(a - b, sdev->devfn);
>         |                              ~~^~~
>   include/hw/pci/pci.h:19:41: note: in definition of macro
>   'PCI_BUILD_BDF'
>      19 | #define PCI_BUILD_BDF(bus, devfn)     ((bus << 8) | (devfn))
>         |                                         ^~~
>   cc1: all warnings being treated as errors
> 
> Signed-off-by: Roque Arcudia Hernandez <roqueh@google.com>
> Reviewed-by: Nabih Estefan <nabihestefan@google.com>
> ---
>   include/hw/pci/pci.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> index 35d4fe0bbf..1daec974da 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -16,7 +16,7 @@ extern bool pci_available;
>   #define PCI_BUS_NUM(x)          (((x) >> 8) & 0xff)
>   #define PCI_SLOT(devfn)         (((devfn) >> 3) & 0x1f)
>   #define PCI_FUNC(devfn)         ((devfn) & 0x07)
> -#define PCI_BUILD_BDF(bus, devfn)     ((bus << 8) | (devfn))
> +#define PCI_BUILD_BDF(bus, devfn)     (((bus) << 8) | (devfn))
>   #define PCI_BDF_TO_DEVFN(x)     ((x) & 0xff)
>   #define PCI_BUS_MAX             256
>   #define PCI_DEVFN_MAX           256

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

end of thread, other threads:[~2024-11-03 11:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-01 21:59 [PATCH] hw/pci: Add parenthesis to PCI_BUILD_BDF macro Roque Arcudia Hernandez
2024-11-03 11:47 ` Philippe Mathieu-Daudé

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