md/raid5: cap worker count
authorShaohua Li <shli@fb.com>
Thu, 21 Sep 2017 18:03:52 +0000 (11:03 -0700)
committerShaohua Li <shli@fb.com>
Thu, 28 Sep 2017 03:08:44 +0000 (20:08 -0700)
static checker reports a potential integer overflow. Cap the worker count to
avoid the overflow.

Reported:-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Shaohua Li <shli@fb.com>
drivers/md/raid5.c

index 076409455b603582f589ea8fcc68173d421ca33a..928e24a071338ab6e1fe7668c8caa42b2803ccfe 100644 (file)
@@ -6575,14 +6575,17 @@ static ssize_t
 raid5_store_group_thread_cnt(struct mddev *mddev, const char *page, size_t len)
 {
        struct r5conf *conf;
-       unsigned long new;
+       unsigned int new;
        int err;
        struct r5worker_group *new_groups, *old_groups;
        int group_cnt, worker_cnt_per_group;
 
        if (len >= PAGE_SIZE)
                return -EINVAL;
-       if (kstrtoul(page, 10, &new))
+       if (kstrtouint(page, 10, &new))
+               return -EINVAL;
+       /* 8192 should be big enough */
+       if (new > 8192)
                return -EINVAL;
 
        err = mddev_lock(mddev);