lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190206095650.GJ21401@unicorn.suse.cz>
Date:   Wed, 6 Feb 2019 10:56:50 +0100
From:   Michal Kubecek <mkubecek@...e.cz>
To:     netdev@...r.kernel.org
Cc:     Jeff Kirsher <jeffrey.t.kirsher@...el.com>, linville@...driver.com,
        Nicholas Nunley <nicholas.d.nunley@...el.com>,
        nhorman@...hat.com, sassmann@...hat.com
Subject: Re: [PATCH v2 1/6] ethtool: move option parsing related code into
 function

On Tue, Feb 05, 2019 at 04:01:01PM -0800, Jeff Kirsher wrote:
> From: Nicholas Nunley <nicholas.d.nunley@...el.com>
> 
> Move option parsing code into find_option function.
> 
> No behavior changes.
> 
> Based on patch by Kan Liang <kan.liang@...el.com>
> 
> Signed-off-by: Nicholas Nunley <nicholas.d.nunley@...el.com>
> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@...el.com>
> ---
>  ethtool.c | 49 +++++++++++++++++++++++++++++++------------------
>  1 file changed, 31 insertions(+), 18 deletions(-)
> 
> diff --git a/ethtool.c b/ethtool.c
> index 2f7e96b..8b7c224 100644
> --- a/ethtool.c
> +++ b/ethtool.c
> @@ -5265,6 +5265,29 @@ static int show_usage(struct cmd_context *ctx)
>  	return 0;
>  }
>  
> +static int find_option(int argc, char **argp)
> +{
> +	const char *opt;
> +	size_t len;
> +	int k;
> +
> +	for (k = 0; args[k].opts; k++) {
> +		opt = args[k].opts;
> +		for (;;) {
> +			len = strcspn(opt, "|");
> +			if (strncmp(*argp, opt, len) == 0 &&
> +			    (*argp)[len] == 0)
> +				return k;
> +
> +			if (opt[len] == 0)
> +				break;
> +			opt += len + 1;
> +		}
> +	}
> +
> +	return -1;
> +}
> +
>  int main(int argc, char **argp)
>  {
>  	int (*func)(struct cmd_context *);
> @@ -5284,24 +5307,14 @@ int main(int argc, char **argp)
>  	 */
>  	if (argc == 0)
>  		exit_bad_args();
> -	for (k = 0; args[k].opts; k++) {
> -		const char *opt;
> -		size_t len;
> -		opt = args[k].opts;
> -		for (;;) {
> -			len = strcspn(opt, "|");
> -			if (strncmp(*argp, opt, len) == 0 &&
> -			    (*argp)[len] == 0) {
> -				argp++;
> -				argc--;
> -				func = args[k].func;
> -				want_device = args[k].want_device;
> -				goto opt_found;
> -			}
> -			if (opt[len] == 0)
> -				break;
> -			opt += len + 1;
> -		}
> +
> +	k = find_option(argc, argp);
> +	if (k >= 0) {
> +		argp++;
> +		argc--;
> +		func = args[k].func;
> +		want_device = args[k].want_device;
> +		goto opt_found;
>  	}
>  	if ((*argp)[0] == '-')
>  		exit_bad_args();

After hiding the loop into find_option() helper, you can put the
following few lines into else branch and get rid of the goto.

Michal Kubecek

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ