From patchwork Sat Jan 17 01:14:38 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1576 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=1768612570; bh=M3bDMBz2lQhx1PxuAL/CCgbRCmReJROV0Ph0F6gbrgU=; 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=Df5CC/WEJB1UvTqn2U7VQx6lBFKDRmFYTzILGMDKJp8/hJ3PSF3eRSCE4Hla0tLks FeKs9VxLWXApwd7rT/XRhnWHPgc3qIilhRmdqGM9S7ibXLKXLXsbdgSqylBJzf1JtL DiFfLNvNTg7QhCY9eyf7T73LOC2EVt46gTXRM2lJH0C7oZIxaHGIvSx752OoYwjgf4 hiNB4+VYa5X1qiYjnurnMx+IGBDBEpZK2Eo7Wfd9qEma55bDDHQaRPmgpU/yBJDXsr qPhBmmLIBDu4Rm1Mb12hhPADG0R4mqY/PHbGqOlRVYh/RpE0PRAaU9hqrtbRg/SCt7 5zgMVB9TR+PIA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ED67A693D6 for ; Fri, 16 Jan 2026 18:16:10 -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 p7L7yt3udRU5 for ; Fri, 16 Jan 2026 18:16:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612570; bh=M3bDMBz2lQhx1PxuAL/CCgbRCmReJROV0Ph0F6gbrgU=; 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=Df5CC/WEJB1UvTqn2U7VQx6lBFKDRmFYTzILGMDKJp8/hJ3PSF3eRSCE4Hla0tLks FeKs9VxLWXApwd7rT/XRhnWHPgc3qIilhRmdqGM9S7ibXLKXLXsbdgSqylBJzf1JtL DiFfLNvNTg7QhCY9eyf7T73LOC2EVt46gTXRM2lJH0C7oZIxaHGIvSx752OoYwjgf4 hiNB4+VYa5X1qiYjnurnMx+IGBDBEpZK2Eo7Wfd9qEma55bDDHQaRPmgpU/yBJDXsr qPhBmmLIBDu4Rm1Mb12hhPADG0R4mqY/PHbGqOlRVYh/RpE0PRAaU9hqrtbRg/SCt7 5zgMVB9TR+PIA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DC3CE693F4 for ; Fri, 16 Jan 2026 18:16:10 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612568; bh=ZxqbLhuOtU6aWp62+FVMNyep0LOtza1GWlSK9GTiRfM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nLPrsQfCda4Givzpe5pR7K42Q3nxOqTyZDadvsSp3rAvkPBVGo9I+Gh0aK8ftNJ+y fT6OQwlklehhu7fLYPmtHNAZAy1yDYhNZajSXbl/O6qK9F4VDew/EOtYcoN7wL/raK SiggmtLTY2wsBLb3X8GD7Q6wu/g6RhLeDEyrIbY8mNsgvWAOd/tSlFCpCBTmiFMdKC 7IAUfS6xUajV714TIENzB5nZBQfHdup2yOvpatrp+d/diSbb0ifDiC5j3867svMtxJ f8l1rGkRkxRvpI/mHEIgeFt1j3atffy9E9FAoysolTDsgjjoHLCIRqsJ/aolweOv/n d40begc1v23Sw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B5EC8693D6; Fri, 16 Jan 2026 18:16:08 -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 RyEP6XxJtuLL; Fri, 16 Jan 2026 18:16:08 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768612563; bh=ieG7S6OaRUnNmzqujS25U+jB4wXRd5iq+bqCmr37xSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v6egAV+0NVvbvTpiuZylwvUwtLkgRcwqKThtF1bpM9zFyOyF0sr9Ct+KeK0H/xLLu 4NXDkWaZbhDHSO16Nwj6CUVp/2OY0mlnbs6Bombz7Nj1eQ1fVEXCMv/7EZ2YGcC4sK TRV8CTSfe/dHrbBeOmCUjX0cjQCKtdMZWJhIb5xW/zRn4cF6O58ylh4uIiGbEP2HgV nwwgb4bj7Yfq8wX1CeNt8H+Q49ztao9B1jtFblXdVAjt24T8fwV8r+Hjmwv11yzLbP 1Q9xKwNcjTvs3ADxtNx1BAGu6HVUoNOLVxIwbYPGmWBBn+qzMND5b2yhOQHGBBdiQd FhH94lPLgZCRg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 1F8C7693F4; Fri, 16 Jan 2026 18:16:03 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 16 Jan 2026 18:14:38 -0700 Message-ID: <20260117011448.3007171-17-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260117011448.3007171-1-sjg@u-boot.org> References: <20260117011448.3007171-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: K3ZVHHWGOW4X5A4L5QJBP5EZGFUDTRM3 X-Message-ID-Hash: K3ZVHHWGOW4X5A4L5QJBP5EZGFUDTRM3 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 16/19] linux: Add kdev_t.h header with device number macros 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 Move device-number-encoding macros to a dedicated header file that mirrors the Linux kernel organisation. kdev_t.h provides: - MINORBITS, MINORMASK - minor number parameters - MAJOR(), MINOR() - extract major/minor from dev_t - MKDEV() - create dev_t from major/minor - old_valid_dev(), old_encode_dev(), old_decode_dev() - old 8:8 format - new_encode_dev(), new_decode_dev() - new format (pass-through) Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 24 ++---------------- include/linux/kdev_t.h | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 22 deletions(-) create mode 100644 include/linux/kdev_t.h diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index f77891835cb..aa357599449 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -1086,28 +1086,8 @@ static inline unsigned int i_gid_read(const struct inode *inode) #define i_uid_update(m, a, i) do { } while (0) #define i_gid_update(m, a, i) do { } while (0) -/* Device encoding helpers */ -#ifndef MINORBITS -#define MINORBITS 20 -#endif -#ifndef MINORMASK -#define MINORMASK ((1U << MINORBITS) - 1) -#endif -#ifndef MAJOR -#define MAJOR(dev) ((unsigned int)((dev) >> MINORBITS)) -#endif -#ifndef MINOR -#define MINOR(dev) ((unsigned int)((dev) & MINORMASK)) -#endif -#ifndef MKDEV -#define MKDEV(ma, mi) (((ma) << MINORBITS) | (mi)) -#endif - -#define old_valid_dev(dev) (MAJOR(dev) < 256 && MINOR(dev) < 256) -#define old_encode_dev(dev) ((MAJOR(dev) << 8) | MINOR(dev)) -#define old_decode_dev(dev) MKDEV((dev) >> 8, (dev) & 0xff) -#define new_encode_dev(dev) ((unsigned int)(dev)) -#define new_decode_dev(dev) ((dev_t)(dev)) +/* Device encoding helpers are now in linux/kdev_t.h */ +#include /* UID/GID bit helpers */ #define low_16_bits(x) ((x) & 0xFFFF) diff --git a/include/linux/kdev_t.h b/include/linux/kdev_t.h new file mode 100644 index 00000000000..1aa524b9dca --- /dev/null +++ b/include/linux/kdev_t.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Device number macros for U-Boot + * + * Based on Linux kdev_t.h + */ +#ifndef _LINUX_KDEV_T_H +#define _LINUX_KDEV_T_H + +#include + +/* Number of minor bits */ +#ifndef MINORBITS +#define MINORBITS 20 +#endif + +/* Minor number mask */ +#ifndef MINORMASK +#define MINORMASK ((1U << MINORBITS) - 1) +#endif + +/** + * MAJOR - extract major number from dev_t + * @dev: device number + */ +#ifndef MAJOR +#define MAJOR(dev) ((unsigned int)((dev) >> MINORBITS)) +#endif + +/** + * MINOR - extract minor number from dev_t + * @dev: device number + */ +#ifndef MINOR +#define MINOR(dev) ((unsigned int)((dev) & MINORMASK)) +#endif + +/** + * MKDEV - create dev_t from major and minor numbers + * @ma: major number + * @mi: minor number + */ +#ifndef MKDEV +#define MKDEV(ma, mi) (((ma) << MINORBITS) | (mi)) +#endif + +/* Old-style device number encoding (8:8) */ +#define old_valid_dev(dev) (MAJOR(dev) < 256 && MINOR(dev) < 256) +#define old_encode_dev(dev) ((MAJOR(dev) << 8) | MINOR(dev)) +#define old_decode_dev(dev) MKDEV((dev) >> 8, (dev) & 0xff) + +/* New-style device number encoding (pass-through) */ +#define new_encode_dev(dev) ((unsigned int)(dev)) +#define new_decode_dev(dev) ((dev_t)(dev)) + +#endif /* _LINUX_KDEV_T_H */