Skip to content

Commit ce5697e

Browse files
Jiri Kosinagregkh
authored andcommitted
floppy: reintroduce O_NDELAY fix
commit 8a0c014 upstream. This issue was originally fixed in 09954ba ("floppy: refactor open() flags handling"). The fix as a side-effect, however, introduce issue for open(O_ACCMODE) that is being used for ioctl-only open. I wrote a fix for that, but instead of it being merged, full revert of 09954ba was performed, re-introducing the O_NDELAY / O_NONBLOCK issue, and it strikes again. This is a forward-port of the original fix to current codebase; the original submission had the changelog below: ==== Commit 09954ba ("floppy: refactor open() flags handling"), as a side-effect, causes open(/dev/fdX, O_ACCMODE) to fail. It turns out that this is being used setfdprm userspace for ioctl-only open(). Reintroduce back the original behavior wrt !(FMODE_READ|FMODE_WRITE) modes, while still keeping the original O_NDELAY bug fixed. Link: https://lore.kernel.org/r/nycvar.YFH.7.76.2101221209060.5622@cbobk.fhfr.pm Cc: stable@vger.kernel.org Reported-by: Wim Osterholt <wim@djo.tudelft.nl> Tested-by: Wim Osterholt <wim@djo.tudelft.nl> Reported-and-tested-by: Kurt Garloff <kurt@garloff.de> Fixes: 09954ba ("floppy: refactor open() flags handling") Fixes: f2791e7 ("Revert "floppy: refactor open() flags handling"") Signed-off-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Denis Efremov <efremov@linux.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9c9f49c commit ce5697e

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

‎drivers/block/floppy.c‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,23 +4120,23 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
41204120
if (fdc_state[FDC(drive)].rawcmd == 1)
41214121
fdc_state[FDC(drive)].rawcmd = 2;
41224122

4123-
if (!(mode & FMODE_NDELAY)) {
4124-
if (mode & (FMODE_READ|FMODE_WRITE)) {
4125-
drive_state[drive].last_checked = 0;
4126-
clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
4127-
&drive_state[drive].flags);
4128-
if (bdev_check_media_change(bdev))
4129-
floppy_revalidate(bdev->bd_disk);
4130-
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
4131-
goto out;
4132-
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
4133-
goto out;
4134-
}
4135-
res = -EROFS;
4136-
if ((mode & FMODE_WRITE) &&
4137-
!test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
4123+
if (mode & (FMODE_READ|FMODE_WRITE)) {
4124+
drive_state[drive].last_checked = 0;
4125+
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
4126+
if (bdev_check_media_change(bdev))
4127+
floppy_revalidate(bdev->bd_disk);
4128+
if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
4129+
goto out;
4130+
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
41384131
goto out;
41394132
}
4133+
4134+
res = -EROFS;
4135+
4136+
if ((mode & FMODE_WRITE) &&
4137+
!test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
4138+
goto out;
4139+
41404140
mutex_unlock(&open_lock);
41414141
mutex_unlock(&floppy_mutex);
41424142
return 0;

0 commit comments

Comments
 (0)