Skip to contentSkip to conversation

char: misc: register chrdev region with all possible minors

PATCH In review Thadeu Lima de Souza Cascardo 2 participants 2 messages Mar 17, 2025 – Mar 21, 2025 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 char: misc: register chrdev region with all possible minors

register_chrdev will only register the first 256 minors of a major chrdev. That means that dynamically allocated misc devices with minor above 255 will fail to open with -ENXIO.

This was found by kernel test robot when testing a different change that makes all dynamically allocated minors be above 255. This has, however, been separately tested by creating 256 serio_raw devices with the help of userio driver.

Ever since allowing misc devices with minors above 128, this has been possible.

Fix it by registering all minor numbers from 0 to MINORMASK + 1 for MISC_MAJOR.

Fixes ab760791c0cf ("char: misc: Increase the maximum number of dynamic misc devices to 1048448")
---
 drivers/char/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc.c +1 -1
index f7dd455dd0dd3c7c9956e772b5ab8bd83a67a4a6..dda466f9181acf76564b5e41ed6e858928e56182 100644
@@ -315,7 +315,7 @@ static int __init misc_init(void)
 		goto fail_remove;
 
 	err = -EIO;
-	if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
+	if (__register_chrdev(MISC_MAJOR, 0, MINORMASK + 1, "misc", &misc_fops))
 		goto fail_printk;
 	return 0;
 

---
base-commit: 2dc25093218f5d42391549de6fe45e1aa9325676
change-id: 20250317-misc-chrdev-b26b572a47fc

Best regards,

Signature · 1 line
Thadeu Lima de Souza Cascardo <[email protected]>
Tested-by on v1 1/1
#1 lore raw
Quoted 41 lines · Thadeu Lima de Souza Cascardo

register_chrdev will only register the first 256 minors of a major chrdev. That means that dynamically allocated misc devices with minor above 255 will fail to open with -ENXIO.

This was found by kernel test robot when testing a different change that makes all dynamically allocated minors be above 255. This has, however, been separately tested by creating 256 serio_raw devices with the help of userio driver.

Ever since allowing misc devices with minors above 128, this has been possible.

Fix it by registering all minor numbers from 0 to MINORMASK + 1 for MISC_MAJOR.

Fixes ab760791c0cf ("char: misc: Increase the maximum number of dynamic misc devices to 1048448")
---
 drivers/char/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc.c +1 -2
index f7dd455dd0dd3c7c9956e772b5ab8bd83a67a4a6..dda466f9181acf76564b5e41ed6e858928e56182 100644
@@ -315,7 +315,7 @@ static int __init misc_init(void)
 		goto fail_remove;
 
 	err = -EIO;
-	if (register_chrdev(MISC_MAJOR, "misc", &misc_fops))
+	if (__register_chrdev(MISC_MAJOR, 0, MINORMASK + 1, "misc", &misc_fops))
 		goto fail_printk;
 	return 0;
 
 
---

base-commit: 2dc25093218f5d42391549de6fe45e1aa9325676
change-id: 20250317-misc-chrdev-b26b572a47fc

Quoted 5 lines

Best regards,

Signature · 1 line
Thadeu Lima de Souza Cascardo <[email protected]>

Thank you for the fixes; we encountered the same problem in our environment as well.