* [PATCH v2 0/9] char: misc: Various cleanup for miscdevice
@ 2025-07-01 15:24 Zijun Hu
2025-07-01 15:24 ` [PATCH v2 1/9] char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/ Zijun Hu
` (8 more replies)
0 siblings, 9 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
This patch series is to do cleanup for:
- Miscdevice APIs
- Miscdevice kunit test cases
- Drivers which use miscdevice APIs
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
Previous discussion link:
https://lore.kernel.org/all/20250620-rfc_miscdev-v1-1-fda25d502a37@oss.qualcomm.com
---
Zijun Hu (9):
char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/
char: misc: Adapt and add test cases for simple minor space division
char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR
char: misc: Add a reentry test case for dynamic minor request
char: misc: Make registering dynamic device reentry
char: misc: Does not request module for miscdevice with dynamic minor
char: misc: Allocate 4 more fixed minors for watchdog
char: misc: Define fixed minor EISA_EEPROM_MINOR in linux/miscdevice.h
sparc: kernel: apc: Remove macro APC_MINOR defination
arch/sparc/kernel/apc.c | 3 +-
drivers/char/Makefile | 1 +
drivers/char/misc.c | 16 +++++-
drivers/{misc => char}/misc_minor_kunit.c | 95 +++++++++++++++++++++----------
drivers/hwmon/fschmd.c | 3 +-
drivers/hwmon/w83793.c | 3 +-
drivers/misc/Makefile | 1 -
drivers/parisc/eisa_eeprom.c | 2 -
drivers/watchdog/cpwd.c | 6 +-
include/linux/miscdevice.h | 13 +++++
10 files changed, 100 insertions(+), 43 deletions(-)
---
base-commit: 626e89412dfb88766d90d842af4d9ec432d8526f
change-id: 20250701-rfc_miscdev-35dd3310c7c0
Best regards,
--
Zijun Hu <zijun.hu@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/9] char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 2/9] char: misc: Adapt and add test cases for simple minor space division Zijun Hu
` (7 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
drivers/misc/misc_minor_kunit.c is to test miscdevice APIs defined in
drivers/char/misc.c, but is not in the same directory as the later.
Move misc_minor_kunit.c to drivers/char/.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/char/Makefile | 1 +
drivers/{misc => char}/misc_minor_kunit.c | 0
drivers/misc/Makefile | 1 -
3 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index e9b360cdc99a7fee9c70eabcffe9caf763552aa2..7d10d92edcedbff5957d6c5c3426aa9400c94e43 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -6,6 +6,7 @@
obj-y += mem.o random.o
obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o
obj-y += misc.o
+obj-$(CONFIG_TEST_MISC_MINOR) += misc_minor_kunit.o
obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
obj-$(CONFIG_VIRTIO_CONSOLE) += virtio_console.o
obj-$(CONFIG_UV_MMTIMER) += uv_mmtimer.o
diff --git a/drivers/misc/misc_minor_kunit.c b/drivers/char/misc_minor_kunit.c
similarity index 100%
rename from drivers/misc/misc_minor_kunit.c
rename to drivers/char/misc_minor_kunit.c
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 917b9a7183aa1db63cc4049c042c3437f6756a1a..94f44e6c2db79dedc3839bbfb53e10cde103fbc6 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -23,7 +23,6 @@ obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o
obj-$(CONFIG_SENSORS_APDS990X) += apds990x.o
obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
obj-$(CONFIG_KGDB_TESTS) += kgdbts.o
-obj-$(CONFIG_TEST_MISC_MINOR) += misc_minor_kunit.o
obj-$(CONFIG_SGI_XP) += sgi-xp/
obj-$(CONFIG_SGI_GRU) += sgi-gru/
obj-$(CONFIG_SMPRO_ERRMON) += smpro-errmon.o
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 2/9] char: misc: Adapt and add test cases for simple minor space division
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
2025-07-01 15:24 ` [PATCH v2 1/9] char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/ Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 3/9] char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR Zijun Hu
` (6 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
Adapt and add test cases for next change which Regard minor
which > MISC_DYNAMIC_MINOR as invalid parameter when register
miscdevice, hence get a simple minor space division below:
|< 255 : Fixed minor code
|== 255 : Indicator to request dynamic minor code
|> 255 : Dynamic minor code requested, 1048320 minor codes totally.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/char/misc_minor_kunit.c | 51 +++++++++++++++++------------------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/drivers/char/misc_minor_kunit.c b/drivers/char/misc_minor_kunit.c
index 30eceac5f1b6402b0f918af6f56602ed1a6c14ec..81e2ef488a6f6ae7138c7dd8bcbeffe38aa65933 100644
--- a/drivers/char/misc_minor_kunit.c
+++ b/drivers/char/misc_minor_kunit.c
@@ -7,12 +7,6 @@
#include <linux/file.h>
#include <linux/init_syscalls.h>
-/* dynamic minor (2) */
-static struct miscdevice dev_dynamic_minor = {
- .minor = 2,
- .name = "dev_dynamic_minor",
-};
-
/* static minor (LCD_MINOR) */
static struct miscdevice dev_static_minor = {
.minor = LCD_MINOR,
@@ -25,16 +19,6 @@ static struct miscdevice dev_misc_dynamic_minor = {
.name = "dev_misc_dynamic_minor",
};
-static void kunit_dynamic_minor(struct kunit *test)
-{
- int ret;
-
- ret = misc_register(&dev_dynamic_minor);
- KUNIT_EXPECT_EQ(test, 0, ret);
- KUNIT_EXPECT_EQ(test, 2, dev_dynamic_minor.minor);
- misc_deregister(&dev_dynamic_minor);
-}
-
static void kunit_static_minor(struct kunit *test)
{
int ret;
@@ -157,13 +141,7 @@ static bool is_valid_dynamic_minor(int minor)
{
if (minor < 0)
return false;
- if (minor == MISC_DYNAMIC_MINOR)
- return false;
- if (minor >= 0 && minor <= 15)
- return false;
- if (minor >= 128 && minor < MISC_DYNAMIC_MINOR)
- return false;
- return true;
+ return minor > MISC_DYNAMIC_MINOR;
}
static int miscdev_test_open(struct inode *inode, struct file *file)
@@ -557,7 +535,7 @@ static void __init miscdev_test_conflict(struct kunit *test)
*/
miscstat.minor = miscdyn.minor;
ret = misc_register(&miscstat);
- KUNIT_EXPECT_EQ(test, ret, -EBUSY);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
if (ret == 0)
misc_deregister(&miscstat);
@@ -590,8 +568,9 @@ static void __init miscdev_test_conflict_reverse(struct kunit *test)
misc_deregister(&miscdyn);
ret = misc_register(&miscstat);
- KUNIT_EXPECT_EQ(test, ret, 0);
- KUNIT_EXPECT_EQ(test, miscstat.minor, miscdyn.minor);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+ if (ret == 0)
+ misc_deregister(&miscstat);
/*
* Try to register a dynamic minor after registering a static minor
@@ -601,20 +580,32 @@ static void __init miscdev_test_conflict_reverse(struct kunit *test)
miscdyn.minor = MISC_DYNAMIC_MINOR;
ret = misc_register(&miscdyn);
KUNIT_EXPECT_EQ(test, ret, 0);
- KUNIT_EXPECT_NE(test, miscdyn.minor, miscstat.minor);
+ KUNIT_EXPECT_EQ(test, miscdyn.minor, miscstat.minor);
KUNIT_EXPECT_TRUE(test, is_valid_dynamic_minor(miscdyn.minor));
if (ret == 0)
misc_deregister(&miscdyn);
+}
- miscdev_test_can_open(test, &miscstat);
+/* Take minor(> MISC_DYNAMIC_MINOR) as invalid when register miscdevice */
+static void __init miscdev_test_invalid_input(struct kunit *test)
+{
+ struct miscdevice misc_test = {
+ .minor = MISC_DYNAMIC_MINOR + 1,
+ .name = "misc_test",
+ .fops = &miscdev_test_fops,
+ };
+ int ret;
- misc_deregister(&miscstat);
+ ret = misc_register(&misc_test);
+ KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+ if (ret == 0)
+ misc_deregister(&misc_test);
}
static struct kunit_case test_cases[] = {
- KUNIT_CASE(kunit_dynamic_minor),
KUNIT_CASE(kunit_static_minor),
KUNIT_CASE(kunit_misc_dynamic_minor),
+ KUNIT_CASE(miscdev_test_invalid_input),
KUNIT_CASE_PARAM(miscdev_test_twice, miscdev_gen_params),
KUNIT_CASE_PARAM(miscdev_test_duplicate_minor, miscdev_gen_params),
KUNIT_CASE(miscdev_test_duplicate_name),
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 3/9] char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
2025-07-01 15:24 ` [PATCH v2 1/9] char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/ Zijun Hu
2025-07-01 15:24 ` [PATCH v2 2/9] char: misc: Adapt and add test cases for simple minor space division Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 4/9] char: misc: Add a reentry test case for dynamic minor request Zijun Hu
` (5 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
Currently, It is allowed to register miscdevice with minor > 255
which is defined by macro MISC_DYNAMIC_MINOR, and cause:
- Chaos regarding divison and management of minor codes.
- Registering failure if the minor was allocated to other dynamic request.
Fortunately, in-kernel users have not had such usage yet.
Fix by explicitly refusing to register miscdev whose minor > 255.
Also bring in very simple minor code space division and management:
|< 255 : Fixed minor code
|== 255 : Indicator to request dynamic minor code
|> 255 : Dynamic minor code requested, 1048320 minor codes totally
And all fixed minors allocated should be registered in 'linux/miscdevice.h'
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/char/misc.c | 6 ++++++
include/linux/miscdevice.h | 8 ++++++++
2 files changed, 14 insertions(+)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 558302a64dd908aee30341547a5413df1af71459..b8e66466184fa21fb66d968db7950e0b5669ac43 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -210,6 +210,12 @@ int misc_register(struct miscdevice *misc)
int err = 0;
bool is_dynamic = (misc->minor == MISC_DYNAMIC_MINOR);
+ if (misc->minor > MISC_DYNAMIC_MINOR) {
+ pr_err("Invalid fixed minor %d for miscdevice '%s'\n",
+ misc->minor, misc->name);
+ return -EINVAL;
+ }
+
INIT_LIST_HEAD(&misc->list);
mutex_lock(&misc_mtx);
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 3e6deb00fc8535a7571f85489c74979e18385bad..565b88efeb23d02b7d91df1cd7df4bdcf2898224 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -71,6 +71,14 @@
#define USERIO_MINOR 240
#define VHOST_VSOCK_MINOR 241
#define RFKILL_MINOR 242
+
+/*
+ * Misc char device minor code space division related to below macro:
+ *
+ * < 255 : Fixed minor code
+ * == 255 : Indicator to request dynamic minor code
+ * > 255 : Dynamic minor code requested, 1048320 minor codes totally.
+ */
#define MISC_DYNAMIC_MINOR 255
struct miscdevice {
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 4/9] char: misc: Add a reentry test case for dynamic minor request
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
` (2 preceding siblings ...)
2025-07-01 15:24 ` [PATCH v2 3/9] char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 5/9] char: misc: Make registering dynamic device reentry Zijun Hu
` (4 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
Add a case to test reentry for requesting dynamic minor:
1) Provide Both @dev_A and @dev_B want to request dynamic minor by
initializing their member minor to MISC_DYNAMIC_MINOR.
2) Register then de-register @dev_A.
3) Register @dev_B.
4) Register @dev_A again without reinitialization.
5) Check if @dev_A can be registered successfully.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/char/misc_minor_kunit.c | 44 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/drivers/char/misc_minor_kunit.c b/drivers/char/misc_minor_kunit.c
index 81e2ef488a6f6ae7138c7dd8bcbeffe38aa65933..9f1f77c04f9f1be56bc94cab4127ecb941e128b2 100644
--- a/drivers/char/misc_minor_kunit.c
+++ b/drivers/char/misc_minor_kunit.c
@@ -602,6 +602,49 @@ static void __init miscdev_test_invalid_input(struct kunit *test)
misc_deregister(&misc_test);
}
+/*
+ * Verify if @miscdyn_a can still be registered successfully without
+ * reinitialization even if its minor ever owned was requested by
+ * another miscdevice such as @miscdyn_b.
+ */
+static void __init miscdev_test_dynamic_reentry(struct kunit *test)
+{
+ struct miscdevice miscdyn_a = {
+ .name = "miscdyn_a",
+ .minor = MISC_DYNAMIC_MINOR,
+ .fops = &miscdev_test_fops,
+ };
+ struct miscdevice miscdyn_b = {
+ .name = "miscdyn_b",
+ .minor = MISC_DYNAMIC_MINOR,
+ .fops = &miscdev_test_fops,
+ };
+ int ret, minor_a;
+
+ ret = misc_register(&miscdyn_a);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ KUNIT_EXPECT_TRUE(test, is_valid_dynamic_minor(miscdyn_a.minor));
+ minor_a = miscdyn_a.minor;
+ if (ret != 0)
+ return;
+ misc_deregister(&miscdyn_a);
+
+ ret = misc_register(&miscdyn_b);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ KUNIT_EXPECT_EQ(test, miscdyn_b.minor, minor_a);
+ if (ret != 0)
+ return;
+
+ ret = misc_register(&miscdyn_a);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+ KUNIT_EXPECT_TRUE(test, is_valid_dynamic_minor(miscdyn_a.minor));
+ KUNIT_EXPECT_NE(test, miscdyn_a.minor, miscdyn_b.minor);
+ if (ret == 0)
+ misc_deregister(&miscdyn_a);
+
+ misc_deregister(&miscdyn_b);
+}
+
static struct kunit_case test_cases[] = {
KUNIT_CASE(kunit_static_minor),
KUNIT_CASE(kunit_misc_dynamic_minor),
@@ -611,6 +654,7 @@ static struct kunit_case test_cases[] = {
KUNIT_CASE(miscdev_test_duplicate_name),
KUNIT_CASE(miscdev_test_duplicate_name_leak),
KUNIT_CASE_PARAM(miscdev_test_duplicate_error, miscdev_gen_params),
+ KUNIT_CASE(miscdev_test_dynamic_reentry),
{}
};
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 5/9] char: misc: Make registering dynamic device reentry
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
` (3 preceding siblings ...)
2025-07-01 15:24 ` [PATCH v2 4/9] char: misc: Add a reentry test case for dynamic minor request Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 6/9] char: misc: Does not request module for miscdevice with dynamic minor Zijun Hu
` (3 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
misc_deregister() frees dynamic minor but does not reset @misc->minor
and cause kunit test case miscdev_test_dynamic_reentry() failure:
| Invalid fixed minor 257 for miscdevice 'miscdyn_a'
| #miscdev_test_dynamic_reentry: ASSERTION FAILED at misc_minor_kunit.c:639
| Expected ret == 0, but
| ret == -22 (0xffffffffffffffea)
| [FAILED] miscdev_test_dynamic_reentry
Fix by resetting dynamic minor in misc_deregister() as error handling
of misc_register() does.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/char/misc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index b8e66466184fa21fb66d968db7950e0b5669ac43..96ed343cf5c8509a09855020049a9af82a3ede95 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -288,6 +288,8 @@ void misc_deregister(struct miscdevice *misc)
list_del(&misc->list);
device_destroy(&misc_class, MKDEV(MISC_MAJOR, misc->minor));
misc_minor_free(misc->minor);
+ if (misc->minor > MISC_DYNAMIC_MINOR)
+ misc->minor = MISC_DYNAMIC_MINOR;
mutex_unlock(&misc_mtx);
}
EXPORT_SYMBOL(misc_deregister);
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 6/9] char: misc: Does not request module for miscdevice with dynamic minor
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
` (4 preceding siblings ...)
2025-07-01 15:24 ` [PATCH v2 5/9] char: misc: Make registering dynamic device reentry Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog Zijun Hu
` (2 subsequent siblings)
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
misc_open() may request module for miscdevice with dynamic minor
which is meaningless since macro MODULE_ALIAS_MISCDEV() is not
applicable for dynamic minor.
Fix by only requesting module for miscdevice with fixed minor.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/char/misc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 96ed343cf5c8509a09855020049a9af82a3ede95..a0aae0fc792666a7bdc0ba00da9dc02ff9cead42 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -132,7 +132,8 @@ static int misc_open(struct inode *inode, struct file *file)
break;
}
- if (!new_fops) {
+ /* Only request module for fixed minor code */
+ if (!new_fops && minor < MISC_DYNAMIC_MINOR) {
mutex_unlock(&misc_mtx);
request_module("char-major-%d-%d", MISC_MAJOR, minor);
mutex_lock(&misc_mtx);
@@ -144,10 +145,11 @@ static int misc_open(struct inode *inode, struct file *file)
new_fops = fops_get(iter->fops);
break;
}
- if (!new_fops)
- goto fail;
}
+ if (!new_fops)
+ goto fail;
+
/*
* Place the miscdevice in the file's
* private_data so it can be used by the
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
` (5 preceding siblings ...)
2025-07-01 15:24 ` [PATCH v2 6/9] char: misc: Does not request module for miscdevice with dynamic minor Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 18:45 ` Arnd Bergmann
2025-07-01 15:24 ` [PATCH v2 8/9] char: misc: Define fixed minor EISA_EEPROM_MINOR in linux/miscdevice.h Zijun Hu
2025-07-01 15:24 ` [PATCH v2 9/9] sparc: kernel: apc: Remove macro APC_MINOR defination Zijun Hu
8 siblings, 1 reply; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
There are drivers which needs more fixed minors for watchdog, but
watchdog only has one fixed minor currently, it causes hardcoded and
unregistered fixed minors are used by these drivers.
Allocate 4 more fixed minors and apply for these drivers.
---
drivers/hwmon/fschmd.c | 3 ++-
drivers/hwmon/w83793.c | 3 ++-
drivers/watchdog/cpwd.c | 6 +++---
include/linux/miscdevice.h | 4 ++++
4 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index a303959879efddd9bfc02e8c25766e67b1a4af8e..7ffaec12eea8473a7dd17d7477db9157230e7f31 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -1084,7 +1084,8 @@ static int fschmd_probe(struct i2c_client *client)
struct fschmd_data *data;
static const char * const names[7] = { "Poseidon", "Hermes", "Scylla",
"Heracles", "Heimdall", "Hades", "Syleus" };
- static const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 };
+ static const int watchdog_minors[] = { WATCHDOG_MINOR, WATCHDOG_MINOR_1,
+ WATCHDOG_MINOR_2, WATCHDOG_MINOR_3, WATCHDOG_MINOR_4 };
int i, err;
enum chips kind = (uintptr_t)i2c_get_match_data(client);
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 67728f60333fe351715ccc03097f9aa2e135f384..fb4d76c87ea26366586f6f6bc2bee4f76a430880 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -1642,7 +1642,8 @@ static int w83793_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
static const int watchdog_minors[] = {
- WATCHDOG_MINOR, 212, 213, 214, 215
+ WATCHDOG_MINOR, WATCHDOG_MINOR_1, WATCHDOG_MINOR_2,
+ WATCHDOG_MINOR_3, WATCHDOG_MINOR_4
};
struct w83793_data *data;
int i, tmp, val, err;
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index 13a4d47e68cd82572f103c37ec066384cc5f7cd7..7891ea8f87451ddfb377e90706310a73324fb0ce 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -44,9 +44,9 @@
#define WD_BTIMEOUT (jiffies + (HZ * 1000))
#define WD_BLIMIT 0xFFFF
-#define WD0_MINOR 212
-#define WD1_MINOR 213
-#define WD2_MINOR 214
+#define WD0_MINOR WATCHDOG_MINOR_1
+#define WD1_MINOR WATCHDOG_MINOR_2
+#define WD2_MINOR WATCHDOG_MINOR_3
/* Internal driver definitions. */
#define WD0_ID 0
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index 565b88efeb23d02b7d91df1cd7df4bdcf2898224..c33839df8bd261bf1ab841b7e50afe3f8b0b007e 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -52,6 +52,10 @@
#define PXA3XX_GCU_MINOR 197
#define TUN_MINOR 200
#define CUSE_MINOR 203
+#define WATCHDOG_MINOR_1 212
+#define WATCHDOG_MINOR_2 213
+#define WATCHDOG_MINOR_3 214
+#define WATCHDOG_MINOR_4 215
#define MWAVE_MINOR 219 /* ACP/Mwave Modem */
#define MPT_MINOR 220
#define MPT2SAS_MINOR 221
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 8/9] char: misc: Define fixed minor EISA_EEPROM_MINOR in linux/miscdevice.h
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
` (6 preceding siblings ...)
2025-07-01 15:24 ` [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 9/9] sparc: kernel: apc: Remove macro APC_MINOR defination Zijun Hu
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
Move fixed minor EISA_EEPROM_MINOR defination to 'linux/miscdevice.h'.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
drivers/parisc/eisa_eeprom.c | 2 --
include/linux/miscdevice.h | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/parisc/eisa_eeprom.c b/drivers/parisc/eisa_eeprom.c
index 443b15422fc179c7379082bb165ea2bb80785fb3..601cbb22574fd64b0c6be568442d5064d38a2c20 100644
--- a/drivers/parisc/eisa_eeprom.c
+++ b/drivers/parisc/eisa_eeprom.c
@@ -15,8 +15,6 @@
#include <linux/uaccess.h>
#include <asm/eisa_eeprom.h>
-#define EISA_EEPROM_MINOR 241
-
static loff_t eisa_eeprom_llseek(struct file *file, loff_t offset, int origin)
{
return fixed_size_llseek(file, offset, origin, HPEE_MAX_LENGTH);
diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h
index c33839df8bd261bf1ab841b7e50afe3f8b0b007e..632263f4d8393701022dd31942f58e901dc087b0 100644
--- a/include/linux/miscdevice.h
+++ b/include/linux/miscdevice.h
@@ -74,6 +74,7 @@
#define UHID_MINOR 239
#define USERIO_MINOR 240
#define VHOST_VSOCK_MINOR 241
+#define EISA_EEPROM_MINOR 241
#define RFKILL_MINOR 242
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v2 9/9] sparc: kernel: apc: Remove macro APC_MINOR defination
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
` (7 preceding siblings ...)
2025-07-01 15:24 ` [PATCH v2 8/9] char: misc: Define fixed minor EISA_EEPROM_MINOR in linux/miscdevice.h Zijun Hu
@ 2025-07-01 15:24 ` Zijun Hu
8 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-01 15:24 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E.J. Bottomley,
Helge Deller, David S. Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, Zijun Hu, linux-kernel,
linux-hwmon, linux-watchdog, linux-parisc, sparclinux, Zijun Hu
From: Zijun Hu <zijun.hu@oss.qualcomm.com>
Macro APC_MINOR is defined as MISC_DYNAMIC_MINOR to request dynamic
minor, but its name 'APC_MINOR' looks like fixed minor.
Remove the macro defination and directly use MISC_DYNAMIC_MINOR instead.
Signed-off-by: Zijun Hu <zijun.hu@oss.qualcomm.com>
---
arch/sparc/kernel/apc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/apc.c b/arch/sparc/kernel/apc.c
index d44725d37e30f388bf8cf19d72baf720f94da084..849db20e7165cdf48d4d36cf770dd6aaaa191b41 100644
--- a/arch/sparc/kernel/apc.c
+++ b/arch/sparc/kernel/apc.c
@@ -28,7 +28,6 @@
* #define APC_DEBUG_LED
*/
-#define APC_MINOR MISC_DYNAMIC_MINOR
#define APC_OBPNAME "power-management"
#define APC_DEVNAME "apc"
@@ -138,7 +137,7 @@ static const struct file_operations apc_fops = {
.llseek = noop_llseek,
};
-static struct miscdevice apc_miscdev = { APC_MINOR, APC_DEVNAME, &apc_fops };
+static struct miscdevice apc_miscdev = { MISC_DYNAMIC_MINOR, APC_DEVNAME, &apc_fops };
static int apc_probe(struct platform_device *op)
{
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog
2025-07-01 15:24 ` [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog Zijun Hu
@ 2025-07-01 18:45 ` Arnd Bergmann
2025-07-02 12:13 ` Zijun Hu
0 siblings, 1 reply; 12+ messages in thread
From: Arnd Bergmann @ 2025-07-01 18:45 UTC (permalink / raw)
To: Zijun Hu, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E . J . Bottomley,
Helge Deller, David S . Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, linux-kernel, linux-hwmon,
linux-watchdog, linux-parisc, sparclinux, Zijun Hu
On Tue, Jul 1, 2025, at 17:24, Zijun Hu wrote:
> From: Zijun Hu <zijun.hu@oss.qualcomm.com>
>
> There are drivers which needs more fixed minors for watchdog, but
> watchdog only has one fixed minor currently, it causes hardcoded and
> unregistered fixed minors are used by these drivers.
>
> Allocate 4 more fixed minors and apply for these drivers.
Missing signoff?
I don't think this is the right fix here, these drivers implement
the normal watchdog API, so they should not even call misc_register
but should instead call watchdog_dev_register().
Obviously doing this right is a bigger change, so maybe the simpler
answer is to use dynamic minors instead of the nonstandard ones.
FWIW, I double-checked to see whether there are any in-tree
references to these two drivers, and there is one each:
drivers/i2c/busses/i2c-i801.c: { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
drivers/i2c/busses/i2c-i801.c: { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
drivers/i2c/busses/i2c-i801.c: { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
arch/powerpc/boot/dts/fsl/t4240rdb.dts: compatible = "winbond,w83793";
These were added in 2009 and 2016, respectively, so the hardware
is probably around somewhere but quite hard to find.
Arnd
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog
2025-07-01 18:45 ` Arnd Bergmann
@ 2025-07-02 12:13 ` Zijun Hu
0 siblings, 0 replies; 12+ messages in thread
From: Zijun Hu @ 2025-07-02 12:13 UTC (permalink / raw)
To: Arnd Bergmann, Greg Kroah-Hartman, Jean Delvare, Guenter Roeck,
Rudolf Marek, Wim Van Sebroeck, James E . J . Bottomley,
Helge Deller, David S . Miller, Andreas Larsson
Cc: Thadeu Lima de Souza Cascardo, linux-kernel, linux-hwmon,
linux-watchdog, linux-parisc, sparclinux, Zijun Hu
On 2025/7/2 02:45, Arnd Bergmann wrote:
> On Tue, Jul 1, 2025, at 17:24, Zijun Hu wrote:
>> From: Zijun Hu <zijun.hu@oss.qualcomm.com>
>>
>> There are drivers which needs more fixed minors for watchdog, but
>> watchdog only has one fixed minor currently, it causes hardcoded and
>> unregistered fixed minors are used by these drivers.
>>
>> Allocate 4 more fixed minors and apply for these drivers.
>
> Missing signoff?
my mistake. thank you for pointing out.
>
>
> I don't think this is the right fix here, these drivers implement
> the normal watchdog API, so they should not even call misc_register
> but should instead call watchdog_dev_register().
>
agree
Documentation/watchdog/convert_drivers_to_kernel_api.rst indeed suggests
convert old watchdog implementation to new one using watchdog framework.
> Obviously doing this right is a bigger change, so maybe the simpler
> answer is to use dynamic minors instead of the nonstandard ones.
>
yes. it is feasible.
> FWIW, I double-checked to see whether there are any in-tree
> references to these two drivers, and there is one each:
>
> drivers/i2c/busses/i2c-i801.c: { "Hermes", DMI_DEV_TYPE_OTHER, 0x73, "fscher" },
> drivers/i2c/busses/i2c-i801.c: { "Hades", DMI_DEV_TYPE_OTHER, 0x73, "fschds" },
> drivers/i2c/busses/i2c-i801.c: { "Syleus", DMI_DEV_TYPE_OTHER, 0x73, "fscsyl" },
> arch/powerpc/boot/dts/fsl/t4240rdb.dts: compatible = "winbond,w83793";
>
> These were added in 2009 and 2016, respectively, so the hardware
> is probably around somewhere but quite hard to find.
>
let me drop this change in next revision.
may try to convert them by following the guidance at my spare time.
> Arnd
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-07-02 12:13 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-01 15:24 [PATCH v2 0/9] char: misc: Various cleanup for miscdevice Zijun Hu
2025-07-01 15:24 ` [PATCH v2 1/9] char: misc: Move drivers/misc/misc_minor_kunit.c to drivers/char/ Zijun Hu
2025-07-01 15:24 ` [PATCH v2 2/9] char: misc: Adapt and add test cases for simple minor space division Zijun Hu
2025-07-01 15:24 ` [PATCH v2 3/9] char: misc: Disallow registering miscdevice whose minor > MISC_DYNAMIC_MINOR Zijun Hu
2025-07-01 15:24 ` [PATCH v2 4/9] char: misc: Add a reentry test case for dynamic minor request Zijun Hu
2025-07-01 15:24 ` [PATCH v2 5/9] char: misc: Make registering dynamic device reentry Zijun Hu
2025-07-01 15:24 ` [PATCH v2 6/9] char: misc: Does not request module for miscdevice with dynamic minor Zijun Hu
2025-07-01 15:24 ` [PATCH v2 7/9] char: misc: Allocate 4 more fixed minors for watchdog Zijun Hu
2025-07-01 18:45 ` Arnd Bergmann
2025-07-02 12:13 ` Zijun Hu
2025-07-01 15:24 ` [PATCH v2 8/9] char: misc: Define fixed minor EISA_EEPROM_MINOR in linux/miscdevice.h Zijun Hu
2025-07-01 15:24 ` [PATCH v2 9/9] sparc: kernel: apc: Remove macro APC_MINOR defination Zijun Hu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).