mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/3] block/swim: Minor fixes
@ 2026-09-29  0:19 Finn Thain
  2026-09-29  0:19 ` [PATCH v2 1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-29  0:19 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Joshua Thompson, Geert Uytterhoeven, Laurent Vivier,
	Stan Johnson, linux-block, linux-kernel, linux-m68k

Two old bugs were reported to me by Stan Johnson while he was testing
my recent patch series, "[PATCH v3] block/swim: Fixes and improvements".
The following patches fix those bugs.

---

Changed since v1:
 - Patch 2/2 was split into two such that each patch alters one driver.
 - 2/3 and 3/3 were revised as described in the commit log entries.
 - Tested-by tags were added.

---

Finn Thain (3):
  swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
  swim: Fix FDEJECT ioctl for exclusive open
  swim3: Fix FDEJECT ioctl for exclusive open

 drivers/block/swim.c  | 10 ++++++----
 drivers/block/swim3.c |  8 +++-----
 2 files changed, 9 insertions(+), 9 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
  2026-09-29  0:19 [PATCH v2 0/3] block/swim: Minor fixes Finn Thain
@ 2026-09-29  0:19 ` Finn Thain
  2026-09-29  0:19 ` [PATCH v2 3/3] swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-29  0:19 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel

Write requests are not supported by the driver and produce IO errors as
shown below. Avoid this by returning -EROFS when opened for writing.

[ 4111.690000] I/O error, dev fd0, sector 2 op 0x1:(WRITE) flags 0x800800 phys_seg 1 prio class 2
[ 4111.700000] Buffer I/O error on dev fd0, logical block 2, lost async page write

Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
 drivers/block/swim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 6f37a01219c2..49c894af7c13 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -639,7 +639,8 @@ static int floppy_open(struct gendisk *disk, blk_mode_t mode)
 	if (mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) {
 		if (disk_check_media_change(disk) && fs->disk_in)
 			fs->ejected = 0;
-		if ((mode & BLK_OPEN_WRITE) && fs->write_protected) {
+		if (mode & BLK_OPEN_WRITE) {
+			/* Write support isn't implemented. */
 			err = -EROFS;
 			goto out;
 		}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] swim: Fix FDEJECT ioctl for exclusive open
  2026-09-29  0:19 [PATCH v2 0/3] block/swim: Minor fixes Finn Thain
  2026-09-29  0:19 ` [PATCH v2 1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
  2026-09-29  0:19 ` [PATCH v2 3/3] swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
@ 2026-09-29  0:19 ` Finn Thain
  2026-09-29  2:30 ` [PATCH v2 0/3] block/swim: Minor fixes Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-29  0:19 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel

The eject command from the util-linux package does not work with the swim
driver: the drive doesn't eject anything and the command fails.
Apparently, ioctl(fd, FDEJECT) returns -EBUSY when fd is opened O_EXCL.
Fix this by checking ref_count for either 1 or -1. Either value means that
the caller is the sole user of the disk.

Fixes: 8852ecd97488 ("m68k: mac - Add SWIM floppy support")
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
Changed since v1:
 - Access ref_count after mutex has been acquired.
---
 drivers/block/swim.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 49c894af7c13..baeb05f3e003 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -700,10 +700,11 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case FDEJECT:
-		if (fs->ref_count != 1)
-			return -EBUSY;
 		mutex_lock(&swim_mutex);
-		err = floppy_eject(fs);
+		if (fs->ref_count == -1 || fs->ref_count == 1)
+			err = floppy_eject(fs);
+		else
+			err = -EBUSY;
 		mutex_unlock(&swim_mutex);
 		return err;
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] swim3: Fix FDEJECT ioctl for exclusive open
  2026-09-29  0:19 [PATCH v2 0/3] block/swim: Minor fixes Finn Thain
  2026-09-29  0:19 ` [PATCH v2 1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
@ 2026-09-29  0:19 ` Finn Thain
  2026-09-29  0:19 ` [PATCH v2 2/3] swim: " Finn Thain
  2026-09-29  2:30 ` [PATCH v2 0/3] block/swim: Minor fixes Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Finn Thain @ 2026-09-29  0:19 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Laurent Vivier, Stan Johnson, Geert Uytterhoeven,
	Joshua Thompson, linux-block, linux-m68k, linux-kernel

The eject command from the util-linux package does not work with the
swim3 driver: the drive doesn't eject anything and the command fails.
Apparently, ioctl(fd, FDEJECT) returns -EBUSY after fd was opened O_EXCL.
Fix this by checking ref_count for either 1 or -1. Either value means that
the caller is the sole user of the disk.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
Changed since v1:
 - Simplify by removing 'err' temporary variable.
---
 drivers/block/swim3.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 01f7aef3fcfb..b55cfe485beb 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -887,7 +887,6 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
 			unsigned int cmd, unsigned long param)
 {
 	struct floppy_state *fs = bdev->bd_disk->private_data;
-	int err;
 		
 	if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -898,10 +897,9 @@ static int floppy_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
 
 	switch (cmd) {
 	case FDEJECT:
-		if (fs->ref_count != 1)
-			return -EBUSY;
-		err = fd_eject(fs);
-		return err;
+		if (fs->ref_count == -1 || fs->ref_count == 1)
+			return fd_eject(fs);
+		return -EBUSY;
 	case FDGETPRM:
 	        if (copy_to_user((void __user *) param, &floppy_type,
 				 sizeof(struct floppy_struct)))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] block/swim: Minor fixes
  2026-09-29  0:19 [PATCH v2 0/3] block/swim: Minor fixes Finn Thain
                   ` (2 preceding siblings ...)
  2026-09-29  0:19 ` [PATCH v2 2/3] swim: " Finn Thain
@ 2026-09-29  2:30 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2026-09-29  2:30 UTC (permalink / raw)
  To: Finn Thain
  Cc: Joshua Thompson, Geert Uytterhoeven, Laurent Vivier,
	Stan Johnson, linux-block, linux-kernel, linux-m68k


On Tue, 29 Sep 2026 10:19:35 +1000, Finn Thain wrote:
> Two old bugs were reported to me by Stan Johnson while he was testing
> my recent patch series, "[PATCH v3] block/swim: Fixes and improvements".
> The following patches fix those bugs.

Applied, thanks!

[1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag
      commit: d8fe777978a12a96cb5d10d6d888720fcba2da2b
[2/3] swim: Fix FDEJECT ioctl for exclusive open
      commit: c76b93df9ae61d8ddebf6aa3bc218252f85e80c6
[3/3] swim3: Fix FDEJECT ioctl for exclusive open
      commit: ce054fbe9a4bf4ffefef0f8e2504ea54da058ed2

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-29  2:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29  0:19 [PATCH v2 0/3] block/swim: Minor fixes Finn Thain
2026-09-29  0:19 ` [PATCH v2 1/3] swim: Return -EROFS when opened with BLK_OPEN_WRITE flag Finn Thain
2026-09-29  0:19 ` [PATCH v2 3/3] swim3: Fix FDEJECT ioctl for exclusive open Finn Thain
2026-09-29  0:19 ` [PATCH v2 2/3] swim: " Finn Thain
2026-09-29  2:30 ` [PATCH v2 0/3] block/swim: Minor fixes Jens Axboe

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®