linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free()
@ 2014-04-21 12:02 Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 1/9] extcon: Add extcon_dev_allocate/free() to control the memory of extcon device Chanwoo Choi
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

Thi patchset add devm_extcon_dev_allocate/free() for the resource management
of extcon device. And devm_extcon_dev_allocate() handles all of supported cables.

Changes from v1:
- Rebase it on latest extcon-next branch

Chanwoo Choi (9):
  extcon: Add extcon_dev_allocate/free() to control the memory of extcon device
  extcon: Add devm_extcon_dev_allocate/free to manage the resource of extcon device
  extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev
  extcon: max77693: Use devm_extcon_dev_allocate for extcon_dev
  extcon: max14577: Use devm_extcon_dev_allocate for extcon_dev
  extcon: palmas: Use devm_extcon_dev_allocate for extcon_dev
  extcon: arizona: Use devm_extcon_dev_allocate for extcon_dev
  extcon: adc-jack: Use devm_extcon_dev_allocate for extcon_dev
  extcon: gpio: Use devm_extcon_dev_allocate for extcon_dev

 drivers/extcon/extcon-adc-jack.c |  21 +--
 drivers/extcon/extcon-arizona.c  |  31 ++--
 drivers/extcon/extcon-class.c    | 341 ++++++++++++++++++++++++---------------
 drivers/extcon/extcon-gpio.c     |  23 ++-
 drivers/extcon/extcon-max14577.c |   5 +-
 drivers/extcon/extcon-max77693.c |   7 +-
 drivers/extcon/extcon-max8997.c  |   5 +-
 drivers/extcon/extcon-palmas.c   |  35 ++--
 include/linux/extcon.h           |  26 +++
 include/linux/mfd/palmas.h       |   2 +-
 10 files changed, 308 insertions(+), 188 deletions(-)

-- 
1.8.0


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

* [PATCHv2 1/9] extcon: Add extcon_dev_allocate/free() to control the memory of extcon device
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 2/9] extcon: Add devm_extcon_dev_allocate/free to manage the resource " Chanwoo Choi
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch add APIs to control the extcon device on extcon provider driver.
The extcon_dev_allocate() allocates the memory of extcon device and initializes
supported cables. And then extcon_dev_free() decrement the reference of the
device of extcon device and free the memory of the extcon device. This APIs
must need to implement devm_extcon_dev_allocate()/free() APIs.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-class.c | 295 +++++++++++++++++++++++-------------------
 include/linux/extcon.h        |  15 +++
 2 files changed, 177 insertions(+), 133 deletions(-)

diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index f6df689..3e485bc 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -558,6 +558,9 @@ static int create_extcon_class(void)
 
 static void extcon_dev_release(struct device *dev)
 {
+	struct extcon_dev *edev = dev_to_extcon_dev(dev);
+
+	kfree(edev);
 }
 
 static const char *muex_name = "mutually_exclusive";
@@ -576,7 +579,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
  */
 int extcon_dev_register(struct extcon_dev *edev)
 {
-	int ret, index = 0;
+	int ret;
 
 	if (!extcon_class) {
 		ret = create_extcon_class();
@@ -584,80 +587,150 @@ int extcon_dev_register(struct extcon_dev *edev)
 			return ret;
 	}
 
-	if (edev->supported_cable) {
-		/* Get size of array */
-		for (index = 0; edev->supported_cable[index]; index++)
-			;
-		edev->max_supported = index;
-	} else {
-		edev->max_supported = 0;
+	edev->name = edev->name ? edev->name : dev_name(edev->dev.parent);
+	if (IS_ERR_OR_NULL(edev->name)) {
+		dev_err(&edev->dev, "extcon device name is null\n");
+		return -EINVAL;
 	}
+	dev_set_name(&edev->dev, "%s", edev->name);
 
-	if (index > SUPPORTED_CABLE_MAX) {
-		dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");
-		return -EINVAL;
+	ret = device_add(&edev->dev);
+	if (ret) {
+		put_device(&edev->dev);
+		return ret;
 	}
+#if defined(CONFIG_ANDROID)
+	if (switch_class)
+		ret = class_compat_create_link(switch_class, &edev->dev, NULL);
+#endif /* CONFIG_ANDROID */
 
-	edev->dev.class = extcon_class;
-	edev->dev.release = extcon_dev_release;
+	RAW_INIT_NOTIFIER_HEAD(&edev->nh);
 
-	edev->name = edev->name ? edev->name : dev_name(edev->dev.parent);
-	if (IS_ERR_OR_NULL(edev->name)) {
-		dev_err(&edev->dev,
-			"extcon device name is null\n");
-		return -EINVAL;
+	dev_set_drvdata(&edev->dev, edev);
+	edev->state = 0;
+
+	mutex_lock(&extcon_dev_list_lock);
+	list_add(&edev->entry, &extcon_dev_list);
+	mutex_unlock(&extcon_dev_list_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(extcon_dev_register);
+
+/**
+ * extcon_dev_unregister() - Unregister the extcon device.
+ * @edev:	the extcon device instance to be unregistered.
+ */
+void extcon_dev_unregister(struct extcon_dev *edev)
+{
+	mutex_lock(&extcon_dev_list_lock);
+	list_del(&edev->entry);
+	mutex_unlock(&extcon_dev_list_lock);
+
+	if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
+		dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
+				dev_name(&edev->dev));
+		return;
 	}
-	dev_set_name(&edev->dev, "%s", edev->name);
 
-	if (edev->max_supported) {
-		char buf[10];
-		char *str;
-		struct extcon_cable *cable;
+	device_unregister(&edev->dev);
 
-		edev->cables = kzalloc(sizeof(struct extcon_cable) *
-				       edev->max_supported, GFP_KERNEL);
-		if (!edev->cables) {
+#if defined(CONFIG_ANDROID)
+	if (switch_class)
+		class_compat_remove_link(switch_class, &edev->dev, NULL);
+#endif
+}
+EXPORT_SYMBOL_GPL(extcon_dev_unregister);
+
+/*
+ * extcon_dev_allocate() - Allocate the memory of extcon device.
+ * @supported_cable:	Array of supported cable names ending with NULL.
+ *			If supported_cable is NULL, cable name related APIs
+ *			are disabled.
+ *
+ * This function allocates the memory for extcon device without allocating
+ * memory in each extcon provider driver and initialize default setting for
+ * extcon device.
+ *
+ * Return the pointer of extcon device if success or ERR_PTR(err) if fail
+ */
+struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
+{
+	struct extcon_dev *edev;
+	int index, ret, count = 0;
+
+	edev = kzalloc(sizeof(*edev), GFP_KERNEL);
+	if (!edev) {
+		pr_err("Failed to allocate the memory for extcon device\n");
+		return ERR_PTR(-ENOMEM);
+	}
+
+	edev->max_supported = 0;
+	edev->supported_cable = supported_cable;
+	if (edev->supported_cable) {
+		for (count = 0; edev->supported_cable[count]; count++)
+			;
+		edev->max_supported = count;
+		if (count > SUPPORTED_CABLE_MAX) {
+			pr_err("Exceed max number of supported cables\n");
 			ret = -ENOMEM;
-			goto err_sysfs_alloc;
+			goto err;
 		}
-		for (index = 0; index < edev->max_supported; index++) {
-			cable = &edev->cables[index];
+	}
 
-			snprintf(buf, 10, "cable.%d", index);
-			str = kzalloc(sizeof(char) * (strlen(buf) + 1),
-				      GFP_KERNEL);
-			if (!str) {
-				for (index--; index >= 0; index--) {
-					cable = &edev->cables[index];
-					kfree(cable->attr_g.name);
-				}
-				ret = -ENOMEM;
+	edev->dev.class = extcon_class;
+	edev->dev.release = extcon_dev_release;
+	device_initialize(&edev->dev);
+	spin_lock_init(&edev->lock);
+
+	if (!edev->max_supported)
+		return 0;
+
+	edev->cables = kzalloc(sizeof(struct extcon_cable) *
+			       edev->max_supported, GFP_KERNEL);
+	if (!edev->cables) {
+		ret = -ENOMEM;
+		goto err;
+	}
 
-				goto err_alloc_cables;
+	for (index = 0; index < edev->max_supported; index++) {
+		struct extcon_cable *cable = &edev->cables[index];
+		char buf[10];
+		char *str;
+
+		snprintf(buf, 10, "cable.%d", index);
+		str = kzalloc(sizeof(char) * (strlen(buf) + 1),
+			      GFP_KERNEL);
+		if (!str) {
+			for (index--; index >= 0; index--) {
+				cable = &edev->cables[index];
+				kfree(cable->attr_g.name);
 			}
-			strcpy(str, buf);
-
-			cable->edev = edev;
-			cable->cable_index = index;
-			cable->attrs[0] = &cable->attr_name.attr;
-			cable->attrs[1] = &cable->attr_state.attr;
-			cable->attrs[2] = NULL;
-			cable->attr_g.name = str;
-			cable->attr_g.attrs = cable->attrs;
-
-			sysfs_attr_init(&cable->attr_name.attr);
-			cable->attr_name.attr.name = "name";
-			cable->attr_name.attr.mode = 0444;
-			cable->attr_name.show = cable_name_show;
-
-			sysfs_attr_init(&cable->attr_state.attr);
-			cable->attr_state.attr.name = "state";
-			cable->attr_state.attr.mode = 0444;
-			cable->attr_state.show = cable_state_show;
+			ret = -ENOMEM;
+			goto err_alloc_cables;
 		}
+		strcpy(str, buf);
+
+		cable->edev = edev;
+		cable->cable_index = index;
+		cable->attrs[0] = &cable->attr_name.attr;
+		cable->attrs[1] = &cable->attr_state.attr;
+		cable->attrs[2] = NULL;
+		cable->attr_g.name = str;
+		cable->attr_g.attrs = cable->attrs;
+
+		sysfs_attr_init(&cable->attr_name.attr);
+		cable->attr_name.attr.name = "name";
+		cable->attr_name.attr.mode = 0444;
+		cable->attr_name.show = cable_name_show;
+
+		sysfs_attr_init(&cable->attr_state.attr);
+		cable->attr_state.attr.name = "state";
+		cable->attr_state.attr.mode = 0444;
+		cable->attr_state.show = cable_state_show;
 	}
 
-	if (edev->max_supported && edev->mutually_exclusive) {
+	if (edev->mutually_exclusive) {
 		char buf[80];
 		char *name;
 
@@ -703,59 +776,32 @@ int extcon_dev_register(struct extcon_dev *edev)
 		}
 		edev->attr_g_muex.name = muex_name;
 		edev->attr_g_muex.attrs = edev->attrs_muex;
-
 	}
 
-	if (edev->max_supported) {
-		edev->extcon_dev_type.groups =
-			kzalloc(sizeof(struct attribute_group *) *
-				(edev->max_supported + 2), GFP_KERNEL);
-		if (!edev->extcon_dev_type.groups) {
-			ret = -ENOMEM;
-			goto err_alloc_groups;
-		}
-
-		edev->extcon_dev_type.name = dev_name(&edev->dev);
-		edev->extcon_dev_type.release = dummy_sysfs_dev_release;
-
-		for (index = 0; index < edev->max_supported; index++)
-			edev->extcon_dev_type.groups[index] =
-				&edev->cables[index].attr_g;
-		if (edev->mutually_exclusive)
-			edev->extcon_dev_type.groups[index] =
-				&edev->attr_g_muex;
-
-		edev->dev.type = &edev->extcon_dev_type;
+	edev->extcon_dev_type.groups =
+		kzalloc(sizeof(struct attribute_group *) *
+			(edev->max_supported + 2), GFP_KERNEL);
+	if (!edev->extcon_dev_type.groups) {
+		ret = -ENOMEM;
+		goto err_alloc_groups;
 	}
 
-	ret = device_register(&edev->dev);
-	if (ret) {
-		put_device(&edev->dev);
-		goto err_dev;
-	}
-#if defined(CONFIG_ANDROID)
-	if (switch_class)
-		ret = class_compat_create_link(switch_class, &edev->dev, NULL);
-#endif /* CONFIG_ANDROID */
-
-	spin_lock_init(&edev->lock);
-
-	RAW_INIT_NOTIFIER_HEAD(&edev->nh);
+	edev->extcon_dev_type.name = dev_name(&edev->dev);
+	edev->extcon_dev_type.release = dummy_sysfs_dev_release;
 
-	dev_set_drvdata(&edev->dev, edev);
-	edev->state = 0;
+	for (index = 0; index < edev->max_supported; index++)
+		edev->extcon_dev_type.groups[index] =
+			&edev->cables[index].attr_g;
+	if (edev->mutually_exclusive)
+		edev->extcon_dev_type.groups[index] =
+			&edev->attr_g_muex;
 
-	mutex_lock(&extcon_dev_list_lock);
-	list_add(&edev->entry, &extcon_dev_list);
-	mutex_unlock(&extcon_dev_list_lock);
+	edev->dev.type = &edev->extcon_dev_type;
 
-	return 0;
+	return edev;
 
-err_dev:
-	if (edev->max_supported)
-		kfree(edev->extcon_dev_type.groups);
 err_alloc_groups:
-	if (edev->max_supported && edev->mutually_exclusive) {
+	if (edev->mutually_exclusive) {
 		for (index = 0; edev->mutually_exclusive[index]; index++)
 			kfree(edev->d_attrs_muex[index].attr.name);
 		kfree(edev->d_attrs_muex);
@@ -765,36 +811,22 @@ err_muex:
 	for (index = 0; index < edev->max_supported; index++)
 		kfree(edev->cables[index].attr_g.name);
 err_alloc_cables:
-	if (edev->max_supported)
-		kfree(edev->cables);
-err_sysfs_alloc:
-	return ret;
+	kfree(edev->cables);
+err:
+	kfree(edev);
+
+	return ERR_PTR(ret);
 }
-EXPORT_SYMBOL_GPL(extcon_dev_register);
+EXPORT_SYMBOL_GPL(extcon_dev_allocate);
 
-/**
- * extcon_dev_unregister() - Unregister the extcon device.
- * @edev:	the extcon device instance to be unregistered.
- *
- * Note that this does not call kfree(edev) because edev was not allocated
- * by this class.
+/*
+ * extcon_dev_free() - Free the memory of extcon device.
+ * @edev:	the extcon device to free
  */
-void extcon_dev_unregister(struct extcon_dev *edev)
+void extcon_dev_free(struct extcon_dev *edev)
 {
 	int index;
 
-	mutex_lock(&extcon_dev_list_lock);
-	list_del(&edev->entry);
-	mutex_unlock(&extcon_dev_list_lock);
-
-	if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
-		dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
-				dev_name(&edev->dev));
-		return;
-	}
-
-	device_unregister(&edev->dev);
-
 	if (edev->mutually_exclusive && edev->max_supported) {
 		for (index = 0; edev->mutually_exclusive[index];
 				index++)
@@ -811,13 +843,10 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 		kfree(edev->cables);
 	}
 
-#if defined(CONFIG_ANDROID)
-	if (switch_class)
-		class_compat_remove_link(switch_class, &edev->dev, NULL);
-#endif
-	put_device(&edev->dev);
+	if (edev)
+		put_device(&edev->dev);
 }
-EXPORT_SYMBOL_GPL(extcon_dev_unregister);
+EXPORT_SYMBOL_GPL(extcon_dev_free);
 
 static void devm_extcon_dev_unreg(struct device *dev, void *res)
 {
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 85a8a5b..20587ee 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -179,6 +179,8 @@ struct extcon_specific_cable_nb {
 
 #if IS_ENABLED(CONFIG_EXTCON)
 
+#define dev_to_extcon_dev(d) container_of(d, struct extcon_dev, dev)
+
 /*
  * Following APIs are for notifiers or configurations.
  * Notifiers are the external port and connection devices.
@@ -250,6 +252,12 @@ extern int extcon_unregister_notifier(struct extcon_dev *edev,
 				      struct notifier_block *nb);
 
 /*
+ * Following APIs control the memory of extcon device.
+ */
+extern struct extcon_dev *extcon_dev_allocate(const char **cables);
+extern void extcon_dev_free(struct extcon_dev *edev);
+
+/*
  * Following API get the extcon device from devicetree.
  * This function use phandle of devicetree to get extcon device directly.
  */
@@ -353,5 +361,12 @@ static inline struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev,
 {
 	return ERR_PTR(-ENODEV);
 }
+
+static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
+{
+	return ERR_PTR(-ENOMEM);
+}
+
+static inline void extcon_dev_free(struct extcon_dev *edev) { }
 #endif /* CONFIG_EXTCON */
 #endif /* __LINUX_EXTCON_H__ */
-- 
1.8.0


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

* [PATCHv2 2/9] extcon: Add devm_extcon_dev_allocate/free to manage the resource of extcon device
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 1/9] extcon: Add extcon_dev_allocate/free() to control the memory of extcon device Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 3/9] extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev Chanwoo Choi
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch add device managed devm_extcon_dev_{allocate,free} to automatically
free the memory of extcon_dev structure without handling free operation.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-class.c | 46 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/extcon.h        | 11 +++++++++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index 3e485bc..677c502 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -848,6 +848,11 @@ void extcon_dev_free(struct extcon_dev *edev)
 }
 EXPORT_SYMBOL_GPL(extcon_dev_free);
 
+static void devm_extcon_dev_release(struct device *dev, void *res)
+{
+	extcon_dev_free(*(struct extcon_dev **)res);
+}
+
 static void devm_extcon_dev_unreg(struct device *dev, void *res)
 {
 	extcon_dev_unregister(*(struct extcon_dev **)res);
@@ -866,6 +871,47 @@ static int devm_extcon_dev_match(struct device *dev, void *res, void *data)
 }
 
 /**
+ * devm_extcon_dev_allocate - Allocate managed extcon device
+ * @dev:		device owning the extcon device being created
+ * @supported_cable:	Array of supported cable names ending with NULL.
+ *			If supported_cable is NULL, cable name related APIs
+ *			are disabled.
+ *
+ * This function manages automatically the memory of extcon device using device
+ * resource management and simplify the control of freeing the memory of extcon
+ * device.
+ *
+ * Returns the pointer memory of allocated extcon_dev if success or NULL if fail
+ */
+struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
+					    const char **supported_cable)
+{
+	struct extcon_dev **ptr, *edev;
+
+	ptr = devres_alloc(devm_extcon_dev_release, sizeof(*ptr), GFP_KERNEL);
+	if (!ptr)
+		return NULL;
+
+	edev = extcon_dev_allocate(supported_cable);
+	if (!IS_ERR(edev)) {
+		*ptr = edev;
+		devres_add(dev, ptr);
+	} else {
+		devres_free(ptr);
+	}
+
+	return edev;
+}
+EXPORT_SYMBOL_GPL(devm_extcon_dev_allocate);
+
+void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev)
+{
+	WARN_ON(devres_release(dev, devm_extcon_dev_release,
+			       devm_extcon_dev_match, edev));
+}
+EXPORT_SYMBOL_GPL(devm_extcon_dev_free);
+
+/**
  * devm_extcon_dev_register() - Resource-managed extcon_dev_register()
  * @dev:	device to allocate extcon device
  * @edev:	the new extcon device to register
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 20587ee..2bc66ca 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -254,6 +254,9 @@ extern int extcon_unregister_notifier(struct extcon_dev *edev,
 /*
  * Following APIs control the memory of extcon device.
  */
+extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
+						   const char **cables);
+extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
 extern struct extcon_dev *extcon_dev_allocate(const char **cables);
 extern void extcon_dev_free(struct extcon_dev *edev);
 
@@ -368,5 +371,13 @@ static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
 }
 
 static inline void extcon_dev_free(struct extcon_dev *edev) { }
+
+static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
+							  const char **cables)
+{
+	return ERR_PTR(-ENOMEM);
+}
+
+static inline void devm_extcon_dev_free(struct extcon_dev *edev) { }
 #endif /* CONFIG_EXTCON */
 #endif /* __LINUX_EXTCON_H__ */
-- 
1.8.0


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

* [PATCHv2 3/9] extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 1/9] extcon: Add extcon_dev_allocate/free() to control the memory of extcon device Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 2/9] extcon: Add devm_extcon_dev_allocate/free to manage the resource " Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-22  8:17   ` Krzysztof Kozlowski
  2014-04-21 12:02 ` [PATCHv2 4/9] extcon: max77693: " Chanwoo Choi
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-max8997.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 804a446..e2ee2f5 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -699,8 +699,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
 	}
 
 	/* External connector */
-	info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
-				  GFP_KERNEL);
+	info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable);
 	if (!info->edev) {
 		dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
 		ret = -ENOMEM;
@@ -708,7 +707,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
 	}
 	info->edev->name = DEV_NAME;
 	info->edev->dev.parent = &pdev->dev;
-	info->edev->supported_cable = max8997_extcon_cable;
+
 	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register extcon device\n");
-- 
1.8.0


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

* [PATCHv2 4/9] extcon: max77693: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
                   ` (2 preceding siblings ...)
  2014-04-21 12:02 ` [PATCHv2 3/9] extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-22  8:18   ` Krzysztof Kozlowski
  2014-04-21 12:02 ` [PATCHv2 5/9] extcon: max14577: " Chanwoo Choi
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-max77693.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index f0f18e2..2e15a24 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -1175,8 +1175,8 @@ static int max77693_muic_probe(struct platform_device *pdev)
 	}
 
 	/* Initialize extcon device */
-	info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
-				  GFP_KERNEL);
+	info->edev = devm_extcon_dev_allocate(&pdev->dev,
+					      max77693_extcon_cable);
 	if (!info->edev) {
 		dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
 		ret = -ENOMEM;
@@ -1184,14 +1184,13 @@ static int max77693_muic_probe(struct platform_device *pdev)
 	}
 	info->edev->name = DEV_NAME;
 	info->edev->dev.parent = &pdev->dev;
-	info->edev->supported_cable = max77693_extcon_cable;
+
 	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register extcon device\n");
 		goto err_irq;
 	}
 
-
 	/* Initialize MUIC register by using platform data or default data */
 	if (pdata && pdata->muic_data) {
 		init_data = pdata->muic_data->init_data;
-- 
1.8.0


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

* [PATCHv2 5/9] extcon: max14577: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
                   ` (3 preceding siblings ...)
  2014-04-21 12:02 ` [PATCHv2 4/9] extcon: max77693: " Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-22  8:18   ` Krzysztof Kozlowski
  2014-04-21 12:02 ` [PATCHv2 6/9] extcon: palmas: " Chanwoo Choi
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Cc: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-max14577.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index 7221b32..3d24dae 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -668,13 +668,14 @@ static int max14577_muic_probe(struct platform_device *pdev)
 	}
 
 	/* Initialize extcon device */
-	info->edev = devm_kzalloc(&pdev->dev, sizeof(*info->edev), GFP_KERNEL);
+	info->edev = devm_extcon_dev_allocate(&pdev->dev,
+					      max14577_extcon_cable);
 	if (!info->edev) {
 		dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
 		return -ENOMEM;
 	}
 	info->edev->name = DEV_NAME;
-	info->edev->supported_cable = max14577_extcon_cable;
+
 	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to register extcon device\n");
-- 
1.8.0


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

* [PATCHv2 6/9] extcon: palmas: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
                   ` (4 preceding siblings ...)
  2014-04-21 12:02 ` [PATCHv2 5/9] extcon: max14577: " Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-23 13:38   ` Lee Jones
                     ` (2 more replies)
  2014-04-21 12:02 ` [PATCHv2 7/9] extcon: arizona: " Chanwoo Choi
                   ` (2 subsequent siblings)
  8 siblings, 3 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi, Samuel Ortiz, Lee Jones

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Cc: Graeme Gregory <gg@slimlogic.co.uk>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Felipe Balbi <balbi@ti.com>
Cc: Samuel Ortiz <sameo@linux.intel.com>
Cc: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-palmas.c | 35 ++++++++++++++++++++---------------
 include/linux/mfd/palmas.h     |  2 +-
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 1a770e0..a9299ea 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -57,7 +57,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
 	if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
 		if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
 			palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
-			extcon_set_cable_state(&palmas_usb->edev, "USB", true);
+			extcon_set_cable_state(palmas_usb->edev, "USB", true);
 			dev_info(palmas_usb->dev, "USB cable is attached\n");
 		} else {
 			dev_dbg(palmas_usb->dev,
@@ -66,7 +66,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
 	} else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
 		if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
 			palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-			extcon_set_cable_state(&palmas_usb->edev, "USB", false);
+			extcon_set_cable_state(palmas_usb->edev, "USB", false);
 			dev_info(palmas_usb->dev, "USB cable is detached\n");
 		} else {
 			dev_dbg(palmas_usb->dev,
@@ -93,7 +93,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
 			PALMAS_USB_ID_INT_LATCH_CLR,
 			PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
 		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
-		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", true);
+		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
 		dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
 	} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
 				(id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
@@ -101,17 +101,17 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
 			PALMAS_USB_ID_INT_LATCH_CLR,
 			PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
 		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
+		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
 		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
 	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
 				(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
 		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
-		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
+		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
 		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
 	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
 				(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
 		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
-		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", true);
+		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
 		dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
 	}
 
@@ -187,15 +187,20 @@ static int palmas_usb_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, palmas_usb);
 
-	palmas_usb->edev.supported_cable = palmas_extcon_cable;
-	palmas_usb->edev.dev.parent = palmas_usb->dev;
-	palmas_usb->edev.name = kstrdup(node->name, GFP_KERNEL);
-	palmas_usb->edev.mutually_exclusive = mutually_exclusive;
+	palmas_usb->edev = devm_extcon_dev_allocate(&pdev->dev,
+						    palmas_extcon_cable);
+	if (!palmas_usb->edev) {
+		dev_err(&pdev->dev, "failed to allocate extcon device\n");
+		return -ENOMEM;
+	}
+	palmas_usb->edev->name = kstrdup(node->name, GFP_KERNEL);
+	palmas_usb->edev->dev.parent = palmas_usb->dev;
+	palmas_usb->edev->mutually_exclusive = mutually_exclusive;
 
-	status = devm_extcon_dev_register(&pdev->dev, &palmas_usb->edev);
+	status = devm_extcon_dev_register(&pdev->dev, palmas_usb->edev);
 	if (status) {
 		dev_err(&pdev->dev, "failed to register extcon device\n");
-		kfree(palmas_usb->edev.name);
+		kfree(palmas_usb->edev->name);
 		return status;
 	}
 
@@ -209,7 +214,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
 		if (status < 0) {
 			dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->id_irq, status);
-			kfree(palmas_usb->edev.name);
+			kfree(palmas_usb->edev->name);
 			return status;
 		}
 	}
@@ -224,7 +229,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
 		if (status < 0) {
 			dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
 					palmas_usb->vbus_irq, status);
-			kfree(palmas_usb->edev.name);
+			kfree(palmas_usb->edev->name);
 			return status;
 		}
 	}
@@ -238,7 +243,7 @@ static int palmas_usb_remove(struct platform_device *pdev)
 {
 	struct palmas_usb *palmas_usb = platform_get_drvdata(pdev);
 
-	kfree(palmas_usb->edev.name);
+	kfree(palmas_usb->edev->name);
 
 	return 0;
 }
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 9974e38..b8f87b7 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -415,7 +415,7 @@ struct palmas_usb {
 	struct palmas *palmas;
 	struct device *dev;
 
-	struct extcon_dev edev;
+	struct extcon_dev *edev;
 
 	int id_otg_irq;
 	int id_irq;
-- 
1.8.0


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

* [PATCHv2 7/9] extcon: arizona: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
                   ` (5 preceding siblings ...)
  2014-04-21 12:02 ` [PATCHv2 6/9] extcon: palmas: " Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-21 12:55   ` Charles Keepax
  2014-04-21 12:02 ` [PATCHv2 8/9] extcon: adc-jack: " Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 9/9] extcon: gpio: " Chanwoo Choi
  8 siblings, 1 reply; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi, patches

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: patches@opensource.wolfsonmicro.com
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-arizona.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index f63fa6f..78931f1 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -91,7 +91,7 @@ struct arizona_extcon_info {
 
 	int hpdet_ip;
 
-	struct extcon_dev edev;
+	struct extcon_dev *edev;
 };
 
 static const struct arizona_micd_config micd_default_modes[] = {
@@ -546,7 +546,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 	}
 
 	/* If the cable was removed while measuring ignore the result */
-	ret = extcon_get_cable_state_(&info->edev, ARIZONA_CABLE_MECHANICAL);
+	ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL);
 	if (ret < 0) {
 		dev_err(arizona->dev, "Failed to check cable state: %d\n",
 			ret);
@@ -581,7 +581,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
 	else
 		report = ARIZONA_CABLE_HEADPHONE;
 
-	ret = extcon_set_cable_state_(&info->edev, report, true);
+	ret = extcon_set_cable_state_(info->edev, report, true);
 	if (ret != 0)
 		dev_err(arizona->dev, "Failed to report HP/line: %d\n",
 			ret);
@@ -664,7 +664,7 @@ err:
 			   ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
 
 	/* Just report headphone */
-	ret = extcon_update_state(&info->edev,
+	ret = extcon_update_state(info->edev,
 				  1 << ARIZONA_CABLE_HEADPHONE,
 				  1 << ARIZONA_CABLE_HEADPHONE);
 	if (ret != 0)
@@ -723,7 +723,7 @@ err:
 			   ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
 
 	/* Just report headphone */
-	ret = extcon_update_state(&info->edev,
+	ret = extcon_update_state(info->edev,
 				  1 << ARIZONA_CABLE_HEADPHONE,
 				  1 << ARIZONA_CABLE_HEADPHONE);
 	if (ret != 0)
@@ -764,7 +764,7 @@ static void arizona_micd_detect(struct work_struct *work)
 	mutex_lock(&info->lock);
 
 	/* If the cable was removed while measuring ignore the result */
-	ret = extcon_get_cable_state_(&info->edev, ARIZONA_CABLE_MECHANICAL);
+	ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL);
 	if (ret < 0) {
 		dev_err(arizona->dev, "Failed to check cable state: %d\n",
 				ret);
@@ -812,7 +812,7 @@ static void arizona_micd_detect(struct work_struct *work)
 	if (info->detecting && (val & ARIZONA_MICD_LVL_8)) {
 		arizona_identify_headphone(info);
 
-		ret = extcon_update_state(&info->edev,
+		ret = extcon_update_state(info->edev,
 					  1 << ARIZONA_CABLE_MICROPHONE,
 					  1 << ARIZONA_CABLE_MICROPHONE);
 
@@ -999,7 +999,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 
 	if (info->last_jackdet == present) {
 		dev_dbg(arizona->dev, "Detected jack\n");
-		ret = extcon_set_cable_state_(&info->edev,
+		ret = extcon_set_cable_state_(info->edev,
 					      ARIZONA_CABLE_MECHANICAL, true);
 
 		if (ret != 0)
@@ -1038,7 +1038,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 					 info->micd_ranges[i].key, 0);
 		input_sync(info->input);
 
-		ret = extcon_update_state(&info->edev, 0xffffffff, 0);
+		ret = extcon_update_state(info->edev, 0xffffffff, 0);
 		if (ret != 0)
 			dev_err(arizona->dev, "Removal report failed: %d\n",
 				ret);
@@ -1150,11 +1150,16 @@ static int arizona_extcon_probe(struct platform_device *pdev)
 		break;
 	}
 
-	info->edev.name = "Headset Jack";
-	info->edev.dev.parent = arizona->dev;
-	info->edev.supported_cable = arizona_cable;
+	info->edev = devm_extcon_dev_allocate(&pdev->dev, arizona_cable);
+	if (!info->edev) {
+		dev_err(&pdev->dev, "failed to allocate extcon device\n");
+		return -ENOMEM;
+	}
+	info->edev->name = "Headset Jack";
+	info->edev->dev.parent = arizona->dev;
+
 
-	ret = devm_extcon_dev_register(&pdev->dev, &info->edev);
+	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
 	if (ret < 0) {
 		dev_err(arizona->dev, "extcon_dev_register() failed: %d\n",
 			ret);
-- 
1.8.0


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

* [PATCHv2 8/9] extcon: adc-jack: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
                   ` (6 preceding siblings ...)
  2014-04-21 12:02 ` [PATCHv2 7/9] extcon: arizona: " Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  2014-04-21 12:02 ` [PATCHv2 9/9] extcon: gpio: " Chanwoo Choi
  8 siblings, 0 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-adc-jack.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index 549d820..fd3bc661 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -39,7 +39,7 @@
  * @chan:		iio channel being queried.
  */
 struct adc_jack_data {
-	struct extcon_dev edev;
+	struct extcon_dev *edev;
 
 	const char **cable_names;
 	int num_cables;
@@ -64,7 +64,7 @@ static void adc_jack_handler(struct work_struct *work)
 
 	ret = iio_read_channel_raw(data->chan, &adc_val);
 	if (ret < 0) {
-		dev_err(&data->edev.dev, "read channel() error: %d\n", ret);
+		dev_err(&data->edev->dev, "read channel() error: %d\n", ret);
 		return;
 	}
 
@@ -80,7 +80,7 @@ static void adc_jack_handler(struct work_struct *work)
 	}
 	/* if no def has met, it means state = 0 (no cables attached) */
 
-	extcon_set_state(&data->edev, state);
+	extcon_set_state(data->edev, state);
 }
 
 static irqreturn_t adc_jack_irq_thread(int irq, void *_data)
@@ -102,18 +102,21 @@ static int adc_jack_probe(struct platform_device *pdev)
 	if (!data)
 		return -ENOMEM;
 
-	data->edev.name = pdata->name;
-
 	if (!pdata->cable_names) {
 		dev_err(&pdev->dev, "error: cable_names not defined.\n");
 		return -EINVAL;
 	}
 
-	data->edev.dev.parent = &pdev->dev;
-	data->edev.supported_cable = pdata->cable_names;
+	data->edev = devm_extcon_dev_allocate(&pdev->dev, pdata->cable_names);
+	if (!data->edev) {
+		dev_err(&pdev->dev, "failed to allocate extcon device\n");
+		return -ENOMEM;
+	}
+	data->edev->dev.parent = &pdev->dev;
+	data->edev->name = pdata->name;
 
 	/* Check the length of array and set num_cables */
-	for (i = 0; data->edev.supported_cable[i]; i++)
+	for (i = 0; data->edev->supported_cable[i]; i++)
 		;
 	if (i == 0 || i > SUPPORTED_CABLE_MAX) {
 		dev_err(&pdev->dev, "error: pdata->cable_names size = %d\n",
@@ -144,7 +147,7 @@ static int adc_jack_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, data);
 
-	err = devm_extcon_dev_register(&pdev->dev, &data->edev);
+	err = devm_extcon_dev_register(&pdev->dev, data->edev);
 	if (err)
 		return err;
 
-- 
1.8.0


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

* [PATCHv2 9/9] extcon: gpio: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
                   ` (7 preceding siblings ...)
  2014-04-21 12:02 ` [PATCHv2 8/9] extcon: adc-jack: " Chanwoo Choi
@ 2014-04-21 12:02 ` Chanwoo Choi
  8 siblings, 0 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-21 12:02 UTC (permalink / raw)
  To: linux-kernel
  Cc: myungjoo.ham, balbi, gg, kishon, ckeepax, broonie, k.kozlowski,
	kyungmin.park, Chanwoo Choi

This patch use devm_extcon_dev_allocate() to simplify the memory control
of extcon device.

Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
---
 drivers/extcon/extcon-gpio.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 43af34c..41e2157 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -32,7 +32,7 @@
 #include <linux/extcon/extcon-gpio.h>
 
 struct gpio_extcon_data {
-	struct extcon_dev edev;
+	struct extcon_dev *edev;
 	unsigned gpio;
 	bool gpio_active_low;
 	const char *state_on;
@@ -53,7 +53,7 @@ static void gpio_extcon_work(struct work_struct *work)
 	state = gpio_get_value(data->gpio);
 	if (data->gpio_active_low)
 		state = !state;
-	extcon_set_state(&data->edev, state);
+	extcon_set_state(data->edev, state);
 }
 
 static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
@@ -67,9 +67,10 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 
 static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf)
 {
-	struct gpio_extcon_data	*extcon_data =
-		container_of(edev, struct gpio_extcon_data, edev);
+	struct device *dev = edev->dev.parent;
+	struct gpio_extcon_data *extcon_data = dev_get_drvdata(dev);
 	const char *state;
+
 	if (extcon_get_state(edev))
 		state = extcon_data->state_on;
 	else
@@ -98,15 +99,21 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	if (!extcon_data)
 		return -ENOMEM;
 
-	extcon_data->edev.name = pdata->name;
-	extcon_data->edev.dev.parent = &pdev->dev;
+	extcon_data->edev = devm_extcon_dev_allocate(&pdev->dev, NULL);
+	if (!extcon_data->edev) {
+		dev_err(&pdev->dev, "failed to allocate extcon device\n");
+		return -ENOMEM;
+	}
+	extcon_data->edev->name = pdata->name;
+	extcon_data->edev->dev.parent = &pdev->dev;
+
 	extcon_data->gpio = pdata->gpio;
 	extcon_data->gpio_active_low = pdata->gpio_active_low;
 	extcon_data->state_on = pdata->state_on;
 	extcon_data->state_off = pdata->state_off;
 	extcon_data->check_on_resume = pdata->check_on_resume;
 	if (pdata->state_on && pdata->state_off)
-		extcon_data->edev.print_state = extcon_gpio_print_state;
+		extcon_data->edev->print_state = extcon_gpio_print_state;
 
 	ret = devm_gpio_request_one(&pdev->dev, extcon_data->gpio, GPIOF_DIR_IN,
 				    pdev->name);
@@ -121,7 +128,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 				msecs_to_jiffies(pdata->debounce);
 	}
 
-	ret = devm_extcon_dev_register(&pdev->dev, &extcon_data->edev);
+	ret = devm_extcon_dev_register(&pdev->dev, extcon_data->edev);
 	if (ret < 0)
 		return ret;
 
-- 
1.8.0


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

* Re: [PATCHv2 7/9] extcon: arizona: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 7/9] extcon: arizona: " Chanwoo Choi
@ 2014-04-21 12:55   ` Charles Keepax
  0 siblings, 0 replies; 18+ messages in thread
From: Charles Keepax @ 2014-04-21 12:55 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, broonie,
	k.kozlowski, kyungmin.park, patches

On Mon, Apr 21, 2014 at 09:02:20PM +0900, Chanwoo Choi wrote:
> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Cc: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: patches@opensource.wolfsonmicro.com
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---

Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

Thanks,
Charles

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

* Re: [PATCHv2 3/9] extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 3/9] extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev Chanwoo Choi
@ 2014-04-22  8:17   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2014-04-22  8:17 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	kyungmin.park

On pon, 2014-04-21 at 21:02 +0900, Chanwoo Choi wrote:
> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/extcon/extcon-max8997.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

> diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
> index 804a446..e2ee2f5 100644
> --- a/drivers/extcon/extcon-max8997.c
> +++ b/drivers/extcon/extcon-max8997.c
> @@ -699,8 +699,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
>  	}
>  
>  	/* External connector */
> -	info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
> -				  GFP_KERNEL);
> +	info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable);
>  	if (!info->edev) {
>  		dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
>  		ret = -ENOMEM;
> @@ -708,7 +707,7 @@ static int max8997_muic_probe(struct platform_device *pdev)
>  	}
>  	info->edev->name = DEV_NAME;
>  	info->edev->dev.parent = &pdev->dev;
> -	info->edev->supported_cable = max8997_extcon_cable;
> +
>  	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to register extcon device\n");


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

* Re: [PATCHv2 4/9] extcon: max77693: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 4/9] extcon: max77693: " Chanwoo Choi
@ 2014-04-22  8:18   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2014-04-22  8:18 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	kyungmin.park


On pon, 2014-04-21 at 21:02 +0900, Chanwoo Choi wrote:
> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/extcon/extcon-max77693.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)


Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof


> diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
> index f0f18e2..2e15a24 100644
> --- a/drivers/extcon/extcon-max77693.c
> +++ b/drivers/extcon/extcon-max77693.c
> @@ -1175,8 +1175,8 @@ static int max77693_muic_probe(struct platform_device *pdev)
>  	}
>  
>  	/* Initialize extcon device */
> -	info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
> -				  GFP_KERNEL);
> +	info->edev = devm_extcon_dev_allocate(&pdev->dev,
> +					      max77693_extcon_cable);
>  	if (!info->edev) {
>  		dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
>  		ret = -ENOMEM;
> @@ -1184,14 +1184,13 @@ static int max77693_muic_probe(struct platform_device *pdev)
>  	}
>  	info->edev->name = DEV_NAME;
>  	info->edev->dev.parent = &pdev->dev;
> -	info->edev->supported_cable = max77693_extcon_cable;
> +
>  	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to register extcon device\n");
>  		goto err_irq;
>  	}
>  
> -
>  	/* Initialize MUIC register by using platform data or default data */
>  	if (pdata && pdata->muic_data) {
>  		init_data = pdata->muic_data->init_data;


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

* Re: [PATCHv2 5/9] extcon: max14577: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 5/9] extcon: max14577: " Chanwoo Choi
@ 2014-04-22  8:18   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2014-04-22  8:18 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	kyungmin.park

On pon, 2014-04-21 at 21:02 +0900, Chanwoo Choi wrote:
> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Cc: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/extcon/extcon-max14577.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>

Best regards,
Krzysztof


> diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
> index 7221b32..3d24dae 100644
> --- a/drivers/extcon/extcon-max14577.c
> +++ b/drivers/extcon/extcon-max14577.c
> @@ -668,13 +668,14 @@ static int max14577_muic_probe(struct platform_device *pdev)
>  	}
>  
>  	/* Initialize extcon device */
> -	info->edev = devm_kzalloc(&pdev->dev, sizeof(*info->edev), GFP_KERNEL);
> +	info->edev = devm_extcon_dev_allocate(&pdev->dev,
> +					      max14577_extcon_cable);
>  	if (!info->edev) {
>  		dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
>  		return -ENOMEM;
>  	}
>  	info->edev->name = DEV_NAME;
> -	info->edev->supported_cable = max14577_extcon_cable;
> +
>  	ret = devm_extcon_dev_register(&pdev->dev, info->edev);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to register extcon device\n");


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

* Re: [PATCHv2 6/9] extcon: palmas: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 6/9] extcon: palmas: " Chanwoo Choi
@ 2014-04-23 13:38   ` Lee Jones
  2014-04-23 13:55     ` Lee Jones
  2014-04-24  5:22   ` Chanwoo Choi
  2014-04-24 14:10   ` Felipe Balbi
  2 siblings, 1 reply; 18+ messages in thread
From: Lee Jones @ 2014-04-23 13:38 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	k.kozlowski, kyungmin.park, Samuel Ortiz

> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Cc: Graeme Gregory <gg@slimlogic.co.uk>
> Cc: Kishon Vijay Abraham I <kishon@ti.com>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Samuel Ortiz <sameo@linux.intel.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/extcon/extcon-palmas.c | 35 ++++++++++++++++++++---------------
>  include/linux/mfd/palmas.h     |  2 +-
>  2 files changed, 21 insertions(+), 16 deletions(-)

Applied, thanks.

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCHv2 6/9] extcon: palmas: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-23 13:38   ` Lee Jones
@ 2014-04-23 13:55     ` Lee Jones
  0 siblings, 0 replies; 18+ messages in thread
From: Lee Jones @ 2014-04-23 13:55 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	k.kozlowski, kyungmin.park, Samuel Ortiz

On Wed, 23 Apr 2014, Lee Jones wrote:

> > This patch use devm_extcon_dev_allocate() to simplify the memory control
> > of extcon device.
> > 
> > Cc: Graeme Gregory <gg@slimlogic.co.uk>
> > Cc: Kishon Vijay Abraham I <kishon@ti.com>
> > Cc: Felipe Balbi <balbi@ti.com>
> > Cc: Samuel Ortiz <sameo@linux.intel.com>
> > Cc: Lee Jones <lee.jones@linaro.org>
> > Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> > ---
> >  drivers/extcon/extcon-palmas.c | 35 ++++++++++++++++++++---------------
> >  include/linux/mfd/palmas.h     |  2 +-
> >  2 files changed, 21 insertions(+), 16 deletions(-)
> 
> Applied, thanks.

Doesn't apply. I guess there are dependencies in your repo. I don't
think a 2 line patch is worth us creating an Immutable branch
for. Instead, here's my:

  Acked-by: Lee Jones <lee.jones@linaro.org>

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCHv2 6/9] extcon: palmas: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 6/9] extcon: palmas: " Chanwoo Choi
  2014-04-23 13:38   ` Lee Jones
@ 2014-04-24  5:22   ` Chanwoo Choi
  2014-04-24 14:10   ` Felipe Balbi
  2 siblings, 0 replies; 18+ messages in thread
From: Chanwoo Choi @ 2014-04-24  5:22 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	k.kozlowski, kyungmin.park, Samuel Ortiz, Lee Jones

Hi Kishon, Felipe,

If you possible, I'd like you to test or review this patch.
And then I'll apply it on extcon-next branch if you could give
me a acked or tested message.

- This patch has a depenency on extcon-next branch.
Following patchset support devm_extcon_dev_* function.
[1] https://lkml.org/lkml/2014/4/21/140
[2] https://lkml.org/lkml/2014/4/21/164

Thanks,
Chanwoo Choi

On 04/21/2014 09:02 PM, Chanwoo Choi wrote:
> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Cc: Graeme Gregory <gg@slimlogic.co.uk>
> Cc: Kishon Vijay Abraham I <kishon@ti.com>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Samuel Ortiz <sameo@linux.intel.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
> ---
>  drivers/extcon/extcon-palmas.c | 35 ++++++++++++++++++++---------------
>  include/linux/mfd/palmas.h     |  2 +-
>  2 files changed, 21 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 1a770e0..a9299ea 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -57,7 +57,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
>  	if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
>  		if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
>  			palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
> -			extcon_set_cable_state(&palmas_usb->edev, "USB", true);
> +			extcon_set_cable_state(palmas_usb->edev, "USB", true);
>  			dev_info(palmas_usb->dev, "USB cable is attached\n");
>  		} else {
>  			dev_dbg(palmas_usb->dev,
> @@ -66,7 +66,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
>  	} else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
>  		if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
>  			palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
> -			extcon_set_cable_state(&palmas_usb->edev, "USB", false);
> +			extcon_set_cable_state(palmas_usb->edev, "USB", false);
>  			dev_info(palmas_usb->dev, "USB cable is detached\n");
>  		} else {
>  			dev_dbg(palmas_usb->dev,
> @@ -93,7 +93,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
>  			PALMAS_USB_ID_INT_LATCH_CLR,
>  			PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
>  		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
> -		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", true);
> +		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
>  		dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
>  	} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
>  				(id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
> @@ -101,17 +101,17 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
>  			PALMAS_USB_ID_INT_LATCH_CLR,
>  			PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
>  		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
> -		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
> +		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
>  		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
>  	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
>  				(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
>  		palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
> -		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
> +		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
>  		dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
>  	} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
>  				(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
>  		palmas_usb->linkstat = PALMAS_USB_STATE_ID;
> -		extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", true);
> +		extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
>  		dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
>  	}
>  
> @@ -187,15 +187,20 @@ static int palmas_usb_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, palmas_usb);
>  
> -	palmas_usb->edev.supported_cable = palmas_extcon_cable;
> -	palmas_usb->edev.dev.parent = palmas_usb->dev;
> -	palmas_usb->edev.name = kstrdup(node->name, GFP_KERNEL);
> -	palmas_usb->edev.mutually_exclusive = mutually_exclusive;
> +	palmas_usb->edev = devm_extcon_dev_allocate(&pdev->dev,
> +						    palmas_extcon_cable);
> +	if (!palmas_usb->edev) {
> +		dev_err(&pdev->dev, "failed to allocate extcon device\n");
> +		return -ENOMEM;
> +	}
> +	palmas_usb->edev->name = kstrdup(node->name, GFP_KERNEL);
> +	palmas_usb->edev->dev.parent = palmas_usb->dev;
> +	palmas_usb->edev->mutually_exclusive = mutually_exclusive;
>  
> -	status = devm_extcon_dev_register(&pdev->dev, &palmas_usb->edev);
> +	status = devm_extcon_dev_register(&pdev->dev, palmas_usb->edev);
>  	if (status) {
>  		dev_err(&pdev->dev, "failed to register extcon device\n");
> -		kfree(palmas_usb->edev.name);
> +		kfree(palmas_usb->edev->name);
>  		return status;
>  	}
>  
> @@ -209,7 +214,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
>  		if (status < 0) {
>  			dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
>  					palmas_usb->id_irq, status);
> -			kfree(palmas_usb->edev.name);
> +			kfree(palmas_usb->edev->name);
>  			return status;
>  		}
>  	}
> @@ -224,7 +229,7 @@ static int palmas_usb_probe(struct platform_device *pdev)
>  		if (status < 0) {
>  			dev_err(&pdev->dev, "can't get IRQ %d, err %d\n",
>  					palmas_usb->vbus_irq, status);
> -			kfree(palmas_usb->edev.name);
> +			kfree(palmas_usb->edev->name);
>  			return status;
>  		}
>  	}
> @@ -238,7 +243,7 @@ static int palmas_usb_remove(struct platform_device *pdev)
>  {
>  	struct palmas_usb *palmas_usb = platform_get_drvdata(pdev);
>  
> -	kfree(palmas_usb->edev.name);
> +	kfree(palmas_usb->edev->name);
>  
>  	return 0;
>  }
> diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
> index 9974e38..b8f87b7 100644
> --- a/include/linux/mfd/palmas.h
> +++ b/include/linux/mfd/palmas.h
> @@ -415,7 +415,7 @@ struct palmas_usb {
>  	struct palmas *palmas;
>  	struct device *dev;
>  
> -	struct extcon_dev edev;
> +	struct extcon_dev *edev;
>  
>  	int id_otg_irq;
>  	int id_irq;
> 


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

* Re: [PATCHv2 6/9] extcon: palmas: Use devm_extcon_dev_allocate for extcon_dev
  2014-04-21 12:02 ` [PATCHv2 6/9] extcon: palmas: " Chanwoo Choi
  2014-04-23 13:38   ` Lee Jones
  2014-04-24  5:22   ` Chanwoo Choi
@ 2014-04-24 14:10   ` Felipe Balbi
  2 siblings, 0 replies; 18+ messages in thread
From: Felipe Balbi @ 2014-04-24 14:10 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: linux-kernel, myungjoo.ham, balbi, gg, kishon, ckeepax, broonie,
	k.kozlowski, kyungmin.park, Samuel Ortiz, Lee Jones

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

On Mon, Apr 21, 2014 at 09:02:19PM +0900, Chanwoo Choi wrote:
> This patch use devm_extcon_dev_allocate() to simplify the memory control
> of extcon device.
> 
> Cc: Graeme Gregory <gg@slimlogic.co.uk>
> Cc: Kishon Vijay Abraham I <kishon@ti.com>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Samuel Ortiz <sameo@linux.intel.com>
> Cc: Lee Jones <lee.jones@linaro.org>
> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>

Tested on OMAP5 uEVM, please remember to fix up ordering in your
extcon-next branch to avoid introducing a non-bisectable history.

Tested-by: Felipe Balbi <balbi@ti.com>
Acked-by: Felipe Balbi <balbi@ti.com>

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2014-04-24 14:10 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-21 12:02 [PATCHv2 0/9] extcon: Support devm_extcon_dev_allocate/free() Chanwoo Choi
2014-04-21 12:02 ` [PATCHv2 1/9] extcon: Add extcon_dev_allocate/free() to control the memory of extcon device Chanwoo Choi
2014-04-21 12:02 ` [PATCHv2 2/9] extcon: Add devm_extcon_dev_allocate/free to manage the resource " Chanwoo Choi
2014-04-21 12:02 ` [PATCHv2 3/9] extcon: max8997: Use devm_extcon_dev_allocate for extcon_dev Chanwoo Choi
2014-04-22  8:17   ` Krzysztof Kozlowski
2014-04-21 12:02 ` [PATCHv2 4/9] extcon: max77693: " Chanwoo Choi
2014-04-22  8:18   ` Krzysztof Kozlowski
2014-04-21 12:02 ` [PATCHv2 5/9] extcon: max14577: " Chanwoo Choi
2014-04-22  8:18   ` Krzysztof Kozlowski
2014-04-21 12:02 ` [PATCHv2 6/9] extcon: palmas: " Chanwoo Choi
2014-04-23 13:38   ` Lee Jones
2014-04-23 13:55     ` Lee Jones
2014-04-24  5:22   ` Chanwoo Choi
2014-04-24 14:10   ` Felipe Balbi
2014-04-21 12:02 ` [PATCHv2 7/9] extcon: arizona: " Chanwoo Choi
2014-04-21 12:55   ` Charles Keepax
2014-04-21 12:02 ` [PATCHv2 8/9] extcon: adc-jack: " Chanwoo Choi
2014-04-21 12:02 ` [PATCHv2 9/9] extcon: gpio: " Chanwoo Choi

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