sg: drop unneeded strdup from ->errdetails() handler
authorTomohiro Kusumi <tkusumi@tuxera.com>
Mon, 12 Jun 2017 20:02:07 +0000 (23:02 +0300)
committerJens Axboe <axboe@fb.com>
Mon, 12 Jun 2017 20:51:01 +0000 (14:51 -0600)
*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 <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
engines/sg.c

index 9d339bd345554e671395e9c96fc13c66c0c14dab..b924ca3e0ae2afc2cfa83ab5b124fdfea53cda4c 100644 (file)
@@ -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;
 }
 
 /*