]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
scsi: scsi_ioctl: Use strnlen() in scsi_ioctl_get_pci()
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 17 May 2026 17:15:47 +0000 (19:15 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sat, 23 May 2026 01:12:32 +0000 (21:12 -0400)
Use strnlen() to limit string scanning to 20 characters.

Reformat the code and use tabs instead of spaces while at it.

[mkp: tweaked comment formatting]

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Link: https://patch.msgid.link/20260517171546.2304-2-thorsten.blum@linux.dev
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/scsi_ioctl.c

index 0ddc95bafc71f76aee9c211842faea0f2eed16cc..c14f81403a09e688a958d2bf803df22b068434d4 100644 (file)
@@ -176,10 +176,13 @@ static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg)
 
        name = dev_name(dev);
 
-       /* compatibility with old ioctl which only returned
-        * 20 characters */
-        return copy_to_user(arg, name, min(strlen(name), (size_t)20))
-               ? -EFAULT: 0;
+       /*
+        * Compatibility with old ioctl which only returned 20 characters.
+        */
+       if (copy_to_user(arg, name, strnlen(name, 20)))
+               return -EFAULT;
+
+       return 0;
 }
 
 static int sg_get_version(int __user *p)