Skip to content

Commit

Permalink
chardev: set variable ret to -EBUSY before checking minor range overlap
Browse files Browse the repository at this point in the history
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: Dan Carpenter <[email protected]>
Signed-off-by: Chengguang Xu <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Chengguang Xu authored and gregkh committed May 24, 2019
1 parent 17aa207 commit 7ef0b15
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/char_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7ef0b15

Please sign in to comment.