public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: Richard Genoud <richard.genoud@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Axel Lin <axel.lin@ingics.com>,
	Stephen Warren <swarren@nvidia.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] BUG: pinmux: forbid mux_usecount to be set at UINT_MAX
Date: Wed, 20 Mar 2013 11:08:53 -0600	[thread overview]
Message-ID: <5149ED25.4010309@wwwdotorg.org> (raw)
In-Reply-To: <CACQ1gAjNFgPg+k9MLgGfvWGTYK1mi2nsiQ-LwCu2gdjjL3wkCA@mail.gmail.com>

On 03/20/2013 10:59 AM, Richard Genoud wrote:
> 2013/3/20 Stephen Warren <swarren@wwwdotorg.org>:
>> On 03/20/2013 05:31 AM, Richard Genoud wrote:
>>> If pin_free is called on a pin already freed, mux_usecount is set to
>>> UINT_MAX which is really a bad idea.
>>> This will silently ignore a double call to pin_free
>>
>> Shouldn't we WARN_ON(this case)?
> yes indeed, it may be better to issue a big warning because AFAIK
> that's not normal.
> 
>>
>>> diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
>>
>>>       if (!gpio_range) {
>>> -             desc->mux_usecount--;
>>> -             if (desc->mux_usecount)
>>> +             if (1 == desc->mux_usecount)
>>> +                     desc->mux_usecount = 0;
>>> +             else
>>>                       return NULL;
>>
>> What if desc-mux_usecount was 2; this patch prevents the use-count from
>> being decremented to 1 in this case. Shouldn't this be:
>>
>>         if (!gpio_range) {
>> +               if (WARN_ON(!desc->mux_usecount))
>> +                       return NULL;
>>                 desc->mux_usecount--;
>
> Well, I'm not very familiar with this code, but can mux_usecount be
> higher than 1 ?

Possibly not, but isn't that more something that the
resource-acquisition code (i.e. whatever does mux_usecount++) should
enforce; the cleanup code should probably support all cases in case the
enforcement rules change in the future. Either that, or convert the
field to a bool so it's clear what the range is.


  reply	other threads:[~2013-03-20 17:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 11:31 [PATCH] BUG: pinmux: release only taken pins on error Richard Genoud
2013-03-20 11:31 ` [PATCH] BUG: pinmux: forbid mux_usecount to be set at UINT_MAX Richard Genoud
2013-03-20 16:14   ` Stephen Warren
2013-03-20 16:59     ` Richard Genoud
2013-03-20 17:08       ` Stephen Warren [this message]
2013-03-21 11:21         ` Richard Genoud
2013-03-21 17:33           ` Stephen Warren
2013-03-21 18:28           ` Linus Walleij
2013-03-20 11:31 ` [PATCH] BUG: [RFC] pinctrl: pins are freed 2 times in pinctrl_bind_pins Richard Genoud
2013-03-20 16:23   ` Stephen Warren
2013-03-21 11:31     ` Richard Genoud
2013-03-20 13:21 ` [PATCH] BUG: pinmux: release only taken pins on error Axel Lin
2013-03-20 14:19   ` Richard Genoud

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=5149ED25.4010309@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=axel.lin@ingics.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard.genoud@gmail.com \
    --cc=swarren@nvidia.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