Преглед изворни кода

intel_th: Fix a deadlock in modprobing

Driver initialization tries to request a hub (GTH) driver module from
its probe callback, resulting in a deadlock.

This patch solves the problem by adding a deferred work for requesting
the hub module.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: <stable@vger.kernel.org> # 4.4.x-
Alexander Shishkin пре 9 година
родитељ
комит
a36aa80f3c
2 измењених фајлова са 37 додато и 1 уклоњено
  1. 34 1
      drivers/hwtracing/intel_th/core.c
  2. 3 0
      drivers/hwtracing/intel_th/intel_th.h

+ 34 - 1
drivers/hwtracing/intel_th/core.c

@@ -465,6 +465,38 @@ static struct intel_th_subdevice {
 	},
 	},
 };
 };
 
 
+#ifdef CONFIG_MODULES
+static void __intel_th_request_hub_module(struct work_struct *work)
+{
+	struct intel_th *th = container_of(work, struct intel_th,
+					   request_module_work);
+
+	request_module("intel_th_%s", th->hub->name);
+}
+
+static int intel_th_request_hub_module(struct intel_th *th)
+{
+	INIT_WORK(&th->request_module_work, __intel_th_request_hub_module);
+	schedule_work(&th->request_module_work);
+
+	return 0;
+}
+
+static void intel_th_request_hub_module_flush(struct intel_th *th)
+{
+	flush_work(&th->request_module_work);
+}
+#else
+static inline int intel_th_request_hub_module(struct intel_th *th)
+{
+	return -EINVAL;
+}
+
+static inline void intel_th_request_hub_module_flush(struct intel_th *th)
+{
+}
+#endif /* CONFIG_MODULES */
+
 static int intel_th_populate(struct intel_th *th, struct resource *devres,
 static int intel_th_populate(struct intel_th *th, struct resource *devres,
 			     unsigned int ndevres, int irq)
 			     unsigned int ndevres, int irq)
 {
 {
@@ -535,7 +567,7 @@ static int intel_th_populate(struct intel_th *th, struct resource *devres,
 		/* need switch driver to be loaded to enumerate the rest */
 		/* need switch driver to be loaded to enumerate the rest */
 		if (subdev->type == INTEL_TH_SWITCH && !req) {
 		if (subdev->type == INTEL_TH_SWITCH && !req) {
 			th->hub = thdev;
 			th->hub = thdev;
-			err = request_module("intel_th_%s", subdev->name);
+			err = intel_th_request_hub_module(th);
 			if (!err)
 			if (!err)
 				req++;
 				req++;
 		}
 		}
@@ -652,6 +684,7 @@ void intel_th_free(struct intel_th *th)
 {
 {
 	int i;
 	int i;
 
 
+	intel_th_request_hub_module_flush(th);
 	for (i = 0; i < TH_SUBDEVICE_MAX; i++)
 	for (i = 0; i < TH_SUBDEVICE_MAX; i++)
 		if (th->thdev[i] != th->hub)
 		if (th->thdev[i] != th->hub)
 			intel_th_device_remove(th->thdev[i]);
 			intel_th_device_remove(th->thdev[i]);

+ 3 - 0
drivers/hwtracing/intel_th/intel_th.h

@@ -205,6 +205,9 @@ struct intel_th {
 
 
 	int			id;
 	int			id;
 	int			major;
 	int			major;
+#ifdef CONFIG_MODULES
+	struct work_struct	request_module_work;
+#endif /* CONFIG_MODULES */
 #ifdef CONFIG_INTEL_TH_DEBUG
 #ifdef CONFIG_INTEL_TH_DEBUG
 	struct dentry		*dbg;
 	struct dentry		*dbg;
 #endif
 #endif