]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
char_dev: Fix off-by-one bugs in find_dynamic_major()
authorSrivatsa S. Bhat <srivatsa@csail.mit.edu>
Tue, 6 Feb 2018 02:25:09 +0000 (18:25 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Mar 2018 16:59:24 +0000 (17:59 +0100)
CHRDEV_MAJOR_DYN_END and CHRDEV_MAJOR_DYN_EXT_END are valid major
numbers. So fix the loop iteration to include them in the search for
free major numbers.

While at it, also remove a redundant if condition ("cd->major != i"),
as it will never be true.

Signed-off-by: Srivatsa S. Bhat <srivatsa@csail.mit.edu>
Reviewed-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/char_dev.c

index a65e4a56318ca79d17c91e36c69c6aa3371728e4..33c93854216023143ba7310ddc68a2ac11314904 100644 (file)
@@ -67,18 +67,18 @@ static int find_dynamic_major(void)
        int i;
        struct char_device_struct *cd;
 
-       for (i = ARRAY_SIZE(chrdevs)-1; i > CHRDEV_MAJOR_DYN_END; i--) {
+       for (i = ARRAY_SIZE(chrdevs)-1; i >= CHRDEV_MAJOR_DYN_END; i--) {
                if (chrdevs[i] == NULL)
                        return i;
        }
 
        for (i = CHRDEV_MAJOR_DYN_EXT_START;
-            i > CHRDEV_MAJOR_DYN_EXT_END; i--) {
+            i >= CHRDEV_MAJOR_DYN_EXT_END; i--) {
                for (cd = chrdevs[major_to_index(i)]; cd; cd = cd->next)
                        if (cd->major == i)
                                break;
 
-               if (cd == NULL || cd->major != i)
+               if (cd == NULL)
                        return i;
        }