linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value
@ 2023-10-30 14:01 Christoph Hellwig
  2023-10-30 14:01 ` [PATCH 2/2] block: dev_t components are unsigned Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-10-30 14:01 UTC (permalink / raw)
  To: axboe, richard, miquel.raynal, vigneshr
  Cc: linux-block, linux-mtd, zhongjinghua, yukuai1

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@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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] block: dev_t components are unsigned
  2023-10-30 14:01 [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Christoph Hellwig
@ 2023-10-30 14:01 ` Christoph Hellwig
  2023-10-30 14:05 ` [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Daniel Golle
  2023-10-30 14:46 ` Richard Weinberger
  2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-10-30 14:01 UTC (permalink / raw)
  To: axboe, richard, miquel.raynal, vigneshr
  Cc: linux-block, linux-mtd, zhongjinghua, yukuai1

... thus mark the major, first_minor and minors fields in struct gendisk
as such.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/genhd.c          | 4 ++--
 include/linux/blkdev.h | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index cc32a0c704eb84..ceeb30518db696 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -180,7 +180,7 @@ void blkdev_show(struct seq_file *seqf, off_t offset)
 	spin_lock(&major_names_spinlock);
 	for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next)
 		if (dp->major == offset)
-			seq_printf(seqf, "%3d %s\n", dp->major, dp->name);
+			seq_printf(seqf, "%3u %s\n", dp->major, dp->name);
 	spin_unlock(&major_names_spinlock);
 }
 #endif /* CONFIG_PROC_FS */
@@ -896,7 +896,7 @@ static ssize_t disk_range_show(struct device *dev,
 {
 	struct gendisk *disk = dev_to_disk(dev);
 
-	return sprintf(buf, "%d\n", disk->minors);
+	return sprintf(buf, "%u\n", disk->minors);
 }
 
 static ssize_t disk_ext_range_show(struct device *dev,
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index eef450f259828d..3ecf928d6325b6 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -130,9 +130,9 @@ struct gendisk {
 	 * major/first_minor/minors should not be set by any new driver, the
 	 * block core will take care of allocating them automatically.
 	 */
-	int major;
-	int first_minor;
-	int minors;
+	unsigned int major;
+	unsigned int first_minor;
+	unsigned int minors;
 
 	char disk_name[DISK_NAME_LEN];	/* name of major driver */
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value
  2023-10-30 14:01 [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Christoph Hellwig
  2023-10-30 14:01 ` [PATCH 2/2] block: dev_t components are unsigned Christoph Hellwig
@ 2023-10-30 14:05 ` Daniel Golle
  2023-10-30 14:46 ` Richard Weinberger
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Golle @ 2023-10-30 14:05 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: axboe, richard, miquel.raynal, vigneshr, linux-block, linux-mtd,
	zhongjinghua, yukuai1

On Mon, Oct 30, 2023 at 03:01:05PM +0100, Christoph Hellwig wrote:
> 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@lst.de>

Reviewed-by: Daniel Golle <daniel@makrotopia.org>

> ---
>  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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value
  2023-10-30 14:01 [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Christoph Hellwig
  2023-10-30 14:01 ` [PATCH 2/2] block: dev_t components are unsigned Christoph Hellwig
  2023-10-30 14:05 ` [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Daniel Golle
@ 2023-10-30 14:46 ` Richard Weinberger
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Weinberger @ 2023-10-30 14:46 UTC (permalink / raw)
  To: hch
  Cc: Jens Axboe, Miquel Raynal, Vignesh Raghavendra, linux-block,
	linux-mtd, zhongjinghua, yukuai1

----- Ursprüngliche Mail -----
> 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@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;

Super minor nit, redundant space.

Acked-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-30 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-30 14:01 [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Christoph Hellwig
2023-10-30 14:01 ` [PATCH 2/2] block: dev_t components are unsigned Christoph Hellwig
2023-10-30 14:05 ` [PATCH 1/2] ubi: block: don't use gendisk->first_minor for the idr_alloc return value Daniel Golle
2023-10-30 14:46 ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).