Commit 6ea54af9 authored by Martin Wilck's avatar Martin Wilck Committed by Greg Kroah-Hartman

scsi: scsi_devinfo: cleanly zero-pad devinfo strings

commit 81df022b upstream.

Cleanly fill memory for "vendor" and "model" with 0-bytes for the
"compatible" case rather than adding only a single 0 byte.  This
simplifies the devinfo code a a bit, and avoids mistakes in other places
of the code (not in current upstream, but we had one such mistake in the
SUSE kernel).

[mkp: applied by hand and added braces]
Signed-off-by: default avatarMartin Wilck <mwilck@suse.com>
Reviewed-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 46466e23
...@@ -34,7 +34,6 @@ struct scsi_dev_info_list_table { ...@@ -34,7 +34,6 @@ struct scsi_dev_info_list_table {
}; };
static const char spaces[] = " "; /* 16 of them */
static unsigned scsi_default_dev_flags; static unsigned scsi_default_dev_flags;
static LIST_HEAD(scsi_dev_info_list); static LIST_HEAD(scsi_dev_info_list);
static char scsi_dev_flags[256]; static char scsi_dev_flags[256];
...@@ -296,20 +295,13 @@ static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length, ...@@ -296,20 +295,13 @@ static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
size_t from_length; size_t from_length;
from_length = strlen(from); from_length = strlen(from);
strncpy(to, from, min(to_length, from_length)); /* this zero-pads the destination */
if (from_length < to_length) { strncpy(to, from, to_length);
if (compatible) { if (from_length < to_length && !compatible) {
/* /*
* NUL terminate the string if it is short. * space pad the string if it is short.
*/ */
to[from_length] = '\0'; memset(&to[from_length], ' ', to_length - from_length);
} else {
/*
* space pad the string if it is short.
*/
strncpy(&to[from_length], spaces,
to_length - from_length);
}
} }
if (from_length > to_length) if (from_length > to_length)
printk(KERN_WARNING "%s: %s string '%s' is too long\n", printk(KERN_WARNING "%s: %s string '%s' is too long\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment