linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] spi: Fix device unregistration when unregistering the bus master
@ 2011-11-28 13:23 Laurent Pinchart
       [not found] ` <1322486604-27808-1-git-send-email-laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
  0 siblings, 1 reply; 10+ messages in thread
From: Laurent Pinchart @ 2011-11-28 13:23 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f

Device are added as children of the bus master's parent device, but
spi_unregister_master() looks for devices to unregister in the bus
master's children. This results in the child devices not being
unregistered.

Fix this by iterating over the bus master's parent device when
unregistering the master.

Signed-off-by: Laurent Pinchart <laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
---
 drivers/spi/spi.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Hi,

I came across this issue when developing an SPI master driver for a platform
device. Board code registers SPI board information for a flash device, an SPI
device was created when I loaded my SPI master driver, but it stayed there when
the SPI master driver was removed.

SPI master unregistration has been patched a couple of times:

- 97dbf37d ("drivers/spi/spi.c: don't release the spi device twice")
- 3486008 ("spi: free children in spi_unregister_master, not siblings")
- 2b9603a0 ("spi: enable spi_board_info to be registered after spi_master")

I'm not too familiar with the way the SPI subsystem plugs its devices in the
Linux device model, so I'm not sure what the right fix is. An alternative would
be to register the SPI devices as children of the SPI master, not as siblings.

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 2e13a14..081e0a1 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -638,7 +638,8 @@ EXPORT_SYMBOL_GPL(spi_register_master);
 
 static int __unregister(struct device *dev, void *null)
 {
-	spi_unregister_device(to_spi_device(dev));
+	if (dev->bus == &spi_bus_type)
+		spi_unregister_device(to_spi_device(dev));
 	return 0;
 }
 
@@ -660,7 +661,7 @@ void spi_unregister_master(struct spi_master *master)
 	list_del(&master->list);
 	mutex_unlock(&board_lock);
 
-	dummy = device_for_each_child(&master->dev, NULL, __unregister);
+	dummy = device_for_each_child(master->dev.parent, NULL, __unregister);
 	device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
-- 
Regards,

Laurent Pinchart


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d

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

end of thread, other threads:[~2011-12-16 17:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-28 13:23 [PATCH/RFC] spi: Fix device unregistration when unregistering the bus master Laurent Pinchart
     [not found] ` <1322486604-27808-1-git-send-email-laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
2011-12-02 12:14   ` Linus Walleij
     [not found]     ` <CACRpkdZf0pcdJyh2Th=KbrcCa=D-aqCiMCNoCmPGQo3iFZpsdg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-06 16:22       ` Laurent Pinchart
     [not found]         ` <201112061722.48910.laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
2011-12-06 19:32           ` Linus Walleij
     [not found]             ` <CACRpkda685p+fe_P5Ww=4Qtup6qmCe_oqiwTqN+KAaAktPNKFw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-12  0:15               ` [PATCH v2] " Laurent Pinchart
     [not found]                 ` <1323648906-24863-1-git-send-email-laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
2011-12-13 22:10                   ` Linus Walleij
2011-12-13 23:45                   ` Grant Likely
     [not found]                     ` <20111213234520.GA24922-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2011-12-16 16:52                       ` Laurent Pinchart
     [not found]                         ` <201112161752.05318.laurent.pinchart-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>
2011-12-16 16:59                           ` Grant Likely
     [not found]                             ` <CACxGe6tYCNdfj7BeHt-801M01=3Lk4LVfR91z6Pyfiq+LqXiJA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-12-16 17:18                               ` Laurent Pinchart

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