This patch fixes bunch of "Argument cannot be negative"
reported by Coverity.
CoverityID: 397713 ("Argument cannot be negative")
CoverityID: 397899 ("Argument cannot be negative")
Pass -rc to strerror() since rc is guaranteed to be negative.
CoverityID: 397769 ("Argument cannot be negative")
read() could return -1 on error. Check before using the value
CoverityID: 397780 ("Argument cannot be negative")
Use static allocation removing the need to call sysconf()
CoverityID: 403104 ("Argument cannot be negative")
On failure to open do not try to call close()
Fixes:
58d744e3 (LU-10092 pcc: Non-blocking PCC caching)
Fixes:
f172b116 (LU-10092 llite: Add persistent cache on client)
Fixes:
aed82919 (LU-16029 utils: add options to lr_reader to parse raw files)
Fixes:
86ba46c2 (LU-9680 obdclass: user netlink to collect devices information)
Signed-off-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Change-Id: Id51c6c184d30dce596e7ab948a6fd0768eed1503
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53796
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
fprintf(stderr,
"%s: cannot attach '%s' on '%s' to PCC with attach ID '%u': %s\n",
argv[0], fidstr, mntpath, attach_id,
- strerror(rc2));
+ strerror(-rc2));
}
if (rc == 0 && rc2 < 0)
rc = rc2;
*/
int llapi_pccdev_get(const char *mntpath)
{
- long page_size = sysconf(_SC_PAGESIZE);
char pathbuf[sizeof(struct obd_uuid)];
+ char buf[65536]; /* large engough to hold PPC dev list */
glob_t path;
- char *buf;
int fd;
int rc;
goto out_free_param;
}
- buf = calloc(1, page_size);
- if (buf == NULL) {
- rc = -ENOMEM;
- llapi_error(LLAPI_MSG_ERROR, rc,
- "error: pccdev_get: allocating '%s' buffer",
- path.gl_pathv[0]);
- goto out_close;
- }
-
while (1) {
- ssize_t count = read(fd, buf, page_size);
+ ssize_t count = read(fd, buf, sizeof(buf));
if (count == 0)
break;
break;
}
}
-out_close:
+
close(fd);
- free(buf);
+ cfs_free_param_data(&path);
+ return rc;
out_free_param:
cfs_free_param_data(&path);
return rc;
llapi_error(LLAPI_MSG_ERROR, errno,
"error on ioctl %#lx for '%s' (%d)",
(long)LL_IOC_LMV_SETSTRIPE, filename, fd);
-out:
close(fd);
+out:
free(namepath);
out_dirpath:
free(dirpath);
do {
n = read(fd, buf, sizeof(buf));
+ if (n < 0) {
+ fprintf(stderr,
+ "%s: dump_log() Failed to read: %s\n",
+ progname, strerror(errno));
+ exit(errno);
+ }
n = write(2, buf, n);
} while (n == sizeof(buf));
int parse_devname(char *func, char *name, int dev_id)
{
int rc = 0;
- int ret = -1;
if (!name)
- return ret;
+ return -EINVAL;
/* Test if its a pure number string */
if (strspn(name, "0123456789") != strlen(name)) {
name++;
rc = do_name2dev(func, name, dev_id);
- if (rc >= 0)
- ret = rc;
} else {
errno = 0;
- ret = strtoul(name, NULL, 10);
+ rc = strtoul(name, NULL, 10);
if (errno)
- rc = errno;
+ rc = -errno;
}
if (rc < 0)
fprintf(stderr, "No device found for name %s: %s\n",
- name, strerror(rc));
- return ret;
+ name, strerror(-rc));
+ return rc;
}
#ifdef HAVE_SERVER_SUPPORT