From patchwork Mon Jan 19 21:48:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1668 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859392; bh=REtq13a6qC7QE+stgZudgupr8m494YXYOVSr2sNEu04=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=nD0ayLPNmbqisdArQpINY95K/yPqPvQ45AP9DGukgAQ50K0LMrQwul/+KeTvg65MW MAMZRFd/WMfaOf3YYR1UsumrFcjpFDV1IW1PrxmnBEwctVmfJvb4FPDhlOyFv59lVl y/igXaMrLrajQzRyJozBntl+OzK8RJGP5QW0AecxzW4FIQIewKPvdAinWw8RPrVGpy JGqPQhZR9vIWaaUZ05BxY2FpGAZo2XoO/dg1AfWodziAHV50XkgxyY6oBryQcLyRhK Uw8LDkPLORcm4zsi0a7yJEdXv+d4Ga8RTrgm541zMjy8x8rLSFrIzQQsGFlQeTjJDf rTnwsYR65LLhQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2EA3469520 for ; Mon, 19 Jan 2026 14:49:52 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id HJ_h25z-E609 for ; Mon, 19 Jan 2026 14:49:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859392; bh=REtq13a6qC7QE+stgZudgupr8m494YXYOVSr2sNEu04=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=nD0ayLPNmbqisdArQpINY95K/yPqPvQ45AP9DGukgAQ50K0LMrQwul/+KeTvg65MW MAMZRFd/WMfaOf3YYR1UsumrFcjpFDV1IW1PrxmnBEwctVmfJvb4FPDhlOyFv59lVl y/igXaMrLrajQzRyJozBntl+OzK8RJGP5QW0AecxzW4FIQIewKPvdAinWw8RPrVGpy JGqPQhZR9vIWaaUZ05BxY2FpGAZo2XoO/dg1AfWodziAHV50XkgxyY6oBryQcLyRhK Uw8LDkPLORcm4zsi0a7yJEdXv+d4Ga8RTrgm541zMjy8x8rLSFrIzQQsGFlQeTjJDf rTnwsYR65LLhQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1C57869525 for ; Mon, 19 Jan 2026 14:49:52 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859390; bh=SmMDTRCv+4Uin1kF3go+xXdUadGb0RNQBMT2R/f+Xyk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MmEgt1/MBFXUDL/+nU0Aq47z7KVUreAvWckOELhk3Zc4Cq9N28z6NM35RROm/WRc9 J4u/8Drpprq/lOSv4Ut002/VMbE13KRSgun4mVtXvL8fdMUAYPwwwvNZ8cBBLDxOV/ ju72VKcJFe4UZQkuFSIJ7GjRkYln8kuUYIRkaOaWACOVeunhoY1Tzhz2+okL7naqHh ogXXr4Q+10JIW+f2ANCLYr8g7Z6RAUwzqN0XKY604zJ6N1HIeeiaAmpKnGwwnJsOyj 27pZoCq6oh4y5bwkMBWh/cdcAmX91PgeNcsDHdaAXu549cAn4kpG8vnyn461++JYJO l+cNUlXUwmKmg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 43E1469520; Mon, 19 Jan 2026 14:49:50 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id mvpJ2vMrtF6u; Mon, 19 Jan 2026 14:49:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859386; bh=PJn3hJoKbR2PL9u6UalxuNpHITHx6+UoSZW5aOrexJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OtyoEDMbUp+AEXS+r+GyRU9e84y1/OWf0SKjtkWrnCN+0xH7Q3fpJ1j2lqSNovZx3 0ciykYnm2kN7XSZExsvX0BC7/WpTF1Sz0YdXxDKO8qISgUdMKmzzqZ5oX62TBH5zV9 D73lQ9EYO/8rqbHWIowlgpYesocPnf3e6ECWZ56MBFZN1zcDzP0etjA0xR4S9A4YK0 TGNAijHAerxR/R0cK8uCyZSXyf05tHpxD3slAkbu6oAZs3EiGa11BxhNY6mLtl1kov 1cZTUqMzZCPy24S0EUbQAXjvcDMwVWOndUcPpmNsiNs2NCZVtKuQckh4qI39j5Cuvs SOuYS7OyTyXmw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id F1C416951A; Mon, 19 Jan 2026 14:49:45 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 19 Jan 2026 14:48:36 -0700 Message-ID: <20260119214846.3087611-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119214846.3087611-1-sjg@u-boot.org> References: <20260119214846.3087611-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 45GHAYIVN56CRJBNW7D6EG56EK4BOSDU X-Message-ID-Hash: 45GHAYIVN56CRJBNW7D6EG56EK4BOSDU X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/16] ext4l: Add linux/overflow.h and move struct_size List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Create include/linux/overflow.h with the struct_size() macro that calculates the size of a structure with a trailing flexible array member. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 4 ++-- include/linux/overflow.h | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 include/linux/overflow.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 69c50d406f7..310d79227b7 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -923,8 +923,8 @@ extern struct inode *iget_locked(struct super_block *sb, unsigned long ino); ssize_t generic_read_dir(struct file *f, char __user *buf, size_t count, loff_t *ppos); -/* struct_size helper */ -#define struct_size(p, member, count) (sizeof(*(p)) + sizeof((p)->member[0]) * (count)) +/* struct_size - use linux/overflow.h */ +#include /* file_operations - extended for dir.c */ struct file_operations { diff --git a/include/linux/overflow.h b/include/linux/overflow.h new file mode 100644 index 00000000000..672377ede42 --- /dev/null +++ b/include/linux/overflow.h @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Overflow checking utilities + * + * Based on Linux overflow.h + */ +#ifndef _LINUX_OVERFLOW_H +#define _LINUX_OVERFLOW_H + +#include + +/** + * struct_size() - Calculate size of structure with trailing array member + * @p: Pointer to the structure + * @member: Name of the array member + * @count: Number of elements in the array + * + * Return: Total size of the structure including @count array elements + */ +#define struct_size(p, member, count) \ + (sizeof(*(p)) + sizeof((p)->member[0]) * (count)) + +#endif /* _LINUX_OVERFLOW_H */