From fd04fa039b1a43d13ac78791f2797685179ba8f9 Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Mon, 12 Jun 2017 23:02:07 +0300 Subject: [PATCH] sg: drop unneeded strdup from ->errdetails() handler *ret as well as strdup aren't really necessary, but only make the code complicated as shown in the previous commit. No functional change. This commit includes reverting of the previous commit. Signed-off-by: Tomohiro Kusumi Signed-off-by: Jens Axboe --- engines/sg.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/engines/sg.c b/engines/sg.c index 9d339bd3..b924ca3e 100644 --- a/engines/sg.c +++ b/engines/sg.c @@ -572,17 +572,17 @@ static char *fio_sgio_errdetails(struct io_u *io_u) struct sg_io_hdr *hdr = &io_u->hdr; #define MAXERRDETAIL 1024 #define MAXMSGCHUNK 128 - char *msg, msgchunk[MAXMSGCHUNK], *ret = NULL; + char *msg, msgchunk[MAXMSGCHUNK]; int i; msg = calloc(1, MAXERRDETAIL); + strcpy(msg, ""); /* * can't seem to find sg_err.h, so I'll just echo the define values * so others can search on internet to find clearer clues of meaning. */ if (hdr->info & SG_INFO_CHECK) { - ret = msg; if (hdr->host_status) { snprintf(msgchunk, MAXMSGCHUNK, "SG Host Status: 0x%02x; ", hdr->host_status); strlcat(msg, msgchunk, MAXERRDETAIL); @@ -755,16 +755,14 @@ static char *fio_sgio_errdetails(struct io_u *io_u) if (hdr->resid != 0) { snprintf(msgchunk, MAXMSGCHUNK, "SG Driver: %d bytes out of %d not transferred. ", hdr->resid, hdr->dxfer_len); strlcat(msg, msgchunk, MAXERRDETAIL); - ret = msg; } } - if (!ret) { - ret = strdup("SG Driver did not report a Host, Driver or Device check"); - free(msg); - } + if (!(hdr->info & SG_INFO_CHECK) && !strlen(msg)) + strncpy(msg, "SG Driver did not report a Host, Driver or Device check", + MAXERRDETAIL - 1); - return ret; + return msg; } /* -- 2.25.1