linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: core: Fix panic when pinctrl devices with hogs are unregistered
@ 2017-01-05 15:52 Jon Hunter
  2017-01-05 16:15 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Hunter @ 2017-01-05 15:52 UTC (permalink / raw)
  To: Linus Walleij, Tony Lindgren
  Cc: linux-gpio, linux-kernel, linux-tegra, Jon Hunter

Commit df61b366af26 ('pinctrl: core: Use delayed work for hogs')
deferred part of the registration for pinctrl devices if the pinctrl
device has hogs. This introduced a window where if the pinctrl device
with hogs was sucessfully registered, but then unregistered again
(which could be caused by parent device being probe deferred) before
the delayed work has chanced to run, then this will cause a kernel
panic to occur because:

1. The 'pctldev->p' has not yet been initialised and when unregistering
   the pinctrl device we only check to see if it is an error value, but
   now it could also be NULL.
2. The pinctrl device may not have been added to the 'pinctrldev_list'
   list and we don't check to see if it was added before removing.

Fix up the above by checking to see if the 'pctldev->p' pointer is an
error value or NULL before putting the pinctrl device and verifying
that the pinctrl device is present in 'pinctrldev_list' before removing.

Fixes: df61b366af26 ('pinctrl: core: Use delayed work for hogs')

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
---
 drivers/pinctrl/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index d311d73..9f305ac 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -2064,6 +2064,8 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 void pinctrl_unregister(struct pinctrl_dev *pctldev)
 {
 	struct pinctrl_gpio_range *range, *n;
+	struct pinctrl_dev *p, *p1;
+
 	if (pctldev == NULL)
 		return;
 
@@ -2072,13 +2074,15 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev)
 	pinctrl_remove_device_debugfs(pctldev);
 	mutex_unlock(&pctldev->mutex);
 
-	if (!IS_ERR(pctldev->p))
+	if (!IS_ERR_OR_NULL(pctldev->p))
 		pinctrl_put(pctldev->p);
 
 	mutex_lock(&pinctrldev_list_mutex);
 	mutex_lock(&pctldev->mutex);
 	/* TODO: check that no pinmuxes are still active? */
-	list_del(&pctldev->node);
+	list_for_each_entry_safe(p, p1, &pinctrldev_list, node)
+		if (p == pctldev)
+			list_del(&p->node);
 	pinmux_generic_free_functions(pctldev);
 	pinctrl_generic_free_groups(pctldev);
 	/* Destroy descriptor tree */
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: core: Fix panic when pinctrl devices with hogs are unregistered
  2017-01-05 15:52 [PATCH] pinctrl: core: Fix panic when pinctrl devices with hogs are unregistered Jon Hunter
@ 2017-01-05 16:15 ` Linus Walleij
  2017-01-05 19:27   ` Tony Lindgren
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2017-01-05 16:15 UTC (permalink / raw)
  To: Jon Hunter; +Cc: Tony Lindgren, linux-gpio, linux-kernel, linux-tegra

On Thu, Jan 5, 2017 at 4:52 PM, Jon Hunter <jonathanh@nvidia.com> wrote:

> Commit df61b366af26 ('pinctrl: core: Use delayed work for hogs')
> deferred part of the registration for pinctrl devices if the pinctrl
> device has hogs. This introduced a window where if the pinctrl device
> with hogs was sucessfully registered, but then unregistered again
> (which could be caused by parent device being probe deferred) before
> the delayed work has chanced to run, then this will cause a kernel
> panic to occur because:
>
> 1. The 'pctldev->p' has not yet been initialised and when unregistering
>    the pinctrl device we only check to see if it is an error value, but
>    now it could also be NULL.
> 2. The pinctrl device may not have been added to the 'pinctrldev_list'
>    list and we don't check to see if it was added before removing.
>
> Fix up the above by checking to see if the 'pctldev->p' pointer is an
> error value or NULL before putting the pinctrl device and verifying
> that the pinctrl device is present in 'pinctrldev_list' before removing.
>
> Fixes: df61b366af26 ('pinctrl: core: Use delayed work for hogs')
>
> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>

Oops. Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: core: Fix panic when pinctrl devices with hogs are unregistered
  2017-01-05 16:15 ` Linus Walleij
@ 2017-01-05 19:27   ` Tony Lindgren
  0 siblings, 0 replies; 3+ messages in thread
From: Tony Lindgren @ 2017-01-05 19:27 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Jon Hunter, linux-gpio, linux-kernel, linux-tegra

* Linus Walleij <linus.walleij@linaro.org> [170105 08:16]:
> On Thu, Jan 5, 2017 at 4:52 PM, Jon Hunter <jonathanh@nvidia.com> wrote:
> 
> > Commit df61b366af26 ('pinctrl: core: Use delayed work for hogs')
> > deferred part of the registration for pinctrl devices if the pinctrl
> > device has hogs. This introduced a window where if the pinctrl device
> > with hogs was sucessfully registered, but then unregistered again
> > (which could be caused by parent device being probe deferred) before
> > the delayed work has chanced to run, then this will cause a kernel
> > panic to occur because:
> >
> > 1. The 'pctldev->p' has not yet been initialised and when unregistering
> >    the pinctrl device we only check to see if it is an error value, but
> >    now it could also be NULL.
> > 2. The pinctrl device may not have been added to the 'pinctrldev_list'
> >    list and we don't check to see if it was added before removing.
> >
> > Fix up the above by checking to see if the 'pctldev->p' pointer is an
> > error value or NULL before putting the pinctrl device and verifying
> > that the pinctrl device is present in 'pinctrldev_list' before removing.
> >
> > Fixes: df61b366af26 ('pinctrl: core: Use delayed work for hogs')
> >
> > Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> 
> Oops. Patch applied.

OK, did not see that with my testing of hogs with omap4-duovero-parlor.
Thanks for fixing that.

Tony

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-05 19:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-05 15:52 [PATCH] pinctrl: core: Fix panic when pinctrl devices with hogs are unregistered Jon Hunter
2017-01-05 16:15 ` Linus Walleij
2017-01-05 19:27   ` Tony Lindgren

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).