block: first batch of add_disk() error handling conversions
Subsystems (7)
PATCH v4 5/6 loop: add error handling support for add_disk()
In reply to Luis ChamberlainWe never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
--- drivers/block/loop.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/block/loop.c +7 -1
@@ -2394,13 +2394,19 @@ static int loop_add(int i) disk->event_flags =DISK_EVENT_FLAG_UEVENT ;sprintf (disk->disk_name,"loop%d" , i);/* Make this loop device reachable from pathname. */ -add_disk (disk); + err =add_disk (disk); +if (err) + goto out_cleanup_disk; +/* Show this loop device. */ mutex_lock (&loop_ctl_mutex); lo->idr_visible = true;mutex_unlock (&loop_ctl_mutex); +return i; +out_cleanup_disk: +blk_cleanup_disk (disk); out_cleanup_tags:blk_mq_free_tag_set (&lo->tag_set); out_free_idr:
Signature · 7 lines
2.30.2 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH v4 1/6 scsi/sd: add error handling support for add_disk()
In reply to Luis ChamberlainWe never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
As with the error handling for device_add() we follow the same logic and just put the device so that cleanup is done via the scsi_disk_release().
--- drivers/scsi/sd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +7 -1
@@ -3449,7 +3449,13 @@ static int sd_probe(struct device *dev)pm_runtime_set_autosuspend_delay (dev, sdp->host->hostt->rpm_autosuspend_delay); } -device_add_disk (dev, gd,NULL ); + + error =device_add_disk (dev, gd,NULL ); +if (error) { +put_device (&sdkp->dev); + goto out; + } +if (sdkp->capacity)sd_dif_config_host (sdkp);
Signature · 1 line
2.30.2
v4 cover block: first batch of add_disk() error handling conversions
This is the first set of driver conversions to use the add_disk() error handling. You can find these changes along with the entire 7th set of driver conversions on my 20210927-for-axboe-add-disk-error-handling branch [0].
Changes on this v4 since the last v3:
- Rebased onto linux-next tag 20210927
- I drop the patches already merged
- Fix the scsi/sd, scsi/sr as noted by Ming Lei
- md: rebased in light of "md: fix a lock order reversal in md_alloc"
- Adds Reviewed / Acked by tags where appropriate. I didn't keep the review by Hannes on the scsi patches as those patches are now slightly fixed
Luis Chamberlain (6):
scsi/sd: add error handling support for add_disk() scsi/sr: add error handling support for add_disk()
md: add error handling support for add_disk()
dm: add add_disk() error handling
loop: add error handling support for add_disk()
nbd: add error handling support for add_disk()
drivers/block/loop.c | 8 +++++++- drivers/block/nbd.c | 6 +++++- drivers/md/dm.c | 4 +++- drivers/md/md.c | 6 +++++- drivers/scsi/sd.c | 8 +++++++- drivers/scsi/sr.c | 7 ++++++- 6 files changed, 33 insertions(+), 6 deletions(-)
Signature · 1 line
2.30.2
PATCH v4 6/6 nbd: add error handling support for add_disk()
We never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
--- drivers/block/nbd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/block/nbd.c +5 -1
@@ -1757,7 +1757,9 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) disk->fops = &nbd_fops; disk->private_data = nbd;sprintf (disk->disk_name,"nbd%d" , index); -add_disk (disk); + err =add_disk (disk); +if (err) + goto out_err_disk;/* * Now publish the device.
@@ -1766,6 +1768,8 @@ static struct nbd_device *nbd_dev_add(int index, unsigned int refs) nbd_total_devices++;return nbd; +out_err_disk: +blk_cleanup_disk (disk); out_free_idr:mutex_lock (&nbd_index_mutex);idr_remove (&nbd_index_idr, index);
Signature · 1 line
2.30.2
PATCH v4 2/6 scsi/sr: add error handling support for add_disk()
In reply to Luis ChamberlainWe never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
Just put the cdrom kref and have the unwinding be done by sr_kref_release().
--- drivers/scsi/sr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/sr.c +6 -1
@@ -727,7 +727,12 @@ static int sr_probe(struct device *dev)dev_set_drvdata (dev, cd); disk->flags |=GENHD_FL_REMOVABLE ;sr_revalidate_disk (cd); -device_add_disk (&sdev->sdev_gendev, disk,NULL ); + + error =device_add_disk (&sdev->sdev_gendev, disk,NULL ); +if (error) { +kref_put (&cd->kref, sr_kref_release); + goto fail; + }sdev_printk (KERN_DEBUG , sdev,"Attached scsi CD-ROM %s\n" , cd->cdi.name);
Signature · 1 line
2.30.2
PATCH v4 3/6 md: add error handling support for add_disk()
In reply to Luis ChamberlainWe never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
We just do the unwinding of what was not done before, and are sure to unlock prior to bailing.
--- drivers/md/md.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/md/md.c +5 -1
@@ -5700,7 +5700,11 @@ static int md_alloc(dev_t dev, char *name) disk->flags |=GENHD_FL_EXT_DEVT ; disk->events |=DISK_EVENT_MEDIA_CHANGE ; mddev->gendisk = disk; -add_disk (disk); + error =add_disk (disk); +if (error) { +blk_cleanup_disk (disk); + goto abort; + } error =kobject_add (&mddev->kobj, &disk_to_dev (disk)->kobj,"%s" ,"md" );if (error) {
Signature · 1 line
2.30.2
PATCH v4 4/6 dm: add add_disk() error handling
In reply to Luis ChamberlainWe never checked for errors on add_disk() as this function returned void. Now that this is fixed, use the shiny new error handling.
There are two calls to dm_setup_md_queue() which can fail then, one on dm_early_create() and we can easily see that the error path there calls dm_destroy in the error path. The other use case is on the ioctl table_load case. If that fails userspace needs to call the DM_DEV_REMOVE_CMD to cleanup the state - similar to any other failure.
--- drivers/md/dm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/md/dm.c +3 -1
@@ -2083,7 +2083,9 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)if (r)return r; -add_disk (md->disk); + r =add_disk (md->disk); +if (r) +return r; r =dm_sysfs_init (md);if (r) {
Signature · 6 lines
2.30.2 -- dm-devel mailing list [email protected] https://listman.redhat.com/mailman/listinfo/dm-devel
Re: [PATCH v4 5/6] loop: add error handling support for add_disk()
In reply to Luis ChamberlainQuoted 3 lines · Luis Chamberlain
We never checked for errors on
add_disk()as this function returned void. Now that this is fixed, use the shiny new error handling.
Applied, thanks.
Signature · 1 line
Jens Axboe
Re: [PATCH v4 6/6] nbd: add error handling support for add_disk()
In reply to Luis ChamberlainQuoted 3 lines · Luis Chamberlain
We never checked for errors on
add_disk()as this function returned void. Now that this is fixed, use the shiny new error handling.
Applied, thanks.
Signature · 1 line
Jens Axboe
Re: [PATCH v4 4/6] dm: add add_disk() error handling
In reply to Luis ChamberlainQuoted 11 lines · Luis Chamberlain
We never checked for errors on
add_disk()as this function returned void. Now that this is fixed, use the shiny new error handling.There are two calls to
dm_setup_md_queue()which can fail then, one ondm_early_create()and we can easily see that the error path there callsdm_destroyin the error path. The other use case is on the ioctltable_loadcase. If that fails userspace needs to call theDM_DEV_REMOVE_CMDto cleanup the state - similar to any other failure.
Quoted 2 lines
Reviewed-by Hannes Reinecke <[email protected]>Signed-off-by Luis Chamberlain <[email protected]>