All of lore.kernel.org
 help / color / mirror / Atom feed
* [Accel-config] Re: [PATCH v1 3/5] accel-config: Fix a return value error
@ 2020-12-08 20:54 Dave Jiang
  0 siblings, 0 replies; only message in thread
From: Dave Jiang @ 2020-12-08 20:54 UTC (permalink / raw)
  To: accel-config

[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

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)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-08 20:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-08 20:54 [Accel-config] Re: [PATCH v1 3/5] accel-config: Fix a return value error Dave Jiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.