From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============5654012950571302070==" MIME-Version: 1.0 From: Dave Jiang Subject: [Accel-config] Re: [PATCH v1 3/5] accel-config: Fix a return value error Date: Tue, 08 Dec 2020 13:54:31 -0700 Message-ID: <20201208135431.00004e00@intel.com> In-Reply-To: 20201208203647.343395-4-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============5654012950571302070== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On Tue, 8 Dec 2020 15:36:45 -0500 wrote: > 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; -ENODEV? -ENOENT? probably better than just -1. = > } > = > static int mdev_str_to_type(char *mdev_type_str) --===============5654012950571302070==--