Skip to contentSkip to conversation

chardev: set variable ret to -EBUSY before checking minor range overlap

PATCH Superseded Chengguang Xu 2 participants 2 messages Apr 5, 2019 – Apr 25, 2019 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chardev: set variable ret to -EBUSY before checking minor range overlap

When allocating dynamic major, the minor range overlap check in __register_chrdev_region() will not fail, so actually there is no real case to passing non negative error code to caller. However, set variable ret to -EBUSY before chekcking minor range overlap will avoid false-positive warning from code analyzing tool(like Smatch) and also make the code more easy to understand.

---
 fs/char_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/char_dev.c +2 -1
index df6a54045ac4..00dfe17871ac 100644
@@ -98,7 +98,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
 			   int minorct, const char *name)
 {
 	struct char_device_struct *cd, *curr, *prev = NULL;
-	int ret -EBUSY;
+	int ret;
 	int i;
 
 	if (major >= CHRDEV_MAJOR_MAX) {
@@ -129,6 +129,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
 		major = ret;
 	}
 
+	ret = -EBUSY;
 	i = major_to_index(major);
 	for (curr = chrdevs[i]; curr; prev = curr, curr = curr->next) {
 		if (curr->major < major)

--
2.17.2

#1 lore raw
Quoted 8 lines · Chengguang Xu

When allocating dynamic major, the minor range overlap check in __register_chrdev_region() will not fail, so actually there is no real case to passing non negative error code to caller. However, set variable ret to -EBUSY before chekcking minor range overlap will avoid false-positive warning from code analyzing tool(like Smatch) and also make the code more easy to understand.

Quoted 5 lines
---
 fs/char_dev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

What tree was this patch made against? I can't seem to apply it anywhere :(

Please fix up and resend.

thanks,

greg k-h