From: Jake McManus Date: Thu, 10 Aug 2023 03:12:03 +0000 (-0400) Subject: LU-17000 lnet: remove redundant errno check in liblnetconfig.c X-Git-Tag: 2.15.58~20 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=1db59b7b603a917d4ab1bba98d94dd169475b86b;p=fs%2Flustre-release.git LU-17000 lnet: remove redundant errno check in liblnetconfig.c Variable root is assigned NULL at the beginning of lustre_lnet_show_stats(). If l_ioctl() fails, its return value stored in rc will take the True path in the following conditional. This conditional currently contains a redundant check for errno, despite the fact that rc would = -errno in this case. If errno had changed between the l_ioctl() call and this subsequent read, errno could be 0, which would, from the out: label, lead to a NULL root being used as a parameter in cYAML_insert_sibling() and dereferencing the NULL root pointer. Replaced l_errno's use as a parameter in strerror with -rc, and removed decleration and other references to l_errno. Addresses-Coverity-ID: 397850 ("Explicit null dereferenced") Signed-off-by: Jake McManus Change-Id: I78f080837b60c8216c52bda8562d4c0f9f45a132 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51846 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Timothy Day Reviewed-by: Chris Horn Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 36bb891..7ed9c05 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -4263,7 +4263,6 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc, struct lnet_ioctl_lnet_stats data; struct lnet_counters *cntrs; int rc; - int l_errno; char err_str[LNET_MAX_STR_LEN] = "\"out of memory\""; struct cYAML *root = NULL, *stats = NULL; @@ -4271,12 +4270,10 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc, rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data); if (rc) { - l_errno = errno; snprintf(err_str, sizeof(err_str), "\"cannot get lnet statistics: %s\"", - strerror(l_errno)); - rc = -l_errno; + strerror(-rc)); goto out; }