Content-Type: multipart/mixed; boundary="===============8785792983055122358==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 2/7] accel-config: Refactor accfg_device_get_cmd_status_str Date: Tue, 02 Mar 2021 12:44:37 -0500 Message-ID: <20210302174442.206008-3-ramesh.thomas@intel.com> In-Reply-To: 20210302174442.206008-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============8785792983055122358== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas 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 --- 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_dev= ice *device) { int status; - const char *stat_str; = status =3D accfg_device_get_cmd_status(device); - if (status < 0) + if (status < 0 || status >=3D ACCFG_CMD_STATUS_MAX) return NULL; = - if (status > ACCFG_CMD_STATUS_MAX) - return NULL; - - stat_str =3D accfg_device_cmd_status[status]; - if (strlen(stat_str) =3D=3D 0) - return NULL; - - return stat_str; + return accfg_device_cmd_status[status]; } = /* Helper function to validate device type in the defined device array bas= ed on -- = 2.26.2 --===============8785792983055122358==--