All of lore.kernel.org
 help / color / mirror / Atom feed
From: Finn Thain <fthain@linux-m68k.org>
To: Luis Chamberlain <mcgrof@kernel.org>
Cc: axboe@kernel.dk, hch@lst.de, efremov@linux.com, song@kernel.org,
	jejb@linux.ibm.com, martin.petersen@oracle.com,
	viro@zeniv.linux.org.uk, hare@suse.de, jack@suse.cz,
	ming.lei@redhat.com, tj@kernel.org, linux-raid@vger.kernel.org,
	linux-scsi@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Subject: Re: [PATCH v2 1/2] block: make __register_blkdev() return an error
Date: Tue, 28 Sep 2021 10:57:18 +1000 (AEST)	[thread overview]
Message-ID: <2ac2e05f-327a-b66f-aaa0-276db2e46730@linux-m68k.org> (raw)
In-Reply-To: <20210927220332.1074647-2-mcgrof@kernel.org>

On Mon, 27 Sep 2021, Luis Chamberlain wrote:

> diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
> index 5dc9b3d32415..be0627345b21 100644
> --- a/drivers/block/ataflop.c
> +++ b/drivers/block/ataflop.c
> @@ -1989,24 +1989,34 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
>  
>  static DEFINE_MUTEX(ataflop_probe_lock);
>  
> -static void ataflop_probe(dev_t dev)
> +static int ataflop_probe(dev_t dev)
>  {
>  	int drive = MINOR(dev) & 3;
>  	int type  = MINOR(dev) >> 2;
> +	int err = 0;
>  
>  	if (type)
>  		type--;
>  
> -	if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
> -		return;
> +	if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS) {
> +		err = -EINVAL;
> +		goto out;
> +	}
> +
>  	mutex_lock(&ataflop_probe_lock);
>  	if (!unit[drive].disk[type]) {
> -		if (ataflop_alloc_disk(drive, type) == 0) {
> -			add_disk(unit[drive].disk[type]);
> +		err = ataflop_alloc_disk(drive, type);
> +		if (err == 0) {
> +			err = add_disk(unit[drive].disk[type]);
> +			if (err)
> +				blk_cleanup_disk(unit[drive].disk[type]);
>  			unit[drive].registered[type] = true;
>  		}
>  	}
>  	mutex_unlock(&ataflop_probe_lock);
> +
> +out:
> +	return err;
>  }
>  
>  static void atari_cleanup_floppy_disk(struct atari_floppy_struct *fs)

I think the change to ataflop_probe() would be more clear without adding 
an 'out' label, like your change to floppy.c:

> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> index 0434f28742e7..95a1c8ef62f7 100644
> --- a/drivers/block/floppy.c
> +++ b/drivers/block/floppy.c
> @@ -4517,21 +4517,27 @@ static int floppy_alloc_disk(unsigned int drive, unsigned int type)
>  
>  static DEFINE_MUTEX(floppy_probe_lock);
>  
> -static void floppy_probe(dev_t dev)
> +static int floppy_probe(dev_t dev)
>  {
>  	unsigned int drive = (MINOR(dev) & 3) | ((MINOR(dev) & 0x80) >> 5);
>  	unsigned int type = (MINOR(dev) >> 2) & 0x1f;
> +	int err = 0;
>  
>  	if (drive >= N_DRIVE || !floppy_available(drive) ||
>  	    type >= ARRAY_SIZE(floppy_type))
> -		return;
> +		return -EINVAL;
>  
>  	mutex_lock(&floppy_probe_lock);
>  	if (!disks[drive][type]) {
> -		if (floppy_alloc_disk(drive, type) == 0)
> -			add_disk(disks[drive][type]);
> +		if (floppy_alloc_disk(drive, type) == 0) {
> +			err = add_disk(disks[drive][type]);
> +			if (err)
> +				blk_cleanup_disk(disks[drive][type]);
> +		}
>  	}
>  	mutex_unlock(&floppy_probe_lock);
> +
> +	return err;
>  }
>  
>  static int __init do_floppy_init(void)

In floppy_probe(), I think you should return the potential error result 
from floppy_alloc_disk(), like you did in ataflop.c.

  parent reply	other threads:[~2021-09-28  0:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 22:03 [PATCH v2 0/2] block: 7th -- last batch of add_disk() error handling conversions Luis Chamberlain
2021-09-27 22:03 ` [PATCH v2 1/2] block: make __register_blkdev() return an error Luis Chamberlain
2021-09-28  0:19   ` Tetsuo Handa
2021-10-15 18:34     ` Luis Chamberlain
2021-09-28  0:57   ` Finn Thain [this message]
2021-10-15 18:43     ` Luis Chamberlain
2021-09-27 22:03 ` [PATCH v2 2/2] block: add __must_check for *add_disk*() callers Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ac2e05f-327a-b66f-aaa0-276db2e46730@linux-m68k.org \
    --to=fthain@linux-m68k.org \
    --cc=axboe@kernel.dk \
    --cc=efremov@linux.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=jejb@linux.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mcgrof@kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.