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

[PATCH] virtual_region: address Misra C:2012 rule 18.3


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Thu, 8 Oct 2026 11:52:18 +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=sZDA2glfVKsohaT+q9MvuOP/DiisaMtmTAUR0MP4+R8=; b=sDVKvYUoCVqhhtXmH75mJYtsfdjwUrMVPaIbIIrvzbpxiSx/gj64wIRSk5RB2N18/f3JlGPIE0U7g3nueyjbIBgbZLNwVtaO/Jp1BgVgwAXxwKfNEcn3XkSqspCIb/Q40cYLhECrPsgo5uVO+QwungswSsbucGVChaNwyDzd6/luP9eXVtwOnlJHk8B1fj+WcxIht3Evmktak1hSD2Dw/kru0D05fssnyT+CQjzlYDnvzrTB3Tnab6f5pJnpVpL2Q6RCY31gRHcaqDE9bcKZs2Kz8gsXKiC0POyltnFzy+tLor2JwhICHE8MA21Gvph7ct2UbY+3fZqhgnuiSPrBNQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EyU5ZGETtHfOr68qXGAhr4IefJVo96vCE1couCn9Kh+3/CVZtbBS3JREHIG/EdPPuSEwhUQB7BmknSOej+ldRD31GyQM+ZrPK1lNa0sQTgjKAl9aYNRrS1QFrPS4lCaLm6UUY4olmP1zBrjFRwPQ8dva7QeU3KWSxlEaySNqvZ/Ih77jc1tZIfg336y4A2n5xXZdVdyxSgCx73PQhdH8VkI0j9Ma+47837Jk7w6u/QcgOuyOKFAgL7ReQPHh69O4rkC6FclnR6J9OQHXEc3yqPOJG/5Zs90b2u51MrVR5j6uwYGckbswpgtsnSYntLx63GVv2D6gg4lI1oeAIzNKeA==
  • 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>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Thu, 08 Oct 2026 11:52:36 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdVxt4SHehqFazWUu0IFdrUKTAbA==
  • Thread-topic: [PATCH] virtual_region: address Misra C:2012 rule 18.3

find_text_region() tests whether an arbitrary address lies inside
[text_start, text_end). The address and those bounds are not known to
point into one object, so relational operators on the pointers are
undefined behaviour and violate Misra C:2012 rule 18.3.

The bounds are cast to unsigned long because addr already has that
type. The type is wide enough to hold a pointer, so the comparison
result stays the same.

No functional changes.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
---
A deviation does not fit because find_text_region() compares an arbitrary 
address
with bounds (as was proposed here:
https://patchew.org/Xen/901917945f704643e95842a773be9e8676f76d10.1755690681.git.dmytro._5Fprokopchuk1@xxxxxxxx/).

Casting resolve this MISRA violation.
---
 xen/common/virtual_region.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/common/virtual_region.c b/xen/common/virtual_region.c
index 1dc2e9f592..a30e6b9c30 100644
--- a/xen/common/virtual_region.c
+++ b/xen/common/virtual_region.c
@@ -83,8 +83,8 @@ const struct virtual_region *find_text_region(unsigned long 
addr)
     rcu_read_lock(&rcu_virtual_region_lock);
     list_for_each_entry_rcu ( iter, &virtual_region_list, list )
     {
-        if ( (void *)addr >= iter->text_start &&
-             (void *)addr <  iter->text_end )
+        if ( addr >= (unsigned long)iter->text_start &&
+             addr < (unsigned long)iter->text_end )
         {
             region = iter;
             break;
-- 
2.43.0



 


Rackspace

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