[PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value

Christoph Hellwig hch at lst.de
Mon Oct 30 07:01:05 PDT 2023


idr_alloc returns an int that is either a negative errno, or the
identifier actually allocated.  Use signed integer ret variable to
catch the return value and only assign it to gd->first_minor to prepare
for marking the first_minor field in the gendisk structure as unsigned.

Signed-off-by: Christoph Hellwig <hch at lst.de>
---
 drivers/mtd/ubi/block.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 437c5b83ffe513..51d00b518d3197 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -402,13 +402,14 @@ int ubiblock_create(struct ubi_volume_info *vi)
 	gd->fops = &ubiblock_ops;
 	gd->major = ubiblock_major;
 	gd->minors = 1;
-	gd->first_minor = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
-	if (gd->first_minor < 0) {
+	ret = idr_alloc(&ubiblock_minor_idr, dev, 0, 0, GFP_KERNEL);
+	if (ret < 0) {
 		dev_err(disk_to_dev(gd),
 			"block: dynamic minor allocation failed");
 		ret = -ENODEV;
 		goto out_cleanup_disk;
 	}
+	gd->first_minor  = ret;
 	gd->flags |= GENHD_FL_NO_PART;
 	gd->private_data = dev;
 	sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
-- 
2.39.2




More information about the linux-mtd mailing list