Skip to contentSkip to conversation

char: misc: Use IS_ERR() for filp_open() return value

PATCH In review Alper Ak 2 participants 4 messages Dec 26, 2025 – Dec 27, 2025 Char and misc drivers

lore
Share & tools
lore

Alper Ak

author
#0 lore raw

PATCH 1/1 char: misc: Use IS_ERR() for filp_open() return value

filp_open() never returns NULL, it returns either a valid pointer or an error pointer. Using IS_ERR_OR_NULL() is unnecessary. Additionally, if filp were NULL, PTR_ERR(NULL) would return 0, leading to a misleading error message.

Fixes 74d8361be344 ("char: misc: add test cases")
---
 drivers/char/misc_minor_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc_minor_kunit.c +1 -1
index 6fc8b05169c5..e930c78e1ef9 100644
@@ -166,7 +166,7 @@ static void __init miscdev_test_can_open(struct kunit *test, struct miscdevice *
 		KUNIT_FAIL(test, "failed to create node\n");
 
 	filp = filp_open(devname, O_RDONLY, 0);
-	if (IS_ERR_OR_NULL(filp))
+	if (IS_ERR(filp))
 		KUNIT_FAIL(test, "failed to open misc device: %ld\n", PTR_ERR(filp));
 	else
 		fput(filp);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 27 lines · Alper Ak

filp_open() never returns NULL, it returns either a valid pointer or an error pointer. Using IS_ERR_OR_NULL() is unnecessary. Additionally, if filp were NULL, PTR_ERR(NULL) would return 0, leading to a misleading error message.

Fixes 74d8361be344 ("char: misc: add test cases")
---
 drivers/char/misc_minor_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc_minor_kunit.c +1 -1
index 6fc8b05169c5..e930c78e1ef9 100644
@@ -166,7 +166,7 @@ static void __init miscdev_test_can_open(struct kunit *test, struct miscdevice *
 		KUNIT_FAIL(test, "failed to create node\n");
 
 	filp = filp_open(devname, O_RDONLY, 0);
-	if (IS_ERR_OR_NULL(filp))
+	if (IS_ERR(filp))
 		KUNIT_FAIL(test, "failed to open misc device: %ld\n", PTR_ERR(filp));
 	else
 		fput(filp);
Signature · 1 line
2.43.0

Also, if possible, please add the following, as this was previously reported, and I forgot to fix it:

Thanks.
Cascardo.

author
#2 lore raw

PATCH 1/1 char: misc: Use IS_ERR() for filp_open() return value

filp_open() never returns NULL, it returns either a valid pointer or an error pointer. Using IS_ERR_OR_NULL() is unnecessary. Additionally, if filp were NULL, PTR_ERR(NULL) would return 0, leading to a misleading error message.

---
 drivers/char/misc_minor_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc_minor_kunit.c +1 -1
index 6fc8b05169c5..e930c78e1ef9 100644
@@ -166,7 +166,7 @@ static void __init miscdev_test_can_open(struct kunit *test, struct miscdevice *
 		KUNIT_FAIL(test, "failed to create node\n");
 
 	filp = filp_open(devname, O_RDONLY, 0);
-	if (IS_ERR_OR_NULL(filp))
+	if (IS_ERR(filp))
 		KUNIT_FAIL(test, "failed to open misc device: %ld\n", PTR_ERR(filp));
 	else
 		fput(filp);
Signature · 1 line
2.43.0
#3 lore raw
Quoted 30 lines · Alper Ak

filp_open() never returns NULL, it returns either a valid pointer or an error pointer. Using IS_ERR_OR_NULL() is unnecessary. Additionally, if filp were NULL, PTR_ERR(NULL) would return 0, leading to a misleading error message.

---
 drivers/char/misc_minor_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/misc_minor_kunit.c +1 -1
index 6fc8b05169c5..e930c78e1ef9 100644
@@ -166,7 +166,7 @@ static void __init miscdev_test_can_open(struct kunit *test, struct miscdevice *
 		KUNIT_FAIL(test, "failed to create node\n");
 
 	filp = filp_open(devname, O_RDONLY, 0);
-	if (IS_ERR_OR_NULL(filp))
+	if (IS_ERR(filp))
 		KUNIT_FAIL(test, "failed to open misc device: %ld\n", PTR_ERR(filp));
 	else
 		fput(filp);
Signature · 1 line
2.43.0