From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:36:09
This is the 6th of 7 batch of driver conversions over to use the
new add_disk() error handling. This series addresses the wonderful
and extremely exciting world of floppy drivers. You can find the full
set of my patches on my 20210901-for-axboe-add-disk-error-handling
branch [0]. This is based on axboe/master.
[0] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git/log/?h=20210901-for-axboe-add-disk-error-handling
Luis Chamberlain (14):
block/swim3: add error handling support for add_disk()
floppy: fix add_disk() assumption on exit due to new developments
floppy: use blk_cleanup_disk()
floppy: fix calling platform_device_unregister() on invalid drives
floppy: add error handling support for add_disk()
amiflop: add error handling support for add_disk()
swim: simplify using blk_cleanup_disk() on swim_remove()
swim: add helper for disk cleanup
swim: add a floppy registration bool which triggers del_gendisk()
swim: add error handling support for add_disk()
block/ataflop: use the blk_cleanup_disk() helper
block/ataflop: add registration bool before calling del_gendisk()
block/ataflop: provide a helper for cleanup up an atari disk
block/ataflop add error handling support for add_disk()
drivers/block/amiflop.c | 7 ++++--
drivers/block/ataflop.c | 47 +++++++++++++++++++++++++----------------
drivers/block/floppy.c | 34 +++++++++++------------------
drivers/block/swim.c | 35 ++++++++++++++++++------------
drivers/block/swim3.c | 4 +++-
5 files changed, 71 insertions(+), 56 deletions(-)
--
2.30.2
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:42
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 caller for fd_alloc_disk() deals with
the rest of the cleanup like the tag.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/amiflop.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
@@ -1798,8 +1799,10 @@ static int fd_alloc_disk(int drive, int system)set_capacity(disk,880*2);unit[drive].gendisk[system]=disk;-add_disk(disk);-return0;+err=add_disk(disk);+if(err)+blk_cleanup_disk(disk);+returnerr;}staticintfd_alloc_drive(intdrive)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:45
After the patch titled "floppy: use blk_mq_alloc_disk and
blk_cleanup_disk" the floppy driver was modified to allocate
the blk_mq_alloc_disk() which allocates the disk with the
queue. This is further clarified later with the patch titled
"block: remove alloc_disk and alloc_disk_node". This clarifies
that:
Most drivers should use and have been converted to use
blk_alloc_disk and blk_mq_alloc_disk. Only the scsi
ULPs and dasd still allocate a disk separately from the
request_queue so don't bother with convenience macros for
something that should not see significant new users and
remove these wrappers.
And then we have the patch titled, "block: hold a request_queue
reference for the lifetime of struct gendisk" which ensures
that a queue is *always* present for sure during the entire
lifetime of a disk.
In the floppy driver's case then the disk always comes with the
queue. So even if even if the queue was cleaned up on exit, putting
the disk *is* still required, and likewise, blk_cleanup_queue() on
a null queue should not happen now as disk->queue is valid from
disk allocation time on.
Automatic backport code scrapers should hopefully not cherry pick
this patch as a stable fix candidate without full due dilligence to
ensure all the work done on the block layer to make this happen is
merged first.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/floppy.c | 13 -------------
1 file changed, 13 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:46
The ataflop assumes del_gendisk() is safe to call, this is only
true because add_disk() does not return a failure, but that will
change soon. And so, before we get to adding error handling for
that case, let's make sure we keep track of which disks actually
get registered. Then we use this to only call del_gendisk for them.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/ataflop.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:48
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/floppy.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:50
We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.
Since we have a caller to do our unwinding for the disk,
and this is already dealt with safely we can re-use our
existing error path goto label which already deals with
the cleanup.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/swim.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:51
platform_device_unregister() should only be called when
a respective platform_device_register() is called. However
the floppy driver currently allows failures when registring
a drive and a bail out could easily cause an invalid call
to platform_device_unregister() where it was not intended.
Fix this by adding a bool to keep track of when the platform
device was registered for a drive.
This does not fix any known panic / bug. This issue was found
through code inspection while preparing the driver to use the
up and coming support for device_add_disk() error handling.
From what I can tell from code inspection, chances of this
ever happening should be insanely small, perhaps OOM.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/floppy.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:53
Instead of calling del_gendisk() on exit alone, let's add
a registration bool to the floppy disk state, this way this can
be done on the shared caller, swim_cleanup_floppy_disk().
This will be more useful in subsequent patches. Right now, this
just shuffles functionality out to a helper in a safe way.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/swim.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:54
Disk cleanup can be shared between exit and bringup. Use a
helper to do the work required. The only functional change at
this point is we're being overly paraoid on exit to check for
a null disk as well now, and this should be safe.
We'll later expand on this, this change just makes subsequent
changes easier to read.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/swim.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:35:58
Use the blk_cleanup_queue() followed by put_disk() can be
replaced with blk_cleanup_disk(). No need for two separate
loops.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/floppy.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:36:01
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/swim3.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:36:04
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/ataflop.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:36:06
We can simplify swim_remove() by using one call instead of two,
just as other drivers do. Use that pattern.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/swim.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:36:12
Use the helper to replace two lines with one.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/ataflop.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2021-09-04 01:36:14
Instead of using two separate code paths for cleaning up an atari disk,
use one. We take the more careful approach to check for *all* disk
types, as is done on exit. The init path didn't have that check as
the alternative disk types are only probed for later, they are not
initialized by default.
Yes, there is a shared tag for all disks.
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
drivers/block/ataflop.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)