netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Eli Cohen <eli@mellanox.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH] Add support for configuring Infiniband GUIDs
Date: Wed, 6 Jul 2016 21:05:26 -0700	[thread overview]
Message-ID: <20160706210526.1e6ea9a4@xeon-e3> (raw)
In-Reply-To: <1467734018-11119-1-git-send-email-eli@mellanox.com>

On Tue,  5 Jul 2016 10:53:38 -0500
Eli Cohen <eli@mellanox.com> wrote:

>  
> +static int extract_guid(__u64 *guid, char *arg)
> +{
> +	__u64 ret;
> +	int g[8];
> +	int err;
> +
> +	err = sscanf(arg, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
> +		     g, g + 1, g + 2, g + 3, g + 4, g + 5, g + 6, g + 7);
> +	if (err != 8)
> +		return -1;
> +
> +	ret = ((__u64)(g[0]) << 56) |
> +	      ((__u64)(g[1]) << 48) |
> +	      ((__u64)(g[2]) << 40) |
> +	      ((__u64)(g[3]) << 32) |
> +	      ((__u64)(g[4]) << 24) |
> +	      ((__u64)(g[5]) << 16) |
> +	      ((__u64)(g[6]) << 8) |
> +	      ((__u64)(g[7]));
> +	*guid = ret;
> +
> +	return 0;
> +}

I would like several things changed here.
 1. put this in generic (ie lib/utils.c) so that other places
    can use it. And rename it match other arg parsing code (ie get_guid)
 2. need range checking for each piece the string, and each hex piece must be unsigned int
    suprised gcc format checks didn't bust you on this.  why not %hhx as format specifier
    
 3. arg should be const char *
 4. local variable err is really unnecessary
 5. local variable ret is unnecessary, you could just assign to *guid
 

  reply	other threads:[~2016-07-07  4:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 15:53 [PATCH] Add support for configuring Infiniband GUIDs Eli Cohen
2016-07-07  4:05 ` Stephen Hemminger [this message]
2016-07-07 10:08   ` David Laight
2016-07-07 21:11   ` Eli Cohen
  -- strict thread matches above, loose matches on Subject: below --
2016-05-06 15:43 Eli Cohen
2016-05-06 17:05 ` Sergei Shtylyov
2016-06-30 18:17   ` Eli Cohen
2016-05-06 18:53 ` Stephen Hemminger
2016-05-09 15:52   ` Eli Cohen
2016-05-13 19:52     ` Eli Cohen
2016-06-06 17:09       ` Eli Cohen
2016-05-08  4:59 ` Leon Romanovsky

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=20160706210526.1e6ea9a4@xeon-e3 \
    --to=stephen@networkplumber.org \
    --cc=eli@mellanox.com \
    --cc=netdev@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).