From: Simon Glass <simon.glass@canonical.com> 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 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- 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 <linux/kdev_t.h> /* 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 <linux/types.h> + +/* 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 */ -- 2.43.0