Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1464415

Re: [PATCH 06/15] genhd: Add return code to device_add_disk

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Cornelia Huck <cornelia.huck@de.ibm.com>
Newsgroups linux.kernel
Subject Re: [PATCH 06/15] genhd: Add return code to device_add_disk
Date Wed, 17 Aug 2016 10:50:01 +0200
Message-ID <s74HT-71z-9@gated-at.bofh.it> (permalink)
References <s73iN-6e4-1@gated-at.bofh.it> <s73st-6je-1@gated-at.bofh.it>
X-Original-To Fam Zheng <famz@redhat.com>
X-Ibm-Helo d06dlp01.portsmouth.uk.ibm.com
X-Ibm-Mailfrom cornelia.huck@de.ibm.com
X-Ibm-Rcptto linux-block@vger.kernel.org;linux-kernel@vger.kernel.org
Organization IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
X-Mailer Claws Mail 3.11.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu)
MIME-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Tm-As-Mml disable
X-Content-Scanned Fidelis XPS MAILER
X-Cbid 16081708-0012-0000-0000-00000446726D
X-Ibm-Av-Detection SAVI=unused REMOTE=unused XFE=unused
X-Cbparentid 16081708-0013-0000-0000-0000150DB973
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:,, definitions=2016-08-17_05:,, signatures=0
X-Proofpoint-Spam-Details rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608170107
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 80
X-Original-Cc linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org, Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, Michael Ellerman <mpe@ellerman.id.au>, virtualization@lists.linux-foundation.org, linux-nvme@lists.infradead.org, "Ed L. Cashin" <ed.cashin@acm.org>, Keith Busch <keith.busch@intel.com>, Minchan Kim <minchan@kernel.org>, Paul Mackerras <paulus@samba.org>, Benjamin Herrenschmidt <benh@kernel.crashing.org>, linux-mtd@lists.infradead.org, Brian Norris <computersforpeace@gmail.com>, linuxppc-dev@lists.ozlabs.org, David Woodhouse <dwmw2@infradead.org>, Nitin Gupta <ngupta@vflare.org>
X-Original-Date Wed, 17 Aug 2016 10:49:14 +0200
X-Original-Message-ID <20160817104914.37087cb3.cornelia.huck@de.ibm.com>
X-Original-References <1471418115-3654-1-git-send-email-famz@redhat.com> <1471418115-3654-7-git-send-email-famz@redhat.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1464415

Show key headers only | View raw


On Wed, 17 Aug 2016 15:15:06 +0800
Fam Zheng <famz@redhat.com> wrote:

> @@ -613,10 +614,8 @@ void device_add_disk(struct device *parent, struct gendisk *disk)
>  	disk->flags |= GENHD_FL_UP;
> 
>  	retval = blk_alloc_devt(&disk->part0, &devt);
> -	if (retval) {
> -		WARN_ON(1);
> -		return;
> -	}
> +	if (retval)
> +		goto fail;
>  	disk_to_dev(disk)->devt = devt;
> 
>  	/* ->major and ->first_minor aren't supposed to be
> @@ -625,16 +624,26 @@ void device_add_disk(struct device *parent, struct gendisk *disk)
>  	disk->major = MAJOR(devt);
>  	disk->first_minor = MINOR(devt);
> 
> -	disk_alloc_events(disk);
> +	retval = disk_alloc_events(disk);
> +	if (retval)
> +		goto fail;
> 
>  	/* Register BDI before referencing it from bdev */
>  	bdi = &disk->queue->backing_dev_info;
> -	bdi_register_owner(bdi, disk_to_dev(disk));
> +	retval = bdi_register_owner(bdi, disk_to_dev(disk));
> +	if (retval)
> +		goto fail;
> 
> -	blk_register_region(disk_devt(disk), disk->minors, NULL,
> -			    exact_match, exact_lock, disk);
> -	register_disk(parent, disk);
> -	blk_register_queue(disk);
> +	retval = blk_register_region(disk_devt(disk), disk->minors, NULL,
> +				     exact_match, exact_lock, disk);
> +	if (retval)
> +		goto fail;
> +	retval = register_disk(parent, disk);
> +	if (retval)
> +		goto fail;
> +	retval = blk_register_queue(disk);
> +	if (retval)
> +		goto fail;
> 
>  	/*
>  	 * Take an extra ref on queue which will be put on disk_release()
> @@ -644,10 +653,20 @@ void device_add_disk(struct device *parent, struct gendisk *disk)
> 
>  	retval = sysfs_create_link(&disk_to_dev(disk)->kobj, &bdi->dev->kobj,
>  				   "bdi");
> +	if (retval)
> +		goto fail;
> +
> +	retval = disk_add_events(disk);
> +	if (retval)
> +		goto fail;
> +
> +	retval = blk_integrity_add(disk);
> +	if (retval)
> +		goto fail;
> +	return 0;
> +fail:
>  	WARN_ON(retval);
> -
> -	disk_add_events(disk);
> -	blk_integrity_add(disk);
> +	return retval;
>  }

Noticed this when trying to figure out whether the error handling in
virtio_blk was correct:

Shouldn't you try to cleanup/rewind so that any structures are in a
sane state after failure? The caller doesn't know where device_add_disk
failed, and calling del_gendisk unconditionally like virtio_blk does is
probably not the right thing to do (at the very least, I don't think
unregistering a device that has not been registered is likely to work).

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/15] Fix issue with KOBJ_ADD uevent versus disk attributes Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 04/15] block: Return error from blk_integrity_add Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 03/15] genhd: Return error from blk_register_region Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 12/15] mtip: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 02/15] genhd: Return error from register_disk() Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 01/15] disk: Drop add_disk in favor of device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 14/15] axonram: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 13/15] aoeblk: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
  [PATCH 15/15] block: Add FIXME comment to handle device_add_disk error Fam Zheng <famz@redhat.com> - 2016-08-17 09:20 +0200
    Re: [PATCH 15/15] block: Add FIXME comment to handle device_add_disk  error Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-08-18 04:40 +0200
  [PATCH 10/15] mtd: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200
  [PATCH 08/15] nvme: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200
  [PATCH 06/15] genhd: Add return code to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200
    Re: [PATCH 06/15] genhd: Add return code to device_add_disk Cornelia Huck <cornelia.huck@de.ibm.com> - 2016-08-17 10:50 +0200
      Re: [PATCH 06/15] genhd: Add return code to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 11:00 +0200
        Re: [PATCH 06/15] genhd: Add return code to device_add_disk Cornelia Huck <cornelia.huck@de.ibm.com> - 2016-08-17 11:10 +0200
          Re: [PATCH 06/15] genhd: Add return code to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 11:30 +0200
            Re: [PATCH 06/15] genhd: Add return code to device_add_disk Ed Cashin <ed.cashin@acm.org> - 2016-08-18 03:40 +0200
  [PATCH 11/15] zram: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200
    Re: [PATCH 11/15] zram: Pass attribute group to device_add_disk Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-08-18 04:00 +0200
      Re: [PATCH 11/15] zram: Pass attribute group to device_add_disk Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-08-18 04:10 +0200
  [PATCH 09/15] virtio-blk: Pass attribute group to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200
  [PATCH 05/15] genhd: Return error from disk_{add,alloc}_events Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200
  [PATCH 07/15] genhd: Add attribute group parameter to device_add_disk Fam Zheng <famz@redhat.com> - 2016-08-17 09:30 +0200

csiph-web