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>
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)