mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] spi: Fix double-free on spi_unregister_master
@ 2007-11-08 14:35 Atsushi Nemoto
  2007-11-08 18:42 ` David Brownell
  0 siblings, 1 reply; 2+ messages in thread
From: Atsushi Nemoto @ 2007-11-08 14:35 UTC (permalink / raw)
  To: David Brownell, Tony Jones; +Cc: linux-kernel, akpm

After 49dce689ad4ef0fd1f970ef762168e4bd46f69a3, device_for_each_child
iteration hits the master device itself.  Do not call
spi_unregister_device() for the master device.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
 drivers/spi/spi.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 89769ce..b31f443 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -457,10 +457,11 @@ done:
 EXPORT_SYMBOL_GPL(spi_register_master);
 
 
-static int __unregister(struct device *dev, void *unused)
+static int __unregister(struct device *dev, void *master_dev)
 {
 	/* note: before about 2.6.14-rc1 this would corrupt memory: */
-	spi_unregister_device(to_spi_device(dev));
+	if (dev != master_dev)
+		spi_unregister_device(to_spi_device(dev));
 	return 0;
 }
 
@@ -478,7 +479,8 @@ void spi_unregister_master(struct spi_master *master)
 {
 	int dummy;
 
-	dummy = device_for_each_child(master->dev.parent, NULL, __unregister);
+	dummy = device_for_each_child(master->dev.parent, &master->dev,
+					__unregister);
 	device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);

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

* Re: [PATCH] spi: Fix double-free on spi_unregister_master
  2007-11-08 14:35 [PATCH] spi: Fix double-free on spi_unregister_master Atsushi Nemoto
@ 2007-11-08 18:42 ` David Brownell
  0 siblings, 0 replies; 2+ messages in thread
From: David Brownell @ 2007-11-08 18:42 UTC (permalink / raw)
  To: Atsushi Nemoto, Tony Jones; +Cc: linux-kernel, akpm, Stephen Street

On Thursday 08 November 2007, Atsushi Nemoto wrote:
> After 49dce689ad4ef0fd1f970ef762168e4bd46f69a3, device_for_each_child
> iteration hits the master device itself.  Do not call
> spi_unregister_device() for the master device.
> 
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

ACK, and thanks.  Regression against 2.6.23...

I should have searched for other device_for_each_child() calls
when I had to do the same thing to fix the mmc_spi breakage.

Looks like the pxa2xx_spi suspend() code probably broke too.
I CC'd the maintainer of that code, though I'm not sure how
much time he has for this lately.

I'll hope someone else checks for non-SPI driver stacks which
such "class_dev" elimination may have broke...


> ---
>  drivers/spi/spi.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 89769ce..b31f443 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -457,10 +457,11 @@ done:
>  EXPORT_SYMBOL_GPL(spi_register_master);
>  
>  
> -static int __unregister(struct device *dev, void *unused)
> +static int __unregister(struct device *dev, void *master_dev)
>  {
>  	/* note: before about 2.6.14-rc1 this would corrupt memory: */
> -	spi_unregister_device(to_spi_device(dev));
> +	if (dev != master_dev)
> +		spi_unregister_device(to_spi_device(dev));
>  	return 0;
>  }
>  
> @@ -478,7 +479,8 @@ void spi_unregister_master(struct spi_master *master)
>  {
>  	int dummy;
>  
> -	dummy = device_for_each_child(master->dev.parent, NULL, __unregister);
> +	dummy = device_for_each_child(master->dev.parent, &master->dev,
> +					__unregister);
>  	device_unregister(&master->dev);
>  }
>  EXPORT_SYMBOL_GPL(spi_unregister_master);
> 



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

end of thread, other threads:[~2007-11-08 19:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-08 14:35 [PATCH] spi: Fix double-free on spi_unregister_master Atsushi Nemoto
2007-11-08 18:42 ` David Brownell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®