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

[PATCH v3 2/3] xen: x86: irq: use do-while loop in create_irq()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Tue, 1 Apr 2025 01:17:51 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • 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=pYY5TMzKZzk8Pg6xp60F/cK2FtqsNx/Afg43r5Pf3JM=; b=mOrbLM/vuq9wFjCobJL4h6WgP0EUf0bCNJfkVFrgQZmE/ykKUs7zmwAtf4iqjZUscF2GeZ1iPcj0TP2MXkXY1TMChrszNIuMUr3uF+Qpc8vVHAXJKsRgqVPQIQPfIimGulLsV1c7FEM7z4+zMh4guMbygkJ/PwffjnEnfbB+oNUvvMz4rrcKJ/gjxDlihybtySNigmA2kl+RrxzallUaVk9PyEGkpS93e7nHMDE6M10aS7w3GFMkGFayI7P1N3prdYrMfoLQJl3A0iiR7MU8pcfgCzRTkOkKannmsVL0cePRoVG8n88uOrBAGocyzh2w1pWnbocVbfGq9Kp7xaHNpg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nAwatLDyaajIHjiL/s5mfEpHBsbwKLOAGOTkfgtUeIMilYYDcjsWvQOs6G0zozNkMC7qGx/DG6UkH03NzM3BYapxhhiTPipH4KUXC9xU5vnqsUlhX7W1SakJEX6028VqLaZSuqoVlC8rotawfVCSEFeFyJYzi52HsyWcFyl4kJo2nZ6eVQ3l/3q4lU6czc4MKroajrfmOUGvdSBKz9xIYJtX4MOPSGsTI6Lq7vlkTr3qKJwdPjDmPBCbIBYoFxURWNycYsM7nTuAH8GO6mkWLTLQRKFdC38nQZQnEQIIklKL+6b2OJJfl8HTwBipacyiQgDBK6yOwdnf4HUKLtst/w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Tue, 01 Apr 2025 01:18:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHboqPjgHkUwEzR90uZDjrf8rDceQ==
  • Thread-topic: [PATCH v3 2/3] xen: x86: irq: use do-while loop in create_irq()

While building xen with GCC 14.2.1 with "-fcondition-coverage" option,
the compiler produces a false positive warning:

  arch/x86/irq.c: In function ‘create_irq’:
  arch/x86/irq.c:281:11: error: ‘desc’ may be used uninitialized 
[-Werror=maybe-uninitialized]
    281 |     ret = init_one_irq_desc(desc);
        |           ^~~~~~~~~~~~~~~~~~~~~~~
  arch/x86/irq.c:269:22: note: ‘desc’ was declared here
    269 |     struct irq_desc *desc;
        |                      ^~~~
  cc1: all warnings being treated as errors
  make[2]: *** [Rules.mk:252: arch/x86/irq.o] Error 1

The same behavior can be observed when building Xen with "-Og"
optimization level. Fix this by using "do { } while" loop instead of
"for" loop.

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>

---

Changes in v3:
 - Correct code style ("do {")
 - Add comment describing why we need do { } while loop.
   I prefer to leave do {} while because Nicola Vetrini
   said that this approach might help with MISRA Rule 9.1
   without needing an explicit initializer.

Changes in v2:

 - Use do { } while loop instead of initializing desc with NULL
---
 xen/arch/x86/irq.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c
index dd8d921f18..2f288704b5 100644
--- a/xen/arch/x86/irq.c
+++ b/xen/arch/x86/irq.c
@@ -264,15 +264,24 @@ void __init clear_irq_vector(int irq)
 
 int create_irq(nodeid_t node, bool grant_access)
 {
-    int irq, ret;
+    int ret;
+    int irq = nr_irqs_gsi;
     struct irq_desc *desc;
 
-    for (irq = nr_irqs_gsi; irq < nr_irqs; irq++)
-    {
+    if ( irq >= nr_irqs )
+        return -ENOSPC;
+
+    /*
+     * do { } while loop is used here to convince gcc14 that 'desc' is
+     * really assigned. Otherwise with -Og or -fcondition-coverage it
+     * may throw an false error stating that 'desc' may be used before
+     * initialization.
+     */
+    do {
         desc = irq_to_desc(irq);
         if (cmpxchg(&desc->arch.used, IRQ_UNUSED, IRQ_RESERVED) == IRQ_UNUSED)
            break;
-    }
+    } while ( ++irq < nr_irqs );
 
     if (irq >= nr_irqs)
          return -ENOSPC;
-- 
2.48.1

 


Rackspace

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