From: Stephen Warren <swarren@wwwdotorg.org>
To: Richard Genoud <richard.genoud@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
Stephen Warren <swarren@nvidia.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/4] pinctrl: disable and free setting in select_state in case of error
Date: Thu, 28 Mar 2013 08:53:01 -0600 [thread overview]
Message-ID: <5154594D.6000103@wwwdotorg.org> (raw)
In-Reply-To: <CACQ1gAjEUsCuFThzAfoX3-PHn3h70=qw+uktHNd9cQDWeQZ1Jw@mail.gmail.com>
On 03/28/2013 04:55 AM, Richard Genoud wrote:
> 2013/3/28 Stephen Warren <swarren@wwwdotorg.org>:
>> On 03/25/2013 08:47 AM, Richard Genoud wrote:
>>> If enabling a pin fails in pinctrl_select_state_locked(), all the
>>> previous enabled pins have to be disabled to get back to the previous
>>> state.
>>
>>> diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
>>> + list_for_each_entry(setting2, &state->settings, node) {
>>> + if (&setting2->node == &setting->node)
>>> + break;
>>> + pinctrl_free_setting(true, setting2);
>>
>> That's clearly wrong.
>>
>> pinctrl_free_setting() is supposed to free any memory associated with
>> the setting; the storage that holds the representation of that setting.
>>
>> It's only appropriate to do that in pinctrl_put(), when actually
>> destroying the whole struct pinctrl object. If pinctrl_select() fails,
>> we don't want to destroy/invalidate the struct pinctrl content, but
>> rather keep it around in case the driver uses it again even if the face
>> of previous errors.
>>
>> In other words, what you should be doing inside this loop body is
>> exactly what the body of the first loop inside pinctrl_select_state()
>> does to "undo" any previously selected state, which is to call
>> pinmux_disable_setting() for each entry, or something similar to that.
>
> The code here tries to undo what have been done in the *second* loop
> of pinctrl_select_state().
>
> The "do" loop is:
>
> list_for_each_entry(setting, &state->settings, node) {
> switch (setting->type) {
> case PIN_MAP_TYPE_MUX_GROUP:
> ret = pinmux_enable_setting(setting);
> break;
> case PIN_MAP_TYPE_CONFIGS_PIN:
> case PIN_MAP_TYPE_CONFIGS_GROUP:
> ret = pinconf_apply_setting(setting);
> break;
> default:
> ret = -EINVAL;
> break;
> }
>
> if (ret < 0)
> goto unapply_new_state;
> }
Right, I understand that.
> And maybe I'm wrong, but I understood that to "undo" pinmux_enable_setting,
> we call pinmux_disable_setting()
Yes.
> and pinmux_free_setting() (which is empty for now).
No. pinmux_free_setting() free's the storage for a setting. Right now,
nothing is dynamically allocated for the setting, so there's nothing to
do. However, it's still semantically wrong to try to free it at this point.
> And to undo pinconf_apply_setting() we call pinconf_free_setting()
> And that's what pinctrl_free_setting() does.
There's no way to undo the application of a setting. The only way to
undo it is to apply a new setting that over-writes it. Hopefully,
re-applying a different state would do that, but it's not guaranteed.
Again, pinconf_free_setting() is all about freeing any dynamically
allocated storage required to represent the setting itself; it's not
about (un-)programming HW.
next prev parent reply other threads:[~2013-03-28 14:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-25 14:47 [PATCH 0/4] pintrcl: restore old state when pinctrl_select_state fails Richard Genoud
2013-03-25 14:47 ` [PATCH 1/4] pinctrl: fix typo in header Richard Genoud
2013-03-27 22:13 ` Linus Walleij
2013-03-25 14:47 ` [PATCH 2/4] pinctrl: create pinctrl_free_setting function Richard Genoud
2013-03-27 22:15 ` Linus Walleij
2013-03-25 14:47 ` [PATCH 3/4] pinctrl: disable and free setting in select_state in case of error Richard Genoud
2013-03-27 22:17 ` Linus Walleij
2013-03-27 23:49 ` Stephen Warren
2013-03-28 10:55 ` Richard Genoud
2013-03-28 14:53 ` Stephen Warren [this message]
2013-03-28 15:47 ` Richard Genoud
2013-04-03 12:30 ` Linus Walleij
2013-04-03 12:36 ` Richard Genoud
2013-03-25 14:47 ` [PATCH 4/4] pinctrl: re-enable old state in case of error in pinctrl_select_state Richard Genoud
2013-03-27 22:18 ` Linus Walleij
2013-03-27 23:55 ` Stephen Warren
2013-03-28 11:35 ` Richard Genoud
2013-03-28 17:34 ` Richard GENOUD
2013-03-28 17:38 ` Stephen Warren
2013-03-28 18:06 ` 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=5154594D.6000103@wwwdotorg.org \
--to=swarren@wwwdotorg.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.