From: Fam Zheng <famz@redhat.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
Subject: Re: [PATCH 06/15] genhd: Add return code to device_add_disk
Date: Wed, 17 Aug 2016 17:14:22 +0800 [thread overview]
Message-ID: <20160817091422.GE19326@al.usersys.redhat.com> (raw)
In-Reply-To: <20160817110645.45370f57.cornelia.huck@de.ibm.com>
On Wed, 08/17 11:06, Cornelia Huck wrote:
> On Wed, 17 Aug 2016 16:48:23 +0800
> Fam Zheng <famz@redhat.com> wrote:
>
> > On Wed, 08/17 10:49, Cornelia Huck wrote:
> > > 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).
> > >
> >
> > Yes, I think all callers need to be reviewed before device_add_disk do the
> > clean up on error. For this patchset I wanted to keep the change small.
>
> But do the callers even have a chance to do this correctly right now?
> They will either clean up too much, or too little. ('Too little' is
> probably the more common case, given that you just added error
> propagation...)
Right, which is pre-exising.
>
> Can you make del_gendisk handle devices partially setup via
> device_add_disk in all cases? Then you could mandate pairing
> device_add_disk with del_gendisk in all cases, error or not, and you
> should have a better chance on avoiding introducing new errors.
>
Of course, the plan is to write patches on top. I'm not cleaning up anything
here because I'm concerned callers may double free (and I didn't look hard into
that).
Fam
next prev parent reply other threads:[~2016-08-17 9:21 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-17 7:15 [PATCH 00/15] Fix issue with KOBJ_ADD uevent versus disk attributes Fam Zheng
2016-08-17 7:15 ` [PATCH 01/15] disk: Drop add_disk in favor of device_add_disk Fam Zheng
2016-08-17 7:15 ` [PATCH 02/15] genhd: Return error from register_disk() Fam Zheng
2016-08-17 7:15 ` [PATCH 03/15] genhd: Return error from blk_register_region Fam Zheng
2016-08-17 7:15 ` [PATCH 04/15] block: Return error from blk_integrity_add Fam Zheng
2016-08-17 7:15 ` [PATCH 05/15] genhd: Return error from disk_{add,alloc}_events Fam Zheng
2016-08-17 7:15 ` [PATCH 06/15] genhd: Add return code to device_add_disk Fam Zheng
2016-08-17 8:49 ` Cornelia Huck
2016-08-17 8:48 ` Fam Zheng
2016-08-17 9:06 ` Cornelia Huck
2016-08-17 9:14 ` Fam Zheng [this message]
2016-08-18 1:09 ` Ed Cashin
2016-08-17 7:15 ` [PATCH 07/15] genhd: Add attribute group parameter " Fam Zheng
2016-08-17 7:15 ` [PATCH 08/15] nvme: Pass attribute group " Fam Zheng
2016-08-17 8:13 ` kbuild test robot
2016-08-17 7:15 ` [PATCH 09/15] virtio-blk: " Fam Zheng
2016-09-04 4:18 ` Michael S. Tsirkin
2016-08-17 7:15 ` [PATCH 10/15] mtd: " Fam Zheng
2016-08-17 7:15 ` [PATCH 11/15] zram: " Fam Zheng
2016-08-18 1:59 ` Sergey Senozhatsky
2016-08-18 2:06 ` Sergey Senozhatsky
2016-08-17 7:15 ` [PATCH 12/15] mtip: " Fam Zheng
2016-08-17 7:15 ` [PATCH 13/15] aoeblk: " Fam Zheng
2016-08-17 7:15 ` [PATCH 14/15] axonram: " Fam Zheng
2016-08-17 7:15 ` [PATCH 15/15] block: Add FIXME comment to handle device_add_disk error Fam Zheng
2016-08-18 2:36 ` Sergey Senozhatsky
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=20160817091422.GE19326@al.usersys.redhat.com \
--to=famz@redhat.com \
--cc=axboe@kernel.dk \
--cc=benh@kernel.crashing.org \
--cc=computersforpeace@gmail.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dwmw2@infradead.org \
--cc=ed.cashin@acm.org \
--cc=keith.busch@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=minchan@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=mst@redhat.com \
--cc=ngupta@vflare.org \
--cc=paulus@samba.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=virtualization@lists.linux-foundation.org \
/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 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).