Skip to content

Commit ac03334

Browse files
Purva Yeshikawasaki
authored andcommitted
block: floppy: fix uninitialized use of outparam in fd_locked_ioctl
Fix Smatch-detected error: drivers/block/floppy.c:3569 fd_locked_ioctl() error: uninitialized symbol 'outparam'. Use the outparam pointer only after it is explicitly initialized. Previously, fd_copyout() was called unconditionally after the switch-case statement, assuming outparam would always be set when _IOC_READ was active. However, not all paths ensured this, which led to potential use of an uninitialized pointer. Move fd_copyout() calls directly into the relevant case blocks immediately after outparam is set. This ensures it is only called when safe and applicable. Signed-off-by: Purva Yeshi <[email protected]>
1 parent 65e573f commit ac03334

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/block/floppy.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3482,6 +3482,7 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
34823482
memcpy(&inparam.g, outparam,
34833483
offsetof(struct floppy_struct, name));
34843484
outparam = &inparam.g;
3485+
return fd_copyout((void __user *)param, outparam, size);
34853486
break;
34863487
case FDMSGON:
34873488
drive_params[drive].flags |= FTD_MSG;
@@ -3515,13 +3516,15 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
35153516
return 0;
35163517
case FDGETMAXERRS:
35173518
outparam = &drive_params[drive].max_errors;
3519+
return fd_copyout((void __user *)param, outparam, size);
35183520
break;
35193521
case FDSETMAXERRS:
35203522
drive_params[drive].max_errors = inparam.max_errors;
35213523
break;
35223524
case FDGETDRVTYP:
35233525
outparam = drive_name(type, drive);
35243526
SUPBOUND(size, strlen((const char *)outparam) + 1);
3527+
return fd_copyout((void __user *)param, outparam, size);
35253528
break;
35263529
case FDSETDRVPRM:
35273530
if (!valid_floppy_drive_params(inparam.dp.autodetect,
@@ -3531,6 +3534,7 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
35313534
break;
35323535
case FDGETDRVPRM:
35333536
outparam = &drive_params[drive];
3537+
return fd_copyout((void __user *)param, outparam, size);
35343538
break;
35353539
case FDPOLLDRVSTAT:
35363540
if (lock_fdc(drive))
@@ -3541,17 +3545,20 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
35413545
fallthrough;
35423546
case FDGETDRVSTAT:
35433547
outparam = &drive_state[drive];
3548+
return fd_copyout((void __user *)param, outparam, size);
35443549
break;
35453550
case FDRESET:
35463551
return user_reset_fdc(drive, (int)param, true);
35473552
case FDGETFDCSTAT:
35483553
outparam = &fdc_state[FDC(drive)];
3554+
return fd_copyout((void __user *)param, outparam, size);
35493555
break;
35503556
case FDWERRORCLR:
35513557
memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
35523558
return 0;
35533559
case FDWERRORGET:
35543560
outparam = &write_errors[drive];
3561+
return fd_copyout((void __user *)param, outparam, size);
35553562
break;
35563563
case FDRAWCMD:
35573564
return floppy_raw_cmd_ioctl(type, drive, cmd, (void __user *)param);
@@ -3565,9 +3572,6 @@ static int fd_locked_ioctl(struct block_device *bdev, blk_mode_t mode,
35653572
return -EINVAL;
35663573
}
35673574

3568-
if (_IOC_DIR(cmd) & _IOC_READ)
3569-
return fd_copyout((void __user *)param, outparam, size);
3570-
35713575
return 0;
35723576
}
35733577

0 commit comments

Comments
 (0)