linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] block: simple *add_disk*() driver conversions
@ 2021-07-15 19:51 Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 1/3] loop: add error handling support for add_disk() Luis Chamberlain
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luis Chamberlain @ 2021-07-15 19:51 UTC (permalink / raw)
  To: axboe
  Cc: hare, bvanassche, ming.lei, hch, jack, osandov, linux-block,
	linux-kernel, Luis Chamberlain

As requested by Christoph, I'm going to add a few demo driver
conversions, to show how drivers can manage *add_disk*() error
handling.

I've converted all drivers at this point, but I think it makes sense to
split these conversion up into groups. This is the first group, which
demos trivial changes. This group is larger than this, but this series
with 3 driver examples should suffice to start review on that group type.

If this seems fine and the block changes get merged I can extend this
group later to include all trivial driver conversions. But patch review
on these would help to get started.

Luis Chamberlain (3):
  loop: add error handling support for add_disk()
  null_blk: add error handling support for add_disk()
  nbd: add error handling support for add_disk()

 drivers/block/loop.c          | 9 ++++++++-
 drivers/block/nbd.c           | 6 +++++-
 drivers/block/null_blk/main.c | 3 +--
 3 files changed, 14 insertions(+), 4 deletions(-)

-- 
2.27.0


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

* [PATCH 1/3] loop: add error handling support for add_disk()
  2021-07-15 19:51 [PATCH 0/3] block: simple *add_disk*() driver conversions Luis Chamberlain
@ 2021-07-15 19:51 ` Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 2/3] null_blk: " Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 3/3] nbd: " Luis Chamberlain
  2 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2021-07-15 19:51 UTC (permalink / raw)
  To: axboe
  Cc: hare, bvanassche, ming.lei, hch, jack, osandov, linux-block,
	linux-kernel, 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.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/block/loop.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index f37b9e3d833c..efbd8e29aca7 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2326,10 +2326,17 @@ static int loop_add(int i)
 	disk->private_data	= lo;
 	disk->queue		= lo->lo_queue;
 	sprintf(disk->disk_name, "loop%d", i);
-	add_disk(disk);
+
+	err = add_disk(disk);
+	if (err)
+		goto out_cleanup_disk;
+
 	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:
-- 
2.27.0


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

* [PATCH 2/3] null_blk: add error handling support for add_disk()
  2021-07-15 19:51 [PATCH 0/3] block: simple *add_disk*() driver conversions Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 1/3] loop: add error handling support for add_disk() Luis Chamberlain
@ 2021-07-15 19:51 ` Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 3/3] nbd: " Luis Chamberlain
  2 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2021-07-15 19:51 UTC (permalink / raw)
  To: axboe
  Cc: hare, bvanassche, ming.lei, hch, jack, osandov, linux-block,
	linux-kernel, 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. The actual cleanup in case of error is
already handled by the caller of null_gendisk_register().

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/block/null_blk/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index d734e9ee1546..2a8f3eee7159 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1721,8 +1721,7 @@ static int null_gendisk_register(struct nullb *nullb)
 			return ret;
 	}
 
-	add_disk(disk);
-	return 0;
+	return add_disk(disk);
 }
 
 static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set)
-- 
2.27.0


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

* [PATCH 3/3] nbd: add error handling support for add_disk()
  2021-07-15 19:51 [PATCH 0/3] block: simple *add_disk*() driver conversions Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 1/3] loop: add error handling support for add_disk() Luis Chamberlain
  2021-07-15 19:51 ` [PATCH 2/3] null_blk: " Luis Chamberlain
@ 2021-07-15 19:51 ` Luis Chamberlain
  2 siblings, 0 replies; 4+ messages in thread
From: Luis Chamberlain @ 2021-07-15 19:51 UTC (permalink / raw)
  To: axboe
  Cc: hare, bvanassche, ming.lei, hch, jack, osandov, linux-block,
	linux-kernel, 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.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 drivers/block/nbd.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b7d663736d35..0ecc1e4e16fd 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1730,10 +1730,14 @@ static int nbd_dev_add(int index)
 	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;
 	nbd_total_devices++;
 	return index;
 
+out_err_disk:
+	blk_cleanup_disk(disk);
 out_free_idr:
 	idr_remove(&nbd_index_idr, index);
 out_free_tags:
-- 
2.27.0


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

end of thread, other threads:[~2021-07-15 19:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-15 19:51 [PATCH 0/3] block: simple *add_disk*() driver conversions Luis Chamberlain
2021-07-15 19:51 ` [PATCH 1/3] loop: add error handling support for add_disk() Luis Chamberlain
2021-07-15 19:51 ` [PATCH 2/3] null_blk: " Luis Chamberlain
2021-07-15 19:51 ` [PATCH 3/3] nbd: " Luis Chamberlain

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