Re: [PATCH v4 2/4] ataflop: address add_disk() error handling on probe

From: Christoph Hellwig
Date: Wed Nov 03 2021 - 14:20:31 EST


On Wed, Nov 03, 2021 at 11:12:56AM -0700, Luis Chamberlain wrote:
> We need to cleanup resources on the probe() callback registered
> with __register_blkdev(), now that add_disk() error handling is
> supported. Address this.
>
> Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>
> ---
> drivers/block/ataflop.c | 16 +++++++++++++---
> 1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
> index 170dd193cef6..e981b351f37e 100644
> --- a/drivers/block/ataflop.c
> +++ b/drivers/block/ataflop.c
> @@ -2012,6 +2012,7 @@ static void ataflop_probe(dev_t dev)
> {
> int drive = MINOR(dev) & 3;
> int type = MINOR(dev) >> 2;
> + int err = 0;
>
> if (type)
> type--;
> @@ -2019,11 +2020,20 @@ static void ataflop_probe(dev_t dev)
> if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
> return;
> if (!unit[drive].disk[type]) {
> + err = ataflop_alloc_disk(drive, type);
> + if (err == 0) {
> + err = add_disk(unit[drive].disk[type]);
> + if (err)
> + goto err_out;
> + else
> + unit[drive].registered[type] = true;

This looks weird. Why not:

if (unit[drive].disk[type])
return;

if (ataflop_alloc_disk(drive, type))
return;
if (add_disk(unit[drive].disk[type]))
goto cleanup_disk;
unit[drive].registered[type] = true;
return;

cleanup_disk:
blk_cleanup_disk(unit[drive].disk[type]);
unit[drive].disk[type] = NULL;