Skip to contentSkip to conversation

spi: free children in spi_unregister_master, not siblings

PATCH In review David Lamparter 2 participants 5 messages Aug 30, 2010 – Sep 1, 2010 4 messages not in the archive SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: free children in spi_unregister_master, not siblings

introduced by 49dce689ad4ef0fd1f970ef762168e4bd46f69a3 and bad-fixed by 350d0076c5763ca2b88ca05e3889bfa7c1905f21, spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

fix it to unregister children.

Cc Tony Jones <[email protected]>
Cc Atsushi Nemoto <[email protected]>
Cc David Brownell <david-b-yBeKhBN/[email protected]>

---

"siblings" were usb endpoint devices in my case, causing a very nice *boom* when the usb code tried to unregister them after they were gone already because of spi_unregister_master. went looking for a bug in my code for 20 hours...

patch is against 2.6.35.4 but there shouldn't be much change in this file.

 drivers/spi/spi.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/spi/spi.c +3 -6
index b3a1f92..144393c 100644
@@ -546,11 +546,9 @@ done:
 EXPORT_SYMBOL_GPL(spi_register_master);
 
 
-static int __unregister(struct device *dev, void *master_dev)
+static int __unregister(struct device *dev, void *null)
 {
-	/* note: before about 2.6.14-rc1 this would corrupt memory: */
-	if (dev != master_dev)
-		spi_unregister_device(to_spi_device(dev));
+	spi_unregister_device(to_spi_device(dev));
 	return 0;
 }
 
@@ -568,8 +566,7 @@ void spi_unregister_master(struct spi_master *master)
 {
 	int dummy;
 
-	dummy = device_for_each_child(master->dev.parent, &master->dev,
-					__unregister);
+	dummy = device_for_each_child(master->dev, NULL, _unregister);
 	device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d

A message that is not in the archive (sent off-list or not yet received): 20100830095837.GA2404529-sd4rSCkhOesKVZNVnti56SRbHCANfdcW@public.gmane.org

#2 lore raw

introduced by 49dce689ad4ef0fd1f970ef762168e4bd46f69a3 and bad-fixed by 350d0076c5763ca2b88ca05e3889bfa7c1905f21, spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

fix it to unregister children.

Cc Tony Jones <[email protected]>
Cc Atsushi Nemoto <[email protected]>
Cc David Brownell <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>

---

Hi Grant,

please see attached patch :)

(reply from David Brownell went off-list because I accidentally Cc'ed an old e-mail address of him. moving this to on-list thread.)

-David L.

Quoted 8 lines · David Lamparter

"siblings" were usb endpoint devices in my case, causing a very nice *boom* when the usb code tried to unregister them after they were gone already because of spi_unregister_master. went looking for a bug in my code for 20 hours...

patch is against 2.6.35.4 but there shouldn't be much change in this file.

Quoted 7 lines · David Brownell

Bug since 2007? OUch!

At a real quick review, it looked right; but
I couldn't test.

Please send this patch also to Grant Likely.

 drivers/spi/spi.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/spi/spi.c +3 -6
index b3a1f92..144393c 100644
@@ -546,11 +546,9 @@ done:
 EXPORT_SYMBOL_GPL(spi_register_master);
 
 
-static int __unregister(struct device *dev, void *master_dev)
+static int __unregister(struct device *dev, void *null)
 {
-	/* note: before about 2.6.14-rc1 this would corrupt memory: */
-	if (dev != master_dev)
-		spi_unregister_device(to_spi_device(dev));
+	spi_unregister_device(to_spi_device(dev));
 	return 0;
 }
 
@@ -568,8 +566,7 @@ void spi_unregister_master(struct spi_master *master)
 {
 	int dummy;
 
-	dummy = device_for_each_child(master->dev.parent, &master->dev,
-					__unregister);
+	dummy = device_for_each_child(master->dev, NULL, _unregister);
 	device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd

A message that is not in the archive (sent off-list or not yet received): 20100830213949.GB2413339-sd4rSCkhOesKVZNVnti56SRbHCANfdcW@public.gmane.org

#4 lore raw

introduced by 49dce689ad4ef0fd1f970ef762168e4bd46f69a3 and bad-fixed by 350d0076c5763ca2b88ca05e3889bfa7c1905f21, spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

fix it to unregister children.

Cc Tony Jones <[email protected]>
Cc Atsushi Nemoto <[email protected]>
Cc David Brownell <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>

---

Great, I'm sending around a wrong version which doesn't even compile...

Review

Quoted 1 line
(quoted diff) +1 -0
+	dummy = device_for_each_child(master->dev, NULL, _unregister);

needs to be

Review

Quoted 1 line
(quoted diff) +1 -0
+	dummy = device_for_each_child(&master->dev, NULL, __unregister);

really.

Sorry,
-David

Quoted 15 lines · David Lamparter

Hi Grant,

please see attached patch :)

(reply from David Brownell went off-list because I accidentally Cc'ed an old e-mail address of him. moving this to on-list thread.)

-David L.

Quoted 5 lines · David Lamparter

"siblings" were usb endpoint devices in my case, causing a very nice *boom* when the usb code tried to unregister them after they were gone already because of spi_unregister_master. went looking for a bug in my code for 20 hours...

Quoted 11 lines
Quoted 3 lines

patch is against 2.6.35.4 but there shouldn't be much change in this file.

Quoted 7 lines · David Brownell

Bug since 2007? OUch!

At a real quick review, it looked right; but
I couldn't test.

Please send this patch also to Grant Likely.

 drivers/spi/spi.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/spi/spi.c +3 -6
index b3a1f92..1a61fa8 100644
@@ -546,11 +546,9 @@ done:
 EXPORT_SYMBOL_GPL(spi_register_master);
 
 
-static int __unregister(struct device *dev, void *master_dev)
+static int __unregister(struct device *dev, void *null)
 {
-	/* note: before about 2.6.14-rc1 this would corrupt memory: */
-	if (dev != master_dev)
-		spi_unregister_device(to_spi_device(dev));
+	spi_unregister_device(to_spi_device(dev));
 	return 0;
 }
 
@@ -568,8 +566,7 @@ void spi_unregister_master(struct spi_master *master)
 {
 	int dummy;
 
-	dummy = device_for_each_child(master->dev.parent, &master->dev,
-					__unregister);
+	dummy = device_for_each_child(&master->dev, NULL, __unregister);
 	device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd

A message that is not in the archive (sent off-list or not yet received): 20100830215417.GC2413339-sd4rSCkhOesKVZNVnti56SRbHCANfdcW@public.gmane.org

#6 lore raw
Quoted 4 lines · David Lamparter

introduced by 49dce689ad4ef0fd1f970ef762168e4bd46f69a3 and bad-fixed by 350d0076c5763ca2b88ca05e3889bfa7c1905f21, spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

Obviously correct. Applied, and I'll push it out after some testing.

BTW, you should be friendly to reviewers when quoting sha1 commit ids. You should also quote the patch title so that readers don't need to context-switch to git or the web to figure out what the patches actually are. This is how I fixed it up in the commit:

introduced by 49dce689 ("spi doesn't need class_device") and bad-fixed by 350d0076 ("spi: fix double-free on spi_unregister_master"), spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

g.

Quoted 85 lines

fix it to unregister children.

Cc Tony Jones <[email protected]>
Cc Atsushi Nemoto <[email protected]>
Cc David Brownell <[email protected]>
Cc Grant Likely <grant.likely-s3s/[email protected]>

---

Great, I'm sending around a wrong version which doesn't even compile...

Review

Quoted 1 line
(quoted diff) +1 -0
+	dummy = device_for_each_child(master->dev, NULL, _unregister);

needs to be

drivers/spi/spi.c void spi_unregister_master(struct spi_master *master) · line 569

Quoted 1 line
drivers/spi/spi.c +1 -0
+	dummy = device_for_each_child(&master->dev, NULL, __unregister);

really.

Sorry,
-David

Quoted 15 lines · David Lamparter

Hi Grant,

please see attached patch :)

(reply from David Brownell went off-list because I accidentally Cc'ed an old e-mail address of him. moving this to on-list thread.)

-David L.

Quoted 5 lines · David Lamparter

"siblings" were usb endpoint devices in my case, causing a very nice *boom* when the usb code tried to unregister them after they were gone already because of spi_unregister_master. went looking for a bug in my code for 20 hours...

Quoted 11 lines
Quoted 3 lines

patch is against 2.6.35.4 but there shouldn't be much change in this file.

Quoted 7 lines · David Brownell

Bug since 2007? OUch!

At a real quick review, it looked right; but
I couldn't test.

Please send this patch also to Grant Likely.

 drivers/spi/spi.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
drivers/spi/spi.c +3 -6
index b3a1f92..1a61fa8 100644
@@ -546,11 +546,9 @@ done:
 EXPORT_SYMBOL_GPL(spi_register_master);
 
 
-static int __unregister(struct device *dev, void *master_dev)
+static int __unregister(struct device *dev, void *null)
 {
-	/* note: before about 2.6.14-rc1 this would corrupt memory: */
-	if (dev != master_dev)
-		spi_unregister_device(to_spi_device(dev));
+	spi_unregister_device(to_spi_device(dev));
 	return 0;
 }
 
@@ -568,8 +566,7 @@ void spi_unregister_master(struct spi_master *master)
 {
 	int dummy;
 
-	dummy = device_for_each_child(master->dev.parent, &master->dev,
-					__unregister);
+	dummy = device_for_each_child(&master->dev, NULL, __unregister);
 	device_unregister(&master->dev);
 }
 EXPORT_SYMBOL_GPL(spi_unregister_master);
Signature · 1 line
1.7.1

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd

A message that is not in the archive (sent off-list or not yet received): 20100901152412.GC13421-MrY2KI0G/OVr83L8+7iqerDks+cytr/[email protected]

#8 lore raw
Quoted 7 lines · Grant Likely
Quoted 4 lines · David Lamparter

introduced by 49dce689ad4ef0fd1f970ef762168e4bd46f69a3 and bad-fixed by 350d0076c5763ca2b88ca05e3889bfa7c1905f21, spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

Obviously correct. Applied, and I'll push it out after some testing.

Thanks!

Quoted 9 lines

BTW, you should be friendly to reviewers when quoting sha1 commit ids. You should also quote the patch title so that readers don't need to context-switch to git or the web to figure out what the patches actually are. This is how I fixed it up in the commit:

introduced by 49dce689 ("spi doesn't need class_device") and bad-fixed by 350d0076 ("spi: fix double-free on spi_unregister_master"), spi_unregister_master would previously device_unregister all of the spi master's siblings (instead of its children). hilarity ensues.

Ah. I oriented on 350d0076's commit message ("spi: fix double-free on spi_unregister_master") which did strike me as weird, but I didn't think. Will remember to do better in the future.

-David

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd