* [Accel-config] [PATCH v1 1/7] accel-config: Fix wrong return values in accfg_device_get_cmd_status
@ 2021-03-02 17:44 ramesh.thomas
0 siblings, 0 replies; only message in thread
From: ramesh.thomas @ 2021-03-02 17:44 UTC (permalink / raw)
To: accel-config
[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
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 <ramesh.thomas(a)intel.com>
---
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 accfg_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) >= 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 = sysfs_read_attr(ctx, path, buf);
+ if (rc < 0)
+ return rc;
status = strtol(buf, &end_ptr, 0);
- if ((errno == ERANGE && (status == LONG_MAX || status == LONG_MIN)) ||
- (errno != 0 && status == 0))
- return -ERANGE;
-
- /* Nothing was found */
- if (end_ptr == buf)
- return -ENXIO;
+ if (errno == ERANGE || end_ptr == buf)
+ return -EIO;
return (int)status;
}
--
2.26.2
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-03-02 17:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 17:44 [Accel-config] [PATCH v1 1/7] accel-config: Fix wrong return values in accfg_device_get_cmd_status ramesh.thomas
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.