On 2/6/18, 8:53 PM, "Bart Van Assche" <Bart.VanAssche@xxxxxxx> wrote: >On Tue, 2018-02-06 at 05:12 -0800, Nilesh Javali wrote: >> From: Andrew Vasquez <andrew.vasquez@xxxxxxxxxx> >> >> The data in NVRAM is not guaranteed to be NUL terminated. >> Copy the data upto the element size or to the first NUL >> in the byte-stream and then append a NUL. >> >> Signed-off-by: Andrew Vasquez <andrew.vasquez@xxxxxxxxxx> >> Signed-off-by: Nilesh Javali <nilesh.javali@xxxxxxxxxx> >> --- >> drivers/scsi/qedi/qedi_main.c | 45 >>+++++++++++++++++++++++++++++++------------ >> 1 file changed, 33 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/scsi/qedi/qedi_main.c >>b/drivers/scsi/qedi/qedi_main.c >> index 8808f0d..f3dd438 100644 >> --- a/drivers/scsi/qedi/qedi_main.c >> +++ b/drivers/scsi/qedi/qedi_main.c >> @@ -1705,6 +1705,27 @@ void qedi_reset_host_mtu(struct qedi_ctx *qedi, >>u16 mtu) >> qedi_ops->ll2->start(qedi->cdev, ¶ms); >> } >> >> +static ssize_t >> +qedi_show_copy_data(char *buf, size_t size, u8 *data) >> +{ >> + size_t i; >> + >> + if (!data) >> + return sprintf(buf, "\n"); >> + >> + /* >> + * Data not guaranteed to be NUL terminated. Copy until NUL found or >> + * complete copy done. >> + */ >> + for (i = 0; i < size && data[i]; i++) >> + buf[i] = data[i]; >> + /* Data copy complete, append NEWLINE and NUL terminator. */ >> + buf[i] = '\n'; >> + buf[i + 1] = '\0'; >> + return strlen(buf); >> +} > >Can the body of the above function be changed into the following, which >is much >shorter? > >sprintf(buf, "%.*s", (int)size, data ? : "") This looks clean and shorter. I will send the updated patch. Thanks, Nilesh