All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang at intel.com>
To: accel-config@lists.01.org
Subject: [Accel-config] Re: [PATCH v1 3/5] accel-config: Fix a return value error
Date: Tue, 08 Dec 2020 13:54:31 -0700	[thread overview]
Message-ID: <20201208135431.00004e00@intel.com> (raw)
In-Reply-To: 20201208203647.343395-4-ramesh.thomas@intel.com

[-- 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)

                 reply	other threads:[~2020-12-08 20:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201208135431.00004e00@intel.com \
    --to=accel-config@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.