Skip to content

Commit 81df022

Browse files
mwilckmartinkpetersen
authored andcommitted
scsi: scsi_devinfo: cleanly zero-pad devinfo strings
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: Martin Wilck <mwilck@suse.com> Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent ba69ead commit 81df022

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

‎drivers/scsi/scsi_devinfo.c‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ struct scsi_dev_info_list_table {
3434
};
3535

3636

37-
static const char spaces[] = " "; /* 16 of them */
3837
static blist_flags_t scsi_default_dev_flags;
3938
static LIST_HEAD(scsi_dev_info_list);
4039
static char scsi_dev_flags[256];
@@ -298,20 +297,13 @@ static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
298297
size_t from_length;
299298

300299
from_length = strlen(from);
301-
strncpy(to, from, min(to_length, from_length));
302-
if (from_length < to_length) {
303-
if (compatible) {
304-
/*
305-
* NUL terminate the string if it is short.
306-
*/
307-
to[from_length] = '\0';
308-
} else {
309-
/*
310-
* space pad the string if it is short.
311-
*/
312-
strncpy(&to[from_length], spaces,
313-
to_length - from_length);
314-
}
300+
/* This zero-pads the destination */
301+
strncpy(to, from, to_length);
302+
if (from_length < to_length && !compatible) {
303+
/*
304+
* space pad the string if it is short.
305+
*/
306+
memset(&to[from_length], ' ', to_length - from_length);
315307
}
316308
if (from_length > to_length)
317309
printk(KERN_WARNING "%s: %s string '%s' is too long\n",

0 commit comments

Comments
 (0)