mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Denis Efremov (Oracle)" <efremov@linux.com>
To: linux-block@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Denis Efremov (Oracle)" <efremov@linux.com>
Subject: [PATCH] floppy: remove usage_count
Date: Fri,  9 Oct 2026 02:40:33 +0400	[thread overview]
Message-ID: <20261008224033.3134735-1-efremov@linux.com> (raw)

usage_count used to count openers and FDC users. Since commit
3e541a4ae534 ("[PATCH] lockdep: floppy.c irq release fix") the only
caller of floppy_grab_irq_and_dma() is do_floppy_init(), which runs it
once for all controllers and drives before any disk is added.
floppy_release_irq_and_dma() runs only after that grab has succeeded:
on init failure after del_gendisk(), or on module exit. The count is 1
for as long as a floppy disk exists, so it carries no information.

The usage_count == 0 checks in lock_fdc(), floppy_queue_rq() and
floppy_revalidate() never fire. The one in floppy_queue_rq() would oops
if it did, since it dereferences current_req, which is NULL when nothing
is in flight. The nested-grab early return in floppy_grab_irq_and_dma(),
the atomic_dec_and_test() in floppy_release_irq_and_dma() and the
usage_count tests before the release calls always go the same way.

Remove the counter and the checks.

Signed-off-by: Denis Efremov (Oracle) <efremov@linux.com>
---
 drivers/block/floppy.c | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index f04397b8e381..a08ed982f013 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -566,8 +566,6 @@ static int floppy_revalidate(struct gendisk *disk);
 #define NEED_1_RECAL	-2
 #define NEED_2_RECAL	-3
 
-static atomic_t usage_count = ATOMIC_INIT(0);
-
 /* buffer related variables */
 static int buffer_track = -1;
 static int buffer_drive = -1;
@@ -883,10 +881,6 @@ static void set_fdc(int drive)
  */
 static int lock_fdc(int drive)
 {
-	if (WARN(atomic_read(&usage_count) == 0,
-		 "Trying to lock fdc while usage count=0\n"))
-		return -1;
-
 	if (wait_event_interruptible(fdc_wait, !test_and_set_bit(0, &fdc_busy)))
 		return -EINTR;
 
@@ -2854,12 +2848,6 @@ static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx,
 		 "VFS: %s called on non-open device\n", __func__))
 		return BLK_STS_IOERR;
 
-	if (WARN(atomic_read(&usage_count) == 0,
-		 "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n",
-		 current_req, (long)blk_rq_pos(current_req),
-		 (__force unsigned long long) current_req->cmd_flags))
-		return BLK_STS_IOERR;
-
 	if (test_and_set_bit(0, &fdc_busy)) {
 		/* fdc busy, this new request will be treated when the
 		   current one is done */
@@ -4178,10 +4166,6 @@ static int floppy_revalidate(struct gendisk *disk)
 	    test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
 	    test_bit(drive, &fake_change) ||
 	    drive_no_geom(drive)) {
-		if (WARN(atomic_read(&usage_count) == 0,
-			 "VFS: revalidate called on non-open device.\n"))
-			return -EFAULT;
-
 		res = lock_fdc(drive);
 		if (res)
 			return res;
@@ -4744,8 +4728,7 @@ static int __init do_floppy_init(void)
 		}
 	}
 out_release_dma:
-	if (atomic_read(&usage_count))
-		floppy_release_irq_and_dma();
+	floppy_release_irq_and_dma();
 out_unreg_driver:
 	platform_driver_unregister(&floppy_driver);
 out_unreg_blkdev:
@@ -4825,9 +4808,6 @@ static int floppy_grab_irq_and_dma(void)
 {
 	int fdc;
 
-	if (atomic_inc_return(&usage_count) > 1)
-		return 0;
-
 	/*
 	 * We might have scheduled a free_irq(), wait it to
 	 * drain first:
@@ -4837,7 +4817,6 @@ static int floppy_grab_irq_and_dma(void)
 	if (fd_request_irq()) {
 		DPRINT("Unable to grab IRQ%d for the floppy driver\n",
 		       FLOPPY_IRQ);
-		atomic_dec(&usage_count);
 		return -1;
 	}
 	if (fd_request_dma()) {
@@ -4847,7 +4826,6 @@ static int floppy_grab_irq_and_dma(void)
 			use_virtual_dma = can_use_virtual_dma = 1;
 		if (!(can_use_virtual_dma & 1)) {
 			fd_free_irq();
-			atomic_dec(&usage_count);
 			return -1;
 		}
 	}
@@ -4883,7 +4861,6 @@ static int floppy_grab_irq_and_dma(void)
 	while (--fdc >= 0)
 		floppy_release_regions(fdc);
 	current_fdc = 0;
-	atomic_dec(&usage_count);
 	return -1;
 }
 
@@ -4896,9 +4873,6 @@ static void floppy_release_irq_and_dma(void)
 	long tmpsize;
 	unsigned long tmpaddr;
 
-	if (!atomic_dec_and_test(&usage_count))
-		return;
-
 	if (irqdma_allocated) {
 		fd_disable_dma();
 		fd_free_dma();
@@ -4994,8 +4968,7 @@ static void __exit floppy_module_exit(void)
 	cancel_delayed_work_sync(&fd_timeout);
 	cancel_delayed_work_sync(&fd_timer);
 
-	if (atomic_read(&usage_count))
-		floppy_release_irq_and_dma();
+	floppy_release_irq_and_dma();
 
 	/* eject disk, if any */
 	fd_eject(0);

base-commit: 6c377d19d4a5116d9bec5203aa3c6c11523e7898
-- 
2.56.0


                 reply	other threads:[~2026-10-08 22:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261008224033.3134735-1-efremov@linux.com \
    --to=efremov@linux.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®