linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "weiyongjun (A)" <weiyongjun1@huawei.com>
Cc: Wei Yongjun <weiyj.lk@gmail.com>,
	Sebastian Reichel <sre@kernel.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>
Subject: Re: [PATCH -next] power: supply: ltc3651-charger: Fix wrong pointer passed to PTR_ERR()
Date: Fri, 19 May 2017 15:07:08 -0700	[thread overview]
Message-ID: <20170519220708.GG19281@dtor-ws> (raw)
In-Reply-To: <6AADFAC011213A4C87B956458587ADB47F6B4A@SZXEMI508-MBX.china.huawei.com>

Hi Wei,

On Fri, May 19, 2017 at 01:27:51AM +0000, weiyongjun (A) wrote:
> Hi, Dmitry
> 
> > Subject: Re: [PATCH -next] power: supply: ltc3651-charger: Fix wrong pointer
> > passed to PTR_ERR()
> > 
> > On Wed, May 17, 2017 at 12:11:32PM +0000, Wei Yongjun wrote:
> > > From: Wei Yongjun <weiyongjun1@huawei.com>
> > >
> > > PTR_ERR should access the value just tested by IS_ERR, otherwise
> > > the wrong error code will be returned.
> > >
> > > Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
> > 
> > This does fix the issue, but maybe we want to use PTR_ERR_OR_ZERO()?
> > 
> > 	ltc3651_charger->acpr_gpio = devm_gpiod_get(&pdev->dev,
> > 					"lltc,acpr", GPIOD_IN);
> > 	ret = PTR_ERR_OR_ZERO(ltc3651_charger->acpr_gpio);
> > 	if (ret)
> > 		...
> > 
> > Or even
> > 
> > 	err = PTR_ERR_OR_ZERO((ltc3651_charger->acpr_gpio =
> > 		devm_gpiod_get(&pdev->dev, "lltc,acpr", GPIOD_IN)));
> > 	if (err)
> > 		...
> > 
> > To make sure we never mix up pointer. Maybe we need
> > ERR_OR_ASSIGN(ptr1,
> > ptr2) to avoid the ugly assignment in argument above...
> > 
> 
> I have checked devm_gpiod_get() and seems it never return NULL.  And the other
> places call devm_gpiod_get() never check for NULL return. So I think PTR_ERR_OR_ZERO()
> is not need here.

The request to use PTR_ERR_OR_ZERO() had nothing to do with
devm_gpiod_get() returning NULL and everything with reducing number of
times one has to write "ltc3651_charger->acpr_gpio". The original
problem was that we checked the wrong value, if we provide macro
incorporating assignment and conversion to an error code in one step
this will reduce number of times we screw up like that in the future.

Thanks.

-- 
Dmitry

  reply	other threads:[~2017-05-19 22:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-17 12:11 [PATCH -next] power: supply: ltc3651-charger: Fix wrong pointer passed to PTR_ERR() Wei Yongjun
2017-05-19  0:59 ` Dmitry Torokhov
2017-05-19  1:27   ` weiyongjun (A)
2017-05-19 22:07     ` Dmitry Torokhov [this message]
2017-06-07 20:16 ` Sebastian Reichel

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=20170519220708.GG19281@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=weiyj.lk@gmail.com \
    --cc=weiyongjun1@huawei.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).