lightnvm: fix off-by-one error on target initialization
authorMatias Bjørling <matias@cnexlabs.com>
Wed, 15 Feb 2017 15:25:32 +0000 (16:25 +0100)
committerJens Axboe <axboe@fb.com>
Wed, 15 Feb 2017 15:27:19 +0000 (08:27 -0700)
If one specifies the end lun id to be the absolute number of luns,
without taking zero indexing into account, the lightnvm core will pass
the off-by-one end lun id to target creation, which then panics during
nvm_ioctl_dev_create.

Signed-off-by: Matias Bjørling <matias@cnexlabs.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/lightnvm/core.c

index 9bfe0352d0930b5631a339901956b24e05199c4d..6ce76c0a75e12f379cb6bb00f86985060991a86f 100644 (file)
@@ -1102,9 +1102,9 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
        }
        s = &create->conf.s;
 
-       if (s->lun_begin > s->lun_end || s->lun_end > dev->geo.nr_luns) {
+       if (s->lun_begin > s->lun_end || s->lun_end >= dev->geo.nr_luns) {
                pr_err("nvm: lun out of bound (%u:%u > %u)\n",
-                       s->lun_begin, s->lun_end, dev->geo.nr_luns);
+                       s->lun_begin, s->lun_end, dev->geo.nr_luns - 1);
                return -EINVAL;
        }