linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	Drew Fustini <drew@beagleboard.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Tony Lindgren <tony@atomide.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
	Jason Kridner <jkridner@beagleboard.org>,
	Robert Nelson <robertcnelson@beagleboard.org>
Subject: Re: [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file
Date: Wed, 10 Feb 2021 23:24:23 -0800	[thread overview]
Message-ID: <7b4105ca8671a2962910deb5418a934bf07d1458.camel@perches.com> (raw)
In-Reply-To: <20210211071153.GJ20820@kadam>

On Thu, 2021-02-11 at 10:11 +0300, Dan Carpenter wrote:
> On Wed, Feb 10, 2021 at 02:28:54PM -0800, Drew Fustini wrote:
> > +	ret = strncpy_from_user(buf, user_buf, PINMUX_MAX_NAME * 2);
> > +	if (ret < 0) {
> > +		dev_err(pctldev->dev, "failed to copy buffer from userspace");
> > +		goto free_gname;
> > +	}
> > +	buf[len-1] = '\0';
> > +
> > +	ret = sscanf(buf, "%s %s", fname, gname);
> > +	if (ret != 2) {
> > +		dev_err(pctldev->dev, "expected format: <function-name> <group-name>");
> > +		goto free_gname;
> 
> We need a "ret = -EINVAL;" before the goto.  sscanf doesn't return error
> codes.  Normally we would write it like so:
> 
> 	if (sscanf(buf, "%s %s", fname, gname) != 2) {
> 		dev_err(pctldev->dev, "expected format: <function-name> <group-name>");
> 		ret = -EINVAL;
> 		goto free_gname;
> 	}
> 
> I'm going to write a Smatch check for this today.

It's a pretty frequently used style:

$ git grep -P '\w+\s*=\s+sscanf\b' | wc -l
327

A grep with -A5 seems to show most use some additional error assignment
when checking the return value.

$ git grep -P -A5 '\w+\s*=\s+sscanf\b' | grep -P '(?:return|=)\s*\-E' | wc -l
174



  reply	other threads:[~2021-02-11  7:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10 22:28 [PATCH v4 0/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
2021-02-10 22:28 ` [PATCH v4 1/2] pinctrl: use to octal permissions for debugfs files Drew Fustini
2021-02-11  7:36   ` Joe Perches
2021-02-11  7:52     ` Drew Fustini
2021-02-10 22:28 ` [PATCH v4 2/2] pinctrl: pinmux: Add pinmux-select debugfs file Drew Fustini
2021-02-11  7:11   ` Dan Carpenter
2021-02-11  7:24     ` Joe Perches [this message]
2021-02-11  7:39       ` Dan Carpenter
2021-02-12  3:35         ` Drew Fustini
2021-02-17  8:18           ` Dan Carpenter
2021-02-11  8:09   ` Geert Uytterhoeven
2021-02-11  9:53     ` Andy Shevchenko
2021-02-12  3:39       ` Drew Fustini
2021-02-12  3:37     ` Drew Fustini
2021-02-11 12:00   ` Dan Carpenter
2021-02-12  3:41     ` Drew Fustini

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=7b4105ca8671a2962910deb5418a934bf07d1458.camel@perches.com \
    --to=joe@perches.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=drew@beagleboard.org \
    --cc=geert@linux-m68k.org \
    --cc=jkridner@beagleboard.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=robertcnelson@beagleboard.org \
    --cc=tony@atomide.com \
    /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).