Skip to content

Commit ff06db1

Browse files
Jiri Kosinaaxboe
authored andcommitted
floppy: fix open(O_ACCMODE) for ioctl-only open
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. Cc: [email protected] # v4.5+ Reported-by: Wim Osterholt <[email protected]> Tested-by: Wim Osterholt <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent c1ece76 commit ff06db1

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

drivers/block/floppy.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3663,11 +3663,6 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
36633663

36643664
opened_bdev[drive] = bdev;
36653665

3666-
if (!(mode & (FMODE_READ|FMODE_WRITE))) {
3667-
res = -EINVAL;
3668-
goto out;
3669-
}
3670-
36713666
res = -ENXIO;
36723667

36733668
if (!floppy_track_buffer) {
@@ -3711,13 +3706,15 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
37113706
if (UFDCS->rawcmd == 1)
37123707
UFDCS->rawcmd = 2;
37133708

3714-
UDRS->last_checked = 0;
3715-
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
3716-
check_disk_change(bdev);
3717-
if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
3718-
goto out;
3719-
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
3720-
goto out;
3709+
if (mode & (FMODE_READ|FMODE_WRITE)) {
3710+
UDRS->last_checked = 0;
3711+
clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
3712+
check_disk_change(bdev);
3713+
if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
3714+
goto out;
3715+
if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
3716+
goto out;
3717+
}
37213718

37223719
res = -EROFS;
37233720

0 commit comments

Comments
 (0)