[PATCH] work around deadlock in add_intf

From: Martin Waitz (tali@admingilde.org)
Date: Thu Jan 16 2003 - 16:52:18 EST


hi :)

the note for cpufreq sysfs support regarding locking in add_intf
has bitten me, too

i don't have a really good idea how to change the locking
so that it just works, so i wrote a workaround

the following patch allows to add interfaces again for me,
it just deferres the actual device additions:

--- src/linux-2.5/drivers/base/intf.c Mon Jan 13 09:49:02 2003
+++ src/linux-rc/drivers/base/intf.c Thu Jan 16 11:13:19 2003
@@ -132,6 +132,22 @@
 
 
 /**
+ * delayed_add - version of add() called via schedule_work
+ * @_data: pointer to arguments
+ */
+static void delayed_add(void *_data)
+{
+ struct {
+ struct device_interface *intf;
+ struct device *dev;
+ struct work_struct work;
+ } *data = _data;
+
+ add(data->intf, data->dev);
+ kfree(data);
+}
+
+/**
  * add_intf - add class's devices to interface.
  * @intf: interface.
  *
@@ -142,12 +158,24 @@
  */
 static void add_intf(struct device_interface * intf)
 {
+ struct {
+ struct device_interface *intf;
+ struct device *dev;
+ struct work_struct work;
+ } *data;
        struct device_class * cls = intf->devclass;
        struct list_head * entry;
 
        down_write(&cls->subsys.rwsem);
- list_for_each(entry,&cls->devices.list)
- add(intf,to_dev(entry));
+ list_for_each(entry,&cls->devices.list) {
+ /* add will lock subsys.rwsem via interface_add_data, */
+ /* do it after lock is released */
+ data = kmalloc(sizeof(*data), GFP_KERNEL);
+ INIT_WORK(&data->work, delayed_add, data);
+ data->intf = intf;
+ data->dev = to_dev(entry);
+ schedule_work(&data->work);
+ }
        up_write(&cls->subsys.rwsem);
 }
 

-- 
CU,		  / Friedrich-Alexander University Erlangen, Germany
Martin Waitz	//  [Tali on IRCnet]  [tali.home.pages.de] _________
______________/// - - - - - - - - - - - - - - - - - - - - ///
dies ist eine manuell generierte mail, sie beinhaltet    //
tippfehler und ist auch ohne grossbuchstaben gueltig.   /
			    -
Wer bereit ist, grundlegende Freiheiten aufzugeben, um sich 
kurzfristige Sicherheit zu verschaffen, der hat weder Freiheit 
noch Sicherheit verdient.            Benjamin Franklin (1706 - 1790)


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Jan 23 2003 - 22:00:14 EST