Content-Type: multipart/mixed; boundary="===============4860772477405332109==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 1/7] accel-config: Fix wrong return values in accfg_device_get_cmd_status Date: Tue, 02 Mar 2021 12:44:36 -0500 Message-ID: <20210302174442.206008-2-ramesh.thomas@intel.com> In-Reply-To: 20210302174442.206008-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============4860772477405332109== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas Function was returning 0 in error cases and incorrectly relying on errno for errors not related to strtol after which it is checked. Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index ae862f8..92afca1 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -1434,6 +1434,7 @@ ACCFG_EXPORT int accfg_device_get_cmd_status(struct a= ccfg_device *device) char *path; int len; char buf[SYSFS_ATTR_SIZE], *end_ptr; + int rc; = if (!device) return -EINVAL; @@ -1445,20 +1446,16 @@ ACCFG_EXPORT int accfg_device_get_cmd_status(struct= accfg_device *device) if (snprintf(path, len, "%s/cmd_status", device->device_path) >=3D len) { err(ctx, "%s: buffer too small!\n", accfg_device_get_devname(device)); - return 0; + return -ENOMEM; } = - if (sysfs_read_attr(ctx, path, buf) < 0) - return 0; + rc =3D sysfs_read_attr(ctx, path, buf); + if (rc < 0) + return rc; = status =3D strtol(buf, &end_ptr, 0); - if ((errno =3D=3D ERANGE && (status =3D=3D LONG_MAX || status =3D=3D LONG= _MIN)) || - (errno !=3D 0 && status =3D=3D 0)) - return -ERANGE; - - /* Nothing was found */ - if (end_ptr =3D=3D buf) - return -ENXIO; + if (errno =3D=3D ERANGE || end_ptr =3D=3D buf) + return -EIO; = return (int)status; } -- = 2.26.2 --===============4860772477405332109==--