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

Re: [XEN PATCH] x86/mce: use offsetof to determine section offset


  • To: Jason Andryuk <jason.andryuk@xxxxxxx>
  • From: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • Date: Wed, 14 Jan 2026 21:56:23 +0100
  • Arc-authentication-results: i=1; bugseng.com; arc=none smtp.remote-ip=162.55.131.47
  • Arc-message-signature: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; c=relaxed/relaxed; t=1768424183; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:X-Sender:Organization:Content-Type: Content-Transfer-Encoding; bh=ntQkDCkn5ceckBt3E0faKoXB378Nkvml9jXdJFgGqf0=; b=o9oDRVk11tM0XLhGUtVnE6iSjV7dCdCzpiQRIx23aJS3g3wK3n+le+zNYjEA4ntWew7I 1v+OODyRFDhl1IrsqCqY7tL7Pd9H0yV0QVwpnoa75GpYPLCGc/u0dv1k+9f1S3PRD4mbh jfUAEWWa3ivDx1pA3r+eEDivKnzAO5zIJFBupF4mZS/QemFAcATHCQoAcXswp4LvkIETt f4+MDb6S1Q14IL5f11LsrA+i5VQvQq3m5gY1djB54PJ/5EsiujuGZoVvWw1kjM3TQ8sTj zOf6w38MZeJuAOKFBouT3rRIwj5Jj3hK+6bV71WXM4LjsbCe0DmR69Wij4wCBkSAgeo+6 2g+D0wEMzZW+aRHba+97yH6Bxr3wb+PVZU2MVBfr4fcQlflqNNvIm4DbcTkIjw6MVYkqC iyaIFRRGIx6nZCFgZIgV96wt+JLlI7iUa0d6fVlP63ujoYSWJ/jCVseyQGFVdWmXPsux8 A1GKHPjzNYURzTFSAIrH3a/9CHc/3wjMiNkz4sMeQ+SI9NEMDkBsVejSwcYtVf8RLnbq6 qUCAR/A2sHRbsZ1zD2IzuP4CFfACBCvZlKOiTSegw1e0dTUlpE+3bAGQCLiLqVc49kzTb SzL9Ysd3Fqh211aNhyroWkNU5A2Ad5QJuu8vyK1mAsj8La+n3Ua2xUlOQuucDAc=
  • Arc-seal: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; cv=none; t=1768424183; b=TUN+L978NZJ09OBLpYrsWLLLXf9lpcLlLrkwiKdVK1BGgCAjTmQ27GlCuyqJ3t3oBEI8 IeHhviwhm6C2E40BrzDw1z72fF+fEMfZu9Y4AueQZvye2Z0CvEk6Os1CTJ08GEyLre2l4 xBSOBSiS7P/RsFpOHFPtISMUztAaq303ACBjE8oC9j/XPmhH1u4bkWgPX3qMiaYB5J9a6 NZ/lk2vUJu7Tzxr4NjV9UcGZS7+05gzdxCrrwf0pGf3OYcitYKfvfC3UCuLIpMKnRgvaT MvrCRbssSgcrJeSbDhBHq+sRO/wD4OxxV+0bpfXEzF5Xg7hi/w8U2TRAI4V8YvFI/Fq5G nqXXaL1VP/o9vxqEAdlHSBhRHQulyjh1IG7J9TfquXDDA+noqfKl32vNtuXVD7Xo4nt77 ubC/rHOdPFw2VRrrZEhUGXNrsAZApIOCSKnJDU8FE1DpGLrhMy5MPcHRlKSeTG69baVsd 5RpLzJb71m/3TSUCg/Ld0xUYjfhUUXmTT8hizjFk+bnKE/BVk3EuIZDJOX65QeKEtRAtK RidqsUV4A/tX12h4GfAhE9dA1Bf2y8waRsdhRtQNyiEqNiJ3pfaz3YhocVYPf6+7GAg/d O4iJdT5rmOJbvfHn/hdwuS0Acjqts5Vda//xC8km8nfi3k/PrsvcdkX+aDU4koU=
  • Authentication-results: bugseng.com; arc=none smtp.remote-ip=162.55.131.47
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 14 Jan 2026 20:56:34 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2026-01-14 21:40, Jason Andryuk wrote:
On 2026-01-14 13:27, Nicola Vetrini wrote:
There is no reason to use pointer difference.
A violation of MISRA C Rule 18.2 ("Subtraction between pointers
shall only be applied to pointers that address elements of the
same array") is also resolved because the object to the subtraction
is applied is not an array.

Signed-off-by: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
---
Found while randomly browsing violations of the rule on the allcode-x86_64 scan.
---
  xen/arch/x86/cpu/mcheck/mce-apei.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/cpu/mcheck/mce-apei.c b/xen/arch/x86/cpu/mcheck/mce-apei.c
index b89502088243..21aabe2027d0 100644
--- a/xen/arch/x86/cpu/mcheck/mce-apei.c
+++ b/xen/arch/x86/cpu/mcheck/mce-apei.c
@@ -74,7 +74,8 @@ int apei_write_mce(struct mce *m)
        rcd.hdr.record_id = cper_next_record_id();
        rcd.hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR;
  -     rcd.sec_hdr.section_offset = (void *)&rcd.mce - (void *)&rcd;
+       rcd.sec_hdr.section_offset = offsetof(struct cper_mce_record, mce) -
+                                    offsetof(struct cper_mce_record, hdr);

"= offsetof(struct cper_mce_record, mce);" should be sufficient since the offset of hdr is 0?

Yeah, makes sense. Given that the struct layout is coming from the UEFI spec it's not likely to change either.


Regards,
Jason

        rcd.sec_hdr.section_length = sizeof(rcd.mce);
        rcd.sec_hdr.revision = CPER_SEC_REV;
        /* fru_id and fru_text is invalid */

--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253



 


Rackspace

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