[Accel-config] Re: [PATCH v1 3/5] accel-config: Fix a return value error

Dave Jiang <dave.jiang at intel.com>
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
On Tue, 8 Dec 2020 15:36:45 -0500
<ramesh.thomas(a)intel.com> wrote:

> From: Ramesh Thomas <ramesh.thomas(a)intel.com>
> 
> 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 <ramesh.thomas(a)intel.com>
> ---
>  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 = ACCFG_DEVICE_DSA;
> -	else if (!strcmp(device->device_type_str, "iax"))
> -		device->type = ACCFG_DEVICE_IAX;
> -	else
> -		device->type = ACCFG_DEVICE_TYPE_UNKNOWN;
> +	for (b = accfg_basenames, i = 0; *b != NULL; b++, i++) {
> +		if (!strcmp(device->device_type_str, *b)) {
> +			device->type = i;
> +			return 0;
> +		}
> +	}
>  
> -	return 0;
> +	return -1;

-ENODEV? -ENOENT? probably better than just -1. 

>  }
>  
>  static int mdev_str_to_type(char *mdev_type_str)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.