From 1db59b7b603a917d4ab1bba98d94dd169475b86b Mon Sep 17 00:00:00 2001 From: Jake McManus Date: Wed, 9 Aug 2023 23:12:03 -0400 Subject: [PATCH] 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 --- lnet/utils/lnetconfig/liblnetconfig.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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; } -- 1.8.3.1