2021-04-23 03:44:58

by Artem Lapkin

[permalink] [raw]
Subject: [PATCH] SPI: meson-spifc add missed calls to remove function

Problem: rmmod meson_gx_mmc - not stable without spi_master_suspend call
and we can get stuck when try unload this module

rmmod meson_gx_mmc
...
[ 421.108614] Deleting MTD partitions on "spi0.0":
[ 424.219862] spi_master spi0: Failed to power device: -13
...
lsmod | grep spi
spi_meson_spifc 16384 -1

Solution: just add spi_master_suspend(master) call

Signed-off-by: Artem Lapkin <[email protected]>
---
drivers/spi/spi-meson-spifc.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/spi/spi-meson-spifc.c b/drivers/spi/spi-meson-spifc.c
index 8eca6f24c..8a97a6dbf 100644
--- a/drivers/spi/spi-meson-spifc.c
+++ b/drivers/spi/spi-meson-spifc.c
@@ -359,6 +359,7 @@ static int meson_spifc_remove(struct platform_device *pdev)
struct spi_master *master = platform_get_drvdata(pdev);
struct meson_spifc *spifc = spi_master_get_devdata(master);

+ spi_master_suspend(master);
pm_runtime_get_sync(&pdev->dev);
clk_disable_unprepare(spifc->clk);
pm_runtime_disable(&pdev->dev);
--
2.25.1


2021-04-23 11:49:37

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] SPI: meson-spifc add missed calls to remove function

On Fri, Apr 23, 2021 at 11:42:47AM +0800, Artem Lapkin wrote:
> Problem: rmmod meson_gx_mmc - not stable without spi_master_suspend call
> and we can get stuck when try unload this module

> +++ b/drivers/spi/spi-meson-spifc.c
> @@ -359,6 +359,7 @@ static int meson_spifc_remove(struct platform_device *pdev)
> struct spi_master *master = platform_get_drvdata(pdev);
> struct meson_spifc *spifc = spi_master_get_devdata(master);
>
> + spi_master_suspend(master);
> pm_runtime_get_sync(&pdev->dev);
> clk_disable_unprepare(spifc->clk);
> pm_runtime_disable(&pdev->dev);

I would expect the driver to unregister the controller at the start of
the remove function, suspend doesn't really make sense here.


Attachments:
(No filename) (730.00 B)
signature.asc (499.00 B)
Download all attachments

2021-04-24 00:12:35

by Artem Lapkin

[permalink] [raw]
Subject: Re: [PATCH] SPI: meson-spifc add missed calls to remove function

> I would expect the driver to unregister the controller at the start of
> the remove function, suspend doesn't really make sense here

It's strange - But without spi_master_suspend i have randomly stucks
when i try unload this module - as was written before
i was test it (load/unload module in loop) and for me suspend make sense here

If anybody has another solution - or real problem not here - please
help to find the right way!

PS: i have another way for solve this problem (may be it can help us
fix problem in kernel)

# before unload module need
echo -n spi0.0 > /sys/bus/spi/drivers/spi-nor/unbind
# after unbind driver we can unload module without problem
rmmod spi_meson_spifc # can stuck without unbind driver before ...


On Fri, Apr 23, 2021 at 7:48 PM Mark Brown <[email protected]> wrote:
>
> On Fri, Apr 23, 2021 at 11:42:47AM +0800, Artem Lapkin wrote:
> > Problem: rmmod meson_gx_mmc - not stable without spi_master_suspend call
> > and we can get stuck when try unload this module
>
> > +++ b/drivers/spi/spi-meson-spifc.c
> > @@ -359,6 +359,7 @@ static int meson_spifc_remove(struct platform_device *pdev)
> > struct spi_master *master = platform_get_drvdata(pdev);
> > struct meson_spifc *spifc = spi_master_get_devdata(master);
> >
> > + spi_master_suspend(master);
> > pm_runtime_get_sync(&pdev->dev);
> > clk_disable_unprepare(spifc->clk);
> > pm_runtime_disable(&pdev->dev);
>
> I would expect the driver to unregister the controller at the start of
> the remove function, suspend doesn't really make sense here.

2021-04-26 11:58:26

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] SPI: meson-spifc add missed calls to remove function

On Sat, Apr 24, 2021 at 07:57:19AM +0800, Art Nikpal wrote:

> > I would expect the driver to unregister the controller at the start of
> > the remove function, suspend doesn't really make sense here

> It's strange - But without spi_master_suspend i have randomly stucks when i
> try unload this module - as was written before
> i was test it (load/unload module in loop) and for me suspend make sense
> here

> If anybody has another solution - or real problem not here - please write
> to me the right way!

As I said above unregister the controller at the start of the remove
function.


Attachments:
(No filename) (605.00 B)
signature.asc (499.00 B)
Download all attachments

2021-04-30 08:50:48

by Artem Lapkin

[permalink] [raw]
Subject: Re: [PATCH] SPI: meson-spifc add missed calls to remove function

Yep! but

if i try call spi_master_put(master) or spi_unregister_controller(master);
it's made Segmentation fault for me

what's wrong - may be somebody can help me


On Mon, Apr 26, 2021 at 7:57 PM Mark Brown <[email protected]> wrote:
>
> On Sat, Apr 24, 2021 at 07:57:19AM +0800, Art Nikpal wrote:
>
> > > I would expect the driver to unregister the controller at the start of
> > > the remove function, suspend doesn't really make sense here
>
> > It's strange - But without spi_master_suspend i have randomly stucks when i
> > try unload this module - as was written before
> > i was test it (load/unload module in loop) and for me suspend make sense
> > here
>
> > If anybody has another solution - or real problem not here - please write
> > to me the right way!
>
> As I said above unregister the controller at the start of the remove
> function.

2021-04-30 11:01:03

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] SPI: meson-spifc add missed calls to remove function

On Fri, Apr 30, 2021 at 04:49:35PM +0800, Art Nikpal wrote:

> Yep! but

Please don't top post, reply in line with needed context. This allows
readers to readily follow the flow of conversation and understand what
you are talking about and also helps ensure that everything in the
discussion is being addressed.

> if i try call spi_master_put(master) or spi_unregister_controller(master);
> it's made Segmentation fault for me
>
> what's wrong - may be somebody can help me

Probably something is referencing the controller afer it was freed, I do
notice that the current version of the driver uses devm_ to register the
controller so you'd end up with a double free unless you either use devm_
when freeing or change to a normal registration.


Attachments:
(No filename) (765.00 B)
signature.asc (499.00 B)
Download all attachments