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

[PATCH] xen/sched: resolve MISRA R18.3 pointer comparison


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Tue, 10 Nov 2026 09:59:14 +0000
  • Accept-language: en-US, uk-UA, ru-RU
  • 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=VyDvllBXRPxQSfWQLbgsaxP6xURaC1wpiaByY+WHwbU=; b=c3KJXzNSAjXz0ymguTXPdYv+rqdIw07pwD47gTYeOZZ9F6szU5KiQNYaPq0AWyJ3mL8WgbNFoMTXKw1YxBu1TJ9/GK9fY+GMB7ufeWr4WRiQ5KCrtF9myd9LbrQKscCjH3k+9hVhU1qFKRdkEseqEeuGScebb1YMqHvn8eh5wlt1L6Z22vtDBYoifaAmHnl5jKlqgQbKvieESfdhxxefyhIM17p+yayYgn9PDkW4nk43tcYX+NRqp8rebBlnAwJ9w3KbM+bADLAV39QbjRGl9DHWo1eW+LyOXIeAjpWXU2Xcm1v+Bew3gX26ahuWwnajsFahd4i2NugysQSMHV1AAQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a8l61o9hpx3EliHDyqi+xcCPwJzXmNb9A7y0nuUBAkHQZA3zZl4z/QdPT+J0ZK7FqnGEXzxa14iXQLAf6oG7x3HJ8VQKhhNEbAp5M4oeqWYuvTP6x14J0Y8QxFoO7SfO6S378PZ1wuLhgQ27vdTtWAfNG6RpgQHkOisN1mcXviDnU6HFz29PU+Xp16hFCr0jam2NNLxkY48q+ZwBD5tEqIdodSALt+ZADYLsJcmZOhpHwgL6ed0TSHPaO/nUF6tClnr9B202ESuXAH4iBBPgXJJPeshRNTv7SThGZAQYJflQ90BEjPdCGE6dIhR64yuqn8urhuiU1UZjcEO1cSdIdQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>
  • Delivery-date: Tue, 10 Nov 2026 09:59:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdcPokuddABcs0aEGWzDRXWlu8ug==
  • Thread-topic: [PATCH] xen/sched: resolve MISRA R18.3 pointer comparison

MISRA C Rule 18.3 states: "The relational operators >, >=, < and <=
shall not be applied to objects of pointer type except where they
point into the same object".

sched_spin_lock_double() takes the lock at the lower address first.
The two spinlock_t pointers are not required to point into the same
object, so compare the addresses as integers.

unsigned long is the right integer type here. It is pointer-sized on
every architecture Xen supports, so the cast keeps the full address,
and an unsigned comparison still means "lower address first". A signed
long would interpret an address with the high bit set as negative, so
the order would no longer follow that rule.

No functional change.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
Test CI pipeline:
https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/3048801945
---
 xen/common/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c
index 88ae40f954..10b6eecccd 100644
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -377,7 +377,7 @@ static always_inline void sched_spin_lock_double(
     {
         *flags = _spin_lock_irqsave(lock1);
     }
-    else if ( lock1 < lock2 )
+    else if ( (unsigned long)lock1 < (unsigned long)lock2 )
     {
         *flags = _spin_lock_irqsave(lock1);
         _spin_lock(lock2);
-- 
2.43.0

 


Rackspace

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