diff mbox series

[v2] block: nbd: fix sanity check for first_minor

Message ID 20211011024509.2012-1-ukernel@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v2] block: nbd: fix sanity check for first_minor | expand

Commit Message

Yan, Zheng Oct. 11, 2021, 2:45 a.m. UTC
From: "Yan, Zheng" <yanzheng03@kuaishou.com>

Device's minor is a 20-bits number, max value is 0xfffff.

Fixes: b1a811633f ("block: nbd: add sanity check for first_minor").
Signed-off-by: "Yan, Zheng" <yanzheng03@kuaishou.com>
---
 drivers/block/nbd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christoph Hellwig Oct. 11, 2021, 7:35 a.m. UTC | #1
On Mon, Oct 11, 2021 at 10:45:09AM +0800, Yan, Zheng wrote:
> From: "Yan, Zheng" <yanzheng03@kuaishou.com>
> 
> Device's minor is a 20-bits number, max value is 0xfffff.

I'd just drop this check again now that we do have proper error
handling in add_disk.
diff mbox series

Patch

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 1183f7872b71..118039d35468 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1750,10 +1750,10 @@  static struct nbd_device *nbd_dev_add(int index, unsigned int refs)
 
 	/* Too big first_minor can cause duplicate creation of
 	 * sysfs files/links, since first_minor will be truncated to
-	 * byte in __device_add_disk().
+	 * 20-bits number in __device_add_disk().
 	 */
 	disk->first_minor = index << part_shift;
-	if (disk->first_minor > 0xff) {
+	if (disk->first_minor > MINORMASK) {
 		err = -EINVAL;
 		goto out_free_idr;
 	}