[PATCH v10 04/41] component: unlocked versions of add and del

Ramalingam C ramalingam.c at intel.com
Sun Jan 20 09:46:18 UTC 2019


We need unlocked versions of component add and del, so that we can
remove a component from the master unbind of the same driver.

Example: In I915 we have a component master which interfaces to
mei_hdcp, where as we have a component for the sound driver interface.
if mei_hdcp is down in master unbind of I915 we deregister the I915
from drm. Hence we need to remove the audio component associated to
this dev from the start of the master_unbind, well before device is
destroyed.

Signed-off-by: Ramalingam C <ramalingam.c at intel.com>
---
 drivers/base/component.c  | 31 ++++++++++++++++++++++++-------
 include/linux/component.h |  2 ++
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/base/component.c b/drivers/base/component.c
index 1b8bb07c0ec7..485899f6fb2b 100644
--- a/drivers/base/component.c
+++ b/drivers/base/component.c
@@ -567,11 +567,12 @@ int component_bind_all(struct device *master_dev, void *data)
 }
 EXPORT_SYMBOL_GPL(component_bind_all);
 
-int component_add(struct device *dev, const struct component_ops *ops)
+int component_add_unlocked(struct device *dev, const struct component_ops *ops)
 {
 	struct component *component;
 	int ret;
 
+	WARN_ON(!mutex_is_locked(&component_mutex));
 	component = kzalloc(sizeof(*component), GFP_KERNEL);
 	if (!component)
 		return -ENOMEM;
@@ -581,7 +582,6 @@ int component_add(struct device *dev, const struct component_ops *ops)
 
 	dev_dbg(dev, "adding component (ops %ps)\n", ops);
 
-	mutex_lock(&component_mutex);
 	list_add_tail(&component->node, &component_list);
 
 	ret = try_to_bring_up_masters(component);
@@ -592,17 +592,28 @@ int component_add(struct device *dev, const struct component_ops *ops)
 
 		kfree(component);
 	}
-	mutex_unlock(&component_mutex);
 
 	return ret < 0 ? ret : 0;
 }
+EXPORT_SYMBOL_GPL(component_add_unlocked);
+
+int component_add(struct device *dev, const struct component_ops *ops)
+{
+	int ret;
+
+	mutex_lock(&component_mutex);
+	ret = component_add_unlocked(dev, ops);
+	mutex_unlock(&component_mutex);
+
+	return ret;
+}
 EXPORT_SYMBOL_GPL(component_add);
 
-void component_del(struct device *dev, const struct component_ops *ops)
+void component_del_unlocked(struct device *dev, const struct component_ops *ops)
 {
 	struct component *c, *component = NULL;
 
-	mutex_lock(&component_mutex);
+	WARN_ON(!mutex_is_locked(&component_mutex));
 	list_for_each_entry(c, &component_list, node)
 		if (c->dev == dev && c->ops == ops) {
 			list_del(&c->node);
@@ -615,11 +626,17 @@ void component_del(struct device *dev, const struct component_ops *ops)
 		remove_component(component->master, component);
 	}
 
-	mutex_unlock(&component_mutex);
-
 	WARN_ON(!component);
 	kfree(component);
 }
+EXPORT_SYMBOL_GPL(component_del_unlocked);
+
+void component_del(struct device *dev, const struct component_ops *ops)
+{
+	mutex_lock(&component_mutex);
+	component_del_unlocked(dev, ops);
+	mutex_unlock(&component_mutex);
+}
 EXPORT_SYMBOL_GPL(component_del);
 
 MODULE_LICENSE("GPL v2");
diff --git a/include/linux/component.h b/include/linux/component.h
index 3f6b420a58f8..5cc2c54a2ebf 100644
--- a/include/linux/component.h
+++ b/include/linux/component.h
@@ -13,7 +13,9 @@ struct component_ops {
 		       void *master_data);
 };
 
+int component_add_unlocked(struct device *, const struct component_ops *);
 int component_add(struct device *, const struct component_ops *);
+void component_del_unlocked(struct device *, const struct component_ops *);
 void component_del(struct device *, const struct component_ops *);
 
 int component_bind_all(struct device *master, void *master_data);
-- 
2.7.4



More information about the Intel-gfx-trybot mailing list