Content-Type: multipart/mixed; boundary="===============3139880962796945131==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 3/5] accel-config: Fix a return value error Date: Tue, 08 Dec 2020 15:36:45 -0500 Message-ID: <20201208203647.343395-4-ramesh.thomas@intel.com> In-Reply-To: 20201208203647.343395-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============3139880962796945131== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas device_parse_type did not return error even if device type name was invalid. Changed the implementation to iterate through basenames array and return the index of matched device type name. This assumes device type enum is equal to index of corresponding device type names in basenames array. If type is not found, return -1 indicating error. Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index 5835129..b1e6d86 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -400,17 +400,17 @@ static int device_parse(struct accfg_ctx *ctx, const = char *base_path, = static int device_parse_type(struct accfg_device *device) { - if (!device) - return -EINVAL; + char **b; + int i; = - if (!strcmp(device->device_type_str, "dsa")) - device->type =3D ACCFG_DEVICE_DSA; - else if (!strcmp(device->device_type_str, "iax")) - device->type =3D ACCFG_DEVICE_IAX; - else - device->type =3D ACCFG_DEVICE_TYPE_UNKNOWN; + for (b =3D accfg_basenames, i =3D 0; *b !=3D NULL; b++, i++) { + if (!strcmp(device->device_type_str, *b)) { + device->type =3D i; + return 0; + } + } = - return 0; + return -1; } = static int mdev_str_to_type(char *mdev_type_str) -- = 2.26.2 --===============3139880962796945131==--