All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Lukas Wunner <lukas@wunner.de>
Cc: Mark Brown <broonie@kernel.org>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	linux-spi@vger.kernel.org, Tsuchiya Yuto <kitakar@gmail.com>,
	Daniel Mack <daniel@zonque.org>,
	Haojian Zhuang <haojian.zhuang@gmail.com>,
	Robert Jarzmik <robert.jarzmik@free.fr>
Subject: Re: [PATCH 2/3] spi: pxa2xx: Fix controller unregister order
Date: Mon, 25 May 2020 16:21:43 +0300	[thread overview]
Message-ID: <20200525132143.GX1634618@smile.fi.intel.com> (raw)
In-Reply-To: <834c446b1cf3284d2660f1bee1ebe3e737cd02a9.1590408496.git.lukas@wunner.de>

On Mon, May 25, 2020 at 02:25:02PM +0200, Lukas Wunner wrote:
> The PXA2xx SPI driver uses devm_spi_register_controller() on bind.
> As a consequence, on unbind, __device_release_driver() first invokes
> pxa2xx_spi_remove() before unregistering the SPI controller via
> devres_release_all().
> 
> This order is incorrect:  pxa2xx_spi_remove() disables the chip,
> rendering the SPI bus inaccessible even though the SPI controller is
> still registered.  When the SPI controller is subsequently unregistered,
> it unbinds all its slave devices.  Because their drivers cannot access
> the SPI bus, e.g. to quiesce interrupts, the slave devices may be left
> in an improper state.
> 
> As a rule, devm_spi_register_controller() must not be used if the
> ->remove() hook performs teardown steps which shall be performed after
> unregistering the controller and specifically after unbinding of slaves.
> 
> Fix by reverting to the non-devm variant of spi_register_controller().
> 
> An alternative approach would be to use device-managed functions for all
> steps in pxa2xx_spi_remove(), e.g. by calling devm_add_action_or_reset()
> on probe.  However that approach would add more LoC to the driver and
> it wouldn't lend itself as well to backporting to stable.

I think it's, unregistering controller first, proper way to quiescence it,
otherwise it can be a surprise transfer started while we are in removal stage.

Yes, there are still some bugs in state machine and remove ordering, but
perhaps they can be fixed separately.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Tsuchiya Yuto, I'm going to apply this series as preparatory to my WIP patch in
topic/spi/reload branch in my kernel tree on GitHub, so, it would be possible
to see if this + my patch fixes crashes on removal. Though, please test this
separately from my stuff to clarify if it fixes or not issue you have seen.

> 
> The improper use of devm_spi_register_controller() was introduced in 2013
> by commit a807fcd090d6 ("spi: pxa2xx: use devm_spi_register_master()"),
> but all earlier versions of the driver going back to 2006 were likewise
> broken because they invoked spi_unregister_master() at the end of
> pxa2xx_spi_remove(), rather than at the beginning.
> 
> Fixes: e0c9905e87ac ("[PATCH] SPI: add PXA2xx SSP SPI Driver")

I'm not sure it's a good idea to mix devm_*() with so old patch, though I
understand your point. Let's leave it up to Mark to decide what would be
correct commit reference here.

> Link: https://bugzilla.kernel.org/show_bug.cgi?id=206403#c1
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Cc: stable@vger.kernel.org # v2.6.17+
> Cc: Tsuchiya Yuto <kitakar@gmail.com>
> ---
>  drivers/spi/spi-pxa2xx.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
> index 20dcbd35611a..2ecf0d8cd9f7 100644
> --- a/drivers/spi/spi-pxa2xx.c
> +++ b/drivers/spi/spi-pxa2xx.c
> @@ -1885,7 +1885,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
>  
>  	/* Register with the SPI framework */
>  	platform_set_drvdata(pdev, drv_data);
> -	status = devm_spi_register_controller(&pdev->dev, controller);
> +	status = spi_register_controller(controller);
>  	if (status != 0) {
>  		dev_err(&pdev->dev, "problem registering spi controller\n");
>  		goto out_error_pm_runtime_enabled;
> @@ -1917,6 +1917,8 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
>  
>  	pm_runtime_get_sync(&pdev->dev);
>  
> +	spi_unregister_controller(drv_data->controller);
> +
>  	/* Disable the SSP at the peripheral and SOC level */
>  	pxa2xx_spi_write(drv_data, SSCR0, 0);
>  	clk_disable_unprepare(ssp->clk);
> -- 
> 2.25.0
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-05-25 13:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25 12:25 [PATCH 0/3] Intel SPI unbind fixes Lukas Wunner
2020-05-25 12:25 ` [PATCH 1/3] spi: dw: Fix controller unregister order Lukas Wunner
2020-05-25 13:15   ` Andy Shevchenko
2020-05-25 12:25 ` [PATCH 2/3] spi: pxa2xx: " Lukas Wunner
2020-05-25 13:21   ` Andy Shevchenko [this message]
2020-05-26  7:39     ` Lukas Wunner
2020-05-26  8:22       ` Andy Shevchenko
2020-05-27 12:09         ` Tsuchiya Yuto
2020-05-27 12:27           ` Andy Shevchenko
2020-05-27 13:14             ` Tsuchiya Yuto
2020-05-28  7:02               ` Tsuchiya Yuto
2020-05-28  8:41                 ` Andy Shevchenko
2020-05-28  9:31                   ` Lukas Wunner
2020-05-29 13:54                     ` Tsuchiya Yuto
2020-05-25 12:25 ` [PATCH 3/3] spi: pxa2xx: Fix runtime PM ref imbalance on probe error Lukas Wunner
2020-05-25 13:12   ` Andy Shevchenko
2020-05-26  8:46     ` Jarkko Nikula
2020-05-25 13:23 ` [PATCH 0/3] Intel SPI unbind fixes Andy Shevchenko
2020-05-26 16:46 ` Mark Brown

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=20200525132143.GX1634618@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=daniel@zonque.org \
    --cc=haojian.zhuang@gmail.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=kitakar@gmail.com \
    --cc=linux-spi@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=robert.jarzmik@free.fr \
    /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.