Commit 7ef0b152 authored by Chengguang Xu's avatar Chengguang Xu Committed by Greg Kroah-Hartman

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 checking
minor range overlap will avoid false-positive warning from
code analyzing tool(like Smatch) and also make the code more
easy to understand.
Suggested-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarChengguang Xu <cgxu519@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 17aa207e
...@@ -98,7 +98,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, ...@@ -98,7 +98,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
int minorct, const char *name) int minorct, const char *name)
{ {
struct char_device_struct *cd, *curr, *prev = NULL; struct char_device_struct *cd, *curr, *prev = NULL;
int ret = -EBUSY; int ret;
int i; int i;
if (major >= CHRDEV_MAJOR_MAX) { if (major >= CHRDEV_MAJOR_MAX) {
...@@ -129,6 +129,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor, ...@@ -129,6 +129,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
major = ret; major = ret;
} }
ret = -EBUSY;
i = major_to_index(major); i = major_to_index(major);
for (curr = chrdevs[i]; curr; prev = curr, curr = curr->next) { for (curr = chrdevs[i]; curr; prev = curr, curr = curr->next) {
if (curr->major < major) if (curr->major < major)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment