[Accel-config] [PATCH v1 2/7] accel-config: Refactor accfg_device_get_cmd_status_str
ramesh.thomas at intel.com
| Newsgroups | dev.linux.lists.accel-config |
|---|---|
| Message-ID | <[email protected]> |
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Simplify the checking of the array containing error messages. The array
is a sparse array of character pointers with NULL in empty elements.
After excluding the bounds, the remaining elements can be returned
directly. A NULL would be returned as expected if the indexing status
code is invalid.
Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
accfg/lib/libaccfg.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c
index 92afca1..976d8cc 100644
--- a/accfg/lib/libaccfg.c
+++ b/accfg/lib/libaccfg.c
@@ -1463,20 +1463,12 @@ ACCFG_EXPORT int accfg_device_get_cmd_status(struct accfg_device *device)
ACCFG_EXPORT const char * accfg_device_get_cmd_status_str(struct accfg_device *device)
{
int status;
- const char *stat_str;
status = accfg_device_get_cmd_status(device);
- if (status < 0)
+ if (status < 0 || status >= ACCFG_CMD_STATUS_MAX)
return NULL;
- if (status > ACCFG_CMD_STATUS_MAX)
- return NULL;
-
- stat_str = accfg_device_cmd_status[status];
- if (strlen(stat_str) == 0)
- return NULL;
-
- return stat_str;
+ return accfg_device_cmd_status[status];
}
/* Helper function to validate device type in the defined device array based on
--
2.26.2