Skip to contentSkip to conversation

extcon: Core cleanups and documentation fixes

PATCH Applied Andy Shevchenko 3 participants 40 messages Mar 22, 2023 – Apr 6, 2023 External connector subsystem (extcon)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover extcon: Core cleanups and documentation fixes

A few fixes to the documentation and some cleanups against extcon core module.

Andy Shevchenko (14):
extcon: Fix kernel doc of property fields to avoid warnings
extcon: Fix kernel doc of property capability fields to avoid warnings
extcon: Use DECLARE_BITMAP() to declare bit arrays
extcon: use sysfs_emit() to instead of sprintf()
extcon: Amend kernel documentation of struct extcon_dev
extcon: Allow name to be assigned outside of the framework
extcon: Use unique number for the extcon device ID
extcon: Switch to use kasprintf_strarray()
extcon: Use device_match_of_node() helper
extcon: use dev_of_node(dev) instead of dev->of_node
extcon: Remove dup device name in the message and unneeded error check
extcon: Use sizeof(*pointer) instead of sizeof(type)
extcon: Drop unneeded assignments
extcon: Use positive conditional in ternary operator

 drivers/extcon/extcon.c | 126 +++++++++++++++++++++-------------------
 drivers/extcon/extcon.h |   9 ++-
 2 files changed, 71 insertions(+), 64 deletions(-)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw

PATCH 1/14 extcon: Fix kernel doc of property fields to avoid warnings

Kernel documentation has to be synchronized with a code, otherwise the validator is not happy:

Function parameter or member 'usb_propval' not described in 'extcon_cable' Function parameter or member 'chg_propval' not described in 'extcon_cable' Function parameter or member 'jack_propval' not described in 'extcon_cable' Function parameter or member 'disp_propval' not described in 'extcon_cable'

Describe the fields added in the past.

Fixes 067c1652e7a7 ("extcon: Add the support for extcon property according to extcon type")
---
 drivers/extcon/extcon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon.c +4 -0
index 3997b39680b7..1bc2639704c2 100644
@@ -206,6 +206,10 @@ static const struct __extcon_info {
  * @attr_name:		"name" sysfs entry
  * @attr_state:		"state" sysfs entry
  * @attrs:		the array pointing to attr_name and attr_state for attr_g
+ * @usb_propval:	the array of USB connector properties
+ * @chg_propval:	the array of charger connector properties
+ * @jack_propval:	the array of jack connector properties
+ * @disp_propval:	the array of display connector properties
  */
 struct extcon_cable {
 	struct extcon_dev *edev;
Signature · 1 line
2.40.0.1.gaa8946217a0b
Applied
#2 lore raw

Re: [PATCH v1 01/14] extcon: Fix kernel doc of property fields to avoid warnings

Quoted 21 lines · Andy Shevchenko

Kernel documentation has to be synchronized with a code, otherwise the validator is not happy:

Function parameter or member 'usb_propval' not described in 'extcon_cable' Function parameter or member 'chg_propval' not described in 'extcon_cable' Function parameter or member 'jack_propval' not described in 'extcon_cable' Function parameter or member 'disp_propval' not described in 'extcon_cable'

Describe the fields added in the past.

Fixes 067c1652e7a7 ("extcon: Add the support for extcon property according to extcon type")
---
 drivers/extcon/extcon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon.c +0 -0
index 3997b39680b7..1bc2639704c2 100644

drivers/extcon/extcon.c static const struct __extcon_info { · line 215

Quoted 10 lines
drivers/extcon/extcon.c +4 -0
@@ -206,6 +206,10 @@ static const struct __extcon_info {
  * @attr_name:		"name" sysfs entry
  * @attr_state:		"state" sysfs entry
  * @attrs:		the array pointing to attr_name and attr_state for attr_g
+ * @usb_propval:	the array of USB connector properties
+ * @chg_propval:	the array of charger connector properties
+ * @jack_propval:	the array of jack connector properties
+ * @disp_propval:	the array of display connector properties
  */
 struct extcon_cable {
 	struct extcon_dev *edev;

Applied it. Thanks.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#3 lore raw

PATCH 2/14 extcon: Fix kernel doc of property capability fields to avoid warnings

In reply to Andy Shevchenko

Kernel documentation has to be synchronized with a code, otherwise the validator is not happy:

Function parameter or member 'usb_bits' not described in 'extcon_cable' Function parameter or member 'chg_bits' not described in 'extcon_cable' Function parameter or member 'jack_bits' not described in 'extcon_cable' Function parameter or member 'disp_bits' not described in 'extcon_cable'

Describe the fields added in the past.

Fixes ceaa98f442cf ("extcon: Add the support for the capability of each property")
---
 drivers/extcon/extcon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon.c +4 -0
index 1bc2639704c2..79006ab5334b 100644
@@ -210,6 +210,10 @@ static const struct __extcon_info {
  * @chg_propval:	the array of charger connector properties
  * @jack_propval:	the array of jack connector properties
  * @disp_propval:	the array of display connector properties
+ * @usb_bits:		the bit array of the USB connector property capabilities
+ * @chg_bits:		the bit array of the charger connector property capabilities
+ * @jack_bits:		the bit array of the jack connector property capabilities
+ * @disp_bits:		the bit array of the display connector property capabilities
  */
 struct extcon_cable {
 	struct extcon_dev *edev;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#4 lore raw

Re: [PATCH v1 02/14] extcon: Fix kernel doc of property capability fields to avoid warnings

Quoted 21 lines · Andy Shevchenko

Kernel documentation has to be synchronized with a code, otherwise the validator is not happy:

Function parameter or member 'usb_bits' not described in 'extcon_cable' Function parameter or member 'chg_bits' not described in 'extcon_cable' Function parameter or member 'jack_bits' not described in 'extcon_cable' Function parameter or member 'disp_bits' not described in 'extcon_cable'

Describe the fields added in the past.

Fixes ceaa98f442cf ("extcon: Add the support for the capability of each property")
---
 drivers/extcon/extcon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/extcon/extcon.c +0 -0
index 1bc2639704c2..79006ab5334b 100644

drivers/extcon/extcon.c static const struct __extcon_info { · line 219

Quoted 10 lines
drivers/extcon/extcon.c +4 -0
@@ -210,6 +210,10 @@ static const struct __extcon_info {
  * @chg_propval:	the array of charger connector properties
  * @jack_propval:	the array of jack connector properties
  * @disp_propval:	the array of display connector properties
+ * @usb_bits:		the bit array of the USB connector property capabilities
+ * @chg_bits:		the bit array of the charger connector property capabilities
+ * @jack_bits:		the bit array of the jack connector property capabilities
+ * @disp_bits:		the bit array of the display connector property capabilities
  */
 struct extcon_cable {
 	struct extcon_dev *edev;

Applied it.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#5 lore raw

PATCH 3/14 extcon: Use DECLARE_BITMAP() to declare bit arrays

In reply to Andy Shevchenko

Bit arrays has a specific type helper for the declaration. Use it instead of homegronw equivalent.

---
 drivers/extcon/extcon.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/extcon/extcon.c +4 -4
index 79006ab5334b..70e9755ba2bc 100644
@@ -230,10 +230,10 @@ struct extcon_cable {
 	union extcon_property_value jack_propval[EXTCON_PROP_JACK_CNT];
 	union extcon_property_value disp_propval[EXTCON_PROP_DISP_CNT];
 
-	unsigned long usb_bits[BITS_TO_LONGS(EXTCON_PROP_USB_CNT)];
-	unsigned long chg_bits[BITS_TO_LONGS(EXTCON_PROP_CHG_CNT)];
-	unsigned long jack_bits[BITS_TO_LONGS(EXTCON_PROP_JACK_CNT)];
-	unsigned long disp_bits[BITS_TO_LONGS(EXTCON_PROP_DISP_CNT)];
+	DECLARE_BITMAP(usb_bits, EXTCON_PROP_USB_CNT);
+	DECLARE_BITMAP(chg_bits, EXTCON_PROP_CHG_CNT);
+	DECLARE_BITMAP(jack_bits, EXTCON_PROP_JACK_CNT);
+	DECLARE_BITMAP(disp_bits, EXTCON_PROP_DISP_CNT);
 };
 
 static struct class *extcon_class;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#6 lore raw

Re: [PATCH v1 03/14] extcon: Use DECLARE_BITMAP() to declare bit arrays

Quoted 17 lines · Andy Shevchenko

Bit arrays has a specific type helper for the declaration. Use it instead of homegronw equivalent.

---
 drivers/extcon/extcon.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/extcon/extcon.c +0 -1
index 79006ab5334b..70e9755ba2bc 100644
@@ -230,10 +230,10 @@ struct extcon_cable {
 	union extcon_property_value jack_propval[EXTCON_PROP_JACK_CNT];
 	union extcon_property_value disp_propval[EXTCON_PROP_DISP_CNT];
 
-	unsigned long usb_bits[BITS_TO_LONGS(EXTCON_PROP_USB_CNT)];

drivers/extcon/extcon.c struct extcon_cable { · line 239

Quoted 10 lines
drivers/extcon/extcon.c +4 -3
-	unsigned long chg_bits[BITS_TO_LONGS(EXTCON_PROP_CHG_CNT)];
-	unsigned long jack_bits[BITS_TO_LONGS(EXTCON_PROP_JACK_CNT)];
-	unsigned long disp_bits[BITS_TO_LONGS(EXTCON_PROP_DISP_CNT)];
+	DECLARE_BITMAP(usb_bits, EXTCON_PROP_USB_CNT);
+	DECLARE_BITMAP(chg_bits, EXTCON_PROP_CHG_CNT);
+	DECLARE_BITMAP(jack_bits, EXTCON_PROP_JACK_CNT);
+	DECLARE_BITMAP(disp_bits, EXTCON_PROP_DISP_CNT);
 };
 
 static struct class *extcon_class;

Applied it.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#7 lore raw

PATCH 4/14 extcon: use sysfs_emit() to instead of sprintf()

In reply to Andy Shevchenko

Follow the advice of the Documentation/filesystems/sysfs.rst that show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/extcon/extcon.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/extcon/extcon.c +9 -9
index 70e9755ba2bc..ac84f4aafc69 100644
@@ -370,12 +370,12 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
 	struct extcon_dev *edev = dev_get_drvdata(dev);
 
 	if (edev->max_supported == 0)
-		return sprintf(buf, "%u\n", edev->state);
+		return sysfs_emit(buf, "%u\n", edev->state);
 
 	for (i = 0; i < edev->max_supported; i++) {
-		count += sprintf(buf + count, "%s=%d\n",
-				extcon_info[edev->supported_cable[i]].name,
-				 !!(edev->state & BIT(i)));
+		count += sysfs_emit_at(buf, count, "%s=%d\n",
+				       extcon_info[edev->supported_cable[i]].name,
+				       !!(edev->state & BIT(i)));
 	}
 
 	return count;
@@ -387,7 +387,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
 {
 	struct extcon_dev *edev = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%s\n", edev->name);
+	return sysfs_emit(buf, "%s\n", edev->name);
 }
 static DEVICE_ATTR_RO(name);
 
@@ -398,8 +398,8 @@ static ssize_t cable_name_show(struct device *dev,
 						  attr_name);
 	int i = cable->cable_index;
 
-	return sprintf(buf, "%s\n",
-			extcon_info[cable->edev->supported_cable[i]].name);
+	return sysfs_emit(buf, "%s\n",
+			  extcon_info[cable->edev->supported_cable[i]].name);
 }
 
 static ssize_t cable_state_show(struct device *dev,
@@ -410,8 +410,8 @@ static ssize_t cable_state_show(struct device *dev,
 
 	int i = cable->cable_index;
 
-	return sprintf(buf, "%d\n",
-		extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
+	return sysfs_emit(buf, "%d\n",
+			  extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
 }
 
 /**
Signature · 1 line
2.40.0.1.gaa8946217a0b
#8 lore raw

Re: [PATCH v1 04/14] extcon: use sysfs_emit() to instead of sprintf()

Quoted 51 lines · Andy Shevchenko

Follow the advice of the Documentation/filesystems/sysfs.rst that show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.

---
 drivers/extcon/extcon.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/extcon/extcon.c +7 -7
index 70e9755ba2bc..ac84f4aafc69 100644
@@ -370,12 +370,12 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
 	struct extcon_dev *edev = dev_get_drvdata(dev);
 
 	if (edev->max_supported == 0)
-		return sprintf(buf, "%u\n", edev->state);
+		return sysfs_emit(buf, "%u\n", edev->state);
 
 	for (i = 0; i < edev->max_supported; i++) {
-		count += sprintf(buf + count, "%s=%d\n",
-				extcon_info[edev->supported_cable[i]].name,
-				 !!(edev->state & BIT(i)));
+		count += sysfs_emit_at(buf, count, "%s=%d\n",
+				       extcon_info[edev->supported_cable[i]].name,
+				       !!(edev->state & BIT(i)));
 	}
 
 	return count;
@@ -387,7 +387,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr,
 {
 	struct extcon_dev *edev = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%s\n", edev->name);
+	return sysfs_emit(buf, "%s\n", edev->name);
 }
 static DEVICE_ATTR_RO(name);
 
@@ -398,8 +398,8 @@ static ssize_t cable_name_show(struct device *dev,
 						  attr_name);
 	int i = cable->cable_index;
 
-	return sprintf(buf, "%s\n",
-			extcon_info[cable->edev->supported_cable[i]].name);
+	return sysfs_emit(buf, "%s\n",
+			  extcon_info[cable->edev->supported_cable[i]].name);
 }
 
 static ssize_t cable_state_show(struct device *dev,

drivers/extcon/extcon.c static ssize_t cable_state_show(struct device *dev, · line 417

Quoted 10 lines
drivers/extcon/extcon.c +2 -2
@@ -410,8 +410,8 @@ static ssize_t cable_state_show(struct device *dev,
 
 	int i = cable->cable_index;
 
-	return sprintf(buf, "%d\n",
-		extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
+	return sysfs_emit(buf, "%d\n",
+			  extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
 }
 
 /**

Applied it.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#9 lore raw

PATCH 5/14 extcon: Amend kernel documentation of struct extcon_dev

In reply to Andy Shevchenko

First of all, the @lock description is missing. Add it. Second, correct the terminator value for the mutual exclusive cabling.

---
 drivers/extcon/extcon.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/extcon/extcon.h +3 -3
index 93b5e0306966..15616446140d 100644
@@ -13,8 +13,8 @@
  *			are disabled.
  * @mutually_exclusive:	Array of mutually exclusive set of cables that cannot
  *			be attached simultaneously. The array should be
- *			ending with NULL or be NULL (no mutually exclusive
- *			cables). For example, if it is { 0x7, 0x30, 0}, then,
+ *			ending with 0 or be NULL (no mutually exclusive cables).
+ *			For example, if it is {0x7, 0x30, 0}, then,
  *			{0, 1}, {0, 1, 2}, {0, 2}, {1, 2}, or {4, 5} cannot
  *			be attached simulataneously. {0x7, 0} is equivalent to
  *			{0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there
@@ -27,7 +27,7 @@
  * @nh:			Notifier for the state change events from this extcon
  * @entry:		To support list of extcon devices so that users can
  *			search for extcon devices based on the extcon name.
- * @lock:
+ * @lock:		Protects device state and serialises device registration
  * @max_supported:	Internal value to store the number of cables.
  * @extcon_dev_type:	Device_type struct to provide attribute_groups
  *			customized for each extcon device.
Signature · 1 line
2.40.0.1.gaa8946217a0b
#10 lore raw

Re: [PATCH v1 05/14] extcon: Amend kernel documentation of struct extcon_dev

Quoted 25 lines · Andy Shevchenko

First of all, the @lock description is missing. Add it. Second, correct the terminator value for the mutual exclusive cabling.

---
 drivers/extcon/extcon.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/extcon/extcon.h +2 -2
index 93b5e0306966..15616446140d 100644
@@ -13,8 +13,8 @@
  *			are disabled.
  * @mutually_exclusive:	Array of mutually exclusive set of cables that cannot
  *			be attached simultaneously. The array should be
- *			ending with NULL or be NULL (no mutually exclusive
- *			cables). For example, if it is { 0x7, 0x30, 0}, then,
+ *			ending with 0 or be NULL (no mutually exclusive cables).
+ *			For example, if it is {0x7, 0x30, 0}, then,
  *			{0, 1}, {0, 1, 2}, {0, 2}, {1, 2}, or {4, 5} cannot
  *			be attached simulataneously. {0x7, 0} is equivalent to
  *			{0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there

drivers/extcon/extcon.h line 33

Quoted 8 lines
drivers/extcon/extcon.h +1 -1
@@ -27,7 +27,7 @@
  * @nh:			Notifier for the state change events from this extcon
  * @entry:		To support list of extcon devices so that users can
  *			search for extcon devices based on the extcon name.
- * @lock:
+ * @lock:		Protects device state and serialises device registration
  * @max_supported:	Internal value to store the number of cables.
  * @extcon_dev_type:	Device_type struct to provide attribute_groups
  *			customized for each extcon device.

Applied it.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#11 lore raw

PATCH 6/14 extcon: Allow name to be assigned outside of the framework

In reply to Andy Shevchenko

The documentation states that name of the extcon can be assigned outside of the framework, however code does something different. Fix the code to be aligned with the documentation.

---
 drivers/extcon/extcon.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/extcon/extcon.c +4 -4
index ac84f4aafc69..14e66e21597f 100644
@@ -1269,10 +1269,10 @@ int extcon_dev_register(struct extcon_dev *edev)
 	edev->dev.class = extcon_class;
 	edev->dev.release = extcon_dev_release;
 
-	edev->name = dev_name(edev->dev.parent);
-	if (IS_ERR_OR_NULL(edev->name)) {
-		dev_err(&edev->dev,
-			"extcon device name is null\n");
+	if (!edev->name)
+		edev->name = dev_name(edev->dev.parent);
+	if (!edev->name) {
+		dev_err(&edev->dev, "extcon device name is null\n");
 		return -EINVAL;
 	}
 	dev_set_name(&edev->dev, "extcon%lu",
Signature · 1 line
2.40.0.1.gaa8946217a0b
#12 lore raw

Re: [PATCH v1 06/14] extcon: Allow name to be assigned outside of the framework

Quoted 3 lines · Andy Shevchenko

The documentation states that name of the extcon can be assigned outside of the framework, however code does something different. Fix the code to be aligned with the documentation.

Actually, it is not possible to initialize the name outside of the framework because commit 20f7b53dfc24 ("extcon: Move struct extcon_cable from header file to core") moved the 'struct extcon_dev' into drivers/extcon/extcon.c in order to prevent the direct accessing of struct extcon_dev.

Instead of this patch, need to change the description of struct extcon_dev.

Quoted 25 lines
---
 drivers/extcon/extcon.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/extcon/extcon.c +4 -4
index ac84f4aafc69..14e66e21597f 100644
@@ -1269,10 +1269,10 @@ int extcon_dev_register(struct extcon_dev *edev)
 	edev->dev.class = extcon_class;
 	edev->dev.release = extcon_dev_release;
 
-	edev->name = dev_name(edev->dev.parent);
-	if (IS_ERR_OR_NULL(edev->name)) {
-		dev_err(&edev->dev,
-			"extcon device name is null\n");
+	if (!edev->name)
+		edev->name = dev_name(edev->dev.parent);
+	if (!edev->name) {
+		dev_err(&edev->dev, "extcon device name is null\n");
 		return -EINVAL;
 	}
 	dev_set_name(&edev->dev, "extcon%lu",
Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#13 lore raw

PATCH 7/14 extcon: Use unique number for the extcon device ID

In reply to Andy Shevchenko

The use of atomic variable is still racy when we do not control which device has been unregistered and there is a (theoretical) possibility of the overflow that may cause a duplicate extcon device ID number to be allocated next time a device is registered.

Replace above mentioned approach by using IDA framework.

---
 drivers/extcon/extcon.c | 15 ++++++++++++---
 drivers/extcon/extcon.h |  2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)
drivers/extcon/extcon.c +12 -3
index 14e66e21597f..0d261ec6c473 100644
@@ -16,6 +16,7 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
+#include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/fs.h>
@@ -238,6 +239,7 @@ struct extcon_cable {
 
 static struct class *extcon_class;
 
+static DEFINE_IDA(extcon_dev_ids);
 static LIST_HEAD(extcon_dev_list);
 static DEFINE_MUTEX(extcon_dev_list_lock);
 
@@ -1248,7 +1250,6 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
 int extcon_dev_register(struct extcon_dev *edev)
 {
 	int ret, index = 0;
-	static atomic_t edev_no = ATOMIC_INIT(-1);
 
 	ret = create_extcon_class();
 	if (ret < 0)
@@ -1275,8 +1276,14 @@ int extcon_dev_register(struct extcon_dev *edev)
 		dev_err(&edev->dev, "extcon device name is null\n");
 		return -EINVAL;
 	}
-	dev_set_name(&edev->dev, "extcon%lu",
-			(unsigned long)atomic_inc_return(&edev_no));
+
+	ret = ida_simple_get(&extcon_dev_ids, 0, INT_MAX, GFP_KERNEL);
+	if (ret < 0)
+		return ret;
+
+	edev->id = ret;
+
+	dev_set_name(&edev->dev, "extcon%d", edev->id);
 
 	ret = extcon_alloc_cables(edev);
 	if (ret < 0)
@@ -1368,6 +1375,8 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 		return;
 	}
 
+	ida_simple_remove(&extcon_dev_ids, edev->id);
+
 	device_unregister(&edev->dev);
 
 	if (edev->mutually_exclusive && edev->max_supported) {
drivers/extcon/extcon.h +2 -0
index 15616446140d..877c0860e300 100644
@@ -20,6 +20,7 @@
  *			{0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there
  *			can be no simultaneous connections.
  * @dev:		Device of this extcon.
+ * @id:			Unique device ID of this extcon.
  * @state:		Attach/detach state of this extcon. Do not provide at
  *			register-time.
  * @nh_all:		Notifier for the state change events for all supported
@@ -46,6 +47,7 @@ struct extcon_dev {
 
 	/* Internal data. Please do not set. */
 	struct device dev;
+	int id;
 	struct raw_notifier_head nh_all;
 	struct raw_notifier_head *nh;
 	struct list_head entry;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#14 lore raw

Re: [PATCH v1 07/14] extcon: Use unique number for the extcon device ID

Quoted 42 lines · Andy Shevchenko

The use of atomic variable is still racy when we do not control which device has been unregistered and there is a (theoretical) possibility of the overflow that may cause a duplicate extcon device ID number to be allocated next time a device is registered.

Replace above mentioned approach by using IDA framework.

---
 drivers/extcon/extcon.c | 15 ++++++++++++---
 drivers/extcon/extcon.h |  2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)
drivers/extcon/extcon.c +2 -1
index 14e66e21597f..0d261ec6c473 100644
@@ -16,6 +16,7 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
+#include <linux/idr.h>
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/fs.h>
@@ -238,6 +239,7 @@ struct extcon_cable {
 
 static struct class *extcon_class;
 
+static DEFINE_IDA(extcon_dev_ids);
 static LIST_HEAD(extcon_dev_list);
 static DEFINE_MUTEX(extcon_dev_list_lock);
 
@@ -1248,7 +1250,6 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
 int extcon_dev_register(struct extcon_dev *edev)
 {
 	int ret, index = 0;
-	static atomic_t edev_no = ATOMIC_INIT(-1);
 
 	ret = create_extcon_class();
 	if (ret < 0)

drivers/extcon/extcon.c int extcon_dev_register(struct extcon_dev *edev) · line 1280

Quoted 7 lines
drivers/extcon/extcon.c +2 -2
@@ -1275,8 +1276,14 @@ int extcon_dev_register(struct extcon_dev *edev)
 		dev_err(&edev->dev, "extcon device name is null\n");
 		return -EINVAL;
 	}
-	dev_set_name(&edev->dev, "extcon%lu",
-			(unsigned long)atomic_inc_return(&edev_no));
+
+	ret = ida_simple_get(&extcon_dev_ids, 0, INT_MAX, GFP_KERNEL);

ida_simple_get and ida_simple_remove are deprecated on commit 3264ceec8f17 ("lib/idr.c: document that ida_simple_{get,remove}() are deprecated"). Instead of them, better to use ida_alloc and ida_free according to the comments.

Quoted 10 lines
drivers/extcon/extcon.c +6 -0
+	if (ret < 0)
+		return ret;
+
+	edev->id = ret;
+
+	dev_set_name(&edev->dev, "extcon%d", edev->id);
 
 	ret = extcon_alloc_cables(edev);
 	if (ret < 0)

drivers/extcon/extcon.c void extcon_dev_unregister(struct extcon_dev *edev) · line 1378

Quoted 4 lines
drivers/extcon/extcon.c +1 -0
@@ -1368,6 +1375,8 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 		return;
 	}
 
+	ida_simple_remove(&extcon_dev_ids, edev->id);

ditto.

Quoted 24 lines
drivers/extcon/extcon.c +1 -0
+
 	device_unregister(&edev->dev);
 
 	if (edev->mutually_exclusive && edev->max_supported) {
drivers/extcon/extcon.h +2 -0
index 15616446140d..877c0860e300 100644
@@ -20,6 +20,7 @@
  *			{0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there
  *			can be no simultaneous connections.
  * @dev:		Device of this extcon.
+ * @id:			Unique device ID of this extcon.
  * @state:		Attach/detach state of this extcon. Do not provide at
  *			register-time.
  * @nh_all:		Notifier for the state change events for all supported
@@ -46,6 +47,7 @@ struct extcon_dev {
 
 	/* Internal data. Please do not set. */
 	struct device dev;
+	int id;
 	struct raw_notifier_head nh_all;
 	struct raw_notifier_head *nh;
 	struct list_head entry;
Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#15 lore raw

Re: [PATCH v1 07/14] extcon: Use unique number for the extcon device ID

Quoted 1 line · Chanwoo Choi

On 23. 3. 22. 23:39, Andy Shevchenko wrote:

...

Quoted 7 lines

drivers/extcon/extcon.c int extcon_dev_register(struct extcon_dev *edev) · line 1280

Quoted 1 line
drivers/extcon/extcon.c +1 -0
+	ret = ida_simple_get(&extcon_dev_ids, 0, INT_MAX, GFP_KERNEL);

ida_simple_get and ida_simple_remove are deprecated on commit 3264ceec8f17 ("lib/idr.c: document that ida_simple_{get,remove}() are deprecated"). Instead of them, better to use ida_alloc and ida_free according to the comments.

Done for v2.

...

Quoted 3 lines

drivers/extcon/extcon.c void extcon_dev_unregister(struct extcon_dev *edev) · line 1378

Quoted 1 line
drivers/extcon/extcon.c +1 -0
+	ida_simple_remove(&extcon_dev_ids, edev->id);

ditto.

Ditto.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#16 lore raw

PATCH 8/14 extcon: Switch to use kasprintf_strarray()

In reply to Andy Shevchenko

Since we have a generic helper, switch the module to use it. No functional change intended.

---
 drivers/extcon/extcon.c | 25 +++++++++++--------------
 drivers/extcon/extcon.h |  1 +
 2 files changed, 12 insertions(+), 14 deletions(-)
drivers/extcon/extcon.c +11 -14
index 0d261ec6c473..a63e7eef02fd 100644
@@ -23,6 +23,7 @@
 #include <linux/err.h>
 #include <linux/of.h>
 #include <linux/slab.h>
+#include <linux/string_helpers.h>
 #include <linux/sysfs.h>
 
 #include "extcon.h"
@@ -1104,19 +1105,17 @@ static int extcon_alloc_cables(struct extcon_dev *edev)
 	if (!edev->cables)
 		return -ENOMEM;
 
+	edev->cable_names = kasprintf_strarray(GFP_KERNEL, "cable", edev->max_supported);
+	if (!edev->cable_names) {
+		kfree(edev->cables);
+		return -ENOMEM;
+	}
+
 	for (index = 0; index < edev->max_supported; index++) {
 		cable = &edev->cables[index];
 
-		str = kasprintf(GFP_KERNEL, "cable.%d", index);
-		if (!str) {
-			for (index--; index >= 0; index--) {
-				cable = &edev->cables[index];
-				kfree(cable->attr_g.name);
-			}
-
-			kfree(edev->cables);
-			return -ENOMEM;
-		}
+		str = edev->cable_names[index];
+		strreplace(str, '-', '.');
 
 		cable->edev = edev;
 		cable->cable_index = index;
@@ -1341,8 +1340,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 		kfree(edev->attrs_muex);
 	}
 err_alloc_muex:
-	for (index = 0; index < edev->max_supported; index++)
-		kfree(edev->cables[index].attr_g.name);
+	kfree_strarray(edev->cable_names, edev->max_supported);
 	if (edev->max_supported)
 		kfree(edev->cables);
 err_alloc_cables:
@@ -1387,8 +1385,7 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 		kfree(edev->attrs_muex);
 	}
 
-	for (index = 0; index < edev->max_supported; index++)
-		kfree(edev->cables[index].attr_g.name);
+	kfree_strarray(edev->cable_names, edev->max_supported);
 
 	if (edev->max_supported) {
 		kfree(edev->extcon_dev_type.groups);
drivers/extcon/extcon.h +1 -0
index 877c0860e300..5624f65ba17a 100644
@@ -58,6 +58,7 @@ struct extcon_dev {
 	/* /sys/class/extcon/.../cable.n/... */
 	struct device_type extcon_dev_type;
 	struct extcon_cable *cables;
+	char **cable_names;
 
 	/* /sys/class/extcon/.../mutually_exclusive/... */
 	struct attribute_group attr_g_muex;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#17 lore raw

Re: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray()

Quoted 74 lines · Andy Shevchenko

Since we have a generic helper, switch the module to use it. No functional change intended.

---
 drivers/extcon/extcon.c | 25 +++++++++++--------------
 drivers/extcon/extcon.h |  1 +
 2 files changed, 12 insertions(+), 14 deletions(-)
drivers/extcon/extcon.c +11 -14
index 0d261ec6c473..a63e7eef02fd 100644
@@ -23,6 +23,7 @@
 #include <linux/err.h>
 #include <linux/of.h>
 #include <linux/slab.h>
+#include <linux/string_helpers.h>
 #include <linux/sysfs.h>
 
 #include "extcon.h"
@@ -1104,19 +1105,17 @@ static int extcon_alloc_cables(struct extcon_dev *edev)
 	if (!edev->cables)
 		return -ENOMEM;
 
+	edev->cable_names = kasprintf_strarray(GFP_KERNEL, "cable", edev->max_supported);
+	if (!edev->cable_names) {
+		kfree(edev->cables);
+		return -ENOMEM;
+	}
+
 	for (index = 0; index < edev->max_supported; index++) {
 		cable = &edev->cables[index];
 
-		str = kasprintf(GFP_KERNEL, "cable.%d", index);
-		if (!str) {
-			for (index--; index >= 0; index--) {
-				cable = &edev->cables[index];
-				kfree(cable->attr_g.name);
-			}
-
-			kfree(edev->cables);
-			return -ENOMEM;
-		}
+		str = edev->cable_names[index];
+		strreplace(str, '-', '.');
 
 		cable->edev = edev;
 		cable->cable_index = index;
@@ -1341,8 +1340,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 		kfree(edev->attrs_muex);
 	}
 err_alloc_muex:
-	for (index = 0; index < edev->max_supported; index++)
-		kfree(edev->cables[index].attr_g.name);
+	kfree_strarray(edev->cable_names, edev->max_supported);
 	if (edev->max_supported)
 		kfree(edev->cables);
 err_alloc_cables:
@@ -1387,8 +1385,7 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 		kfree(edev->attrs_muex);
 	}
 
-	for (index = 0; index < edev->max_supported; index++)
-		kfree(edev->cables[index].attr_g.name);
+	kfree_strarray(edev->cable_names, edev->max_supported);
 
 	if (edev->max_supported) {
 		kfree(edev->extcon_dev_type.groups);
drivers/extcon/extcon.h +0 -0
index 877c0860e300..5624f65ba17a 100644

drivers/extcon/extcon.h struct extcon_dev { · line 61

Quoted 4 lines
drivers/extcon/extcon.h +1 -0
@@ -58,6 +58,7 @@ struct extcon_dev {
 	/* /sys/class/extcon/.../cable.n/... */
 	struct device_type extcon_dev_type;
 	struct extcon_cable *cables;
+	char **cable_names;

The extcon cable information should be included in struct extcon_cable in order to gather information into one point like encapsulation.

I don't prefer to add 'cable_names'.

Quoted 3 lines
drivers/extcon/extcon.h +0 -0
 	/* /sys/class/extcon/.../mutually_exclusive/... */
 	struct attribute_group attr_g_muex;
Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#18 lore raw

Re: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray()

Quoted 3 lines · Chanwoo Choi
Quoted 2 lines · Andy Shevchenko

Since we have a generic helper, switch the module to use it. No functional change intended.

...

Quoted 15 lines
Quoted 15 lines
drivers/extcon/extcon.c +8 -0
+	edev->cable_names = kasprintf_strarray(GFP_KERNEL, "cable", edev->max_supported);
+	if (!edev->cable_names) {
+		kfree(edev->cables);
+		return -ENOMEM;
+	}
+
 	for (index = 0; index < edev->max_supported; index++) {
 		cable = &edev->cables[index];
 
 
+		str = edev->cable_names[index];
+		strreplace(str, '-', '.');
 
 		cable->edev = edev;
 		cable->cable_index = index;

...

Quoted 9 lines

drivers/extcon/extcon.h struct extcon_dev { · line 61

Quoted 4 lines
drivers/extcon/extcon.h +1 -0
 	/* /sys/class/extcon/.../cable.n/... */
 	struct device_type extcon_dev_type;
 	struct extcon_cable *cables;
+	char **cable_names;

The extcon cable information should be included in struct extcon_cable in order to gather information into one point like encapsulation.

I don't prefer to add 'cable_names'.

I don't get this. The idea is to allocate the cable names in one call, we have already API for that. The cable names are kept in the struct extcon_cable as before. So, functionally it doesn't change anything, it is a simple cleanup.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#19 lore raw

Re: [PATCH v1 08/14] extcon: Switch to use kasprintf_strarray()

Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Chanwoo Choi
Quoted 2 lines · Andy Shevchenko

Since we have a generic helper, switch the module to use it. No functional change intended.

...

Quoted 26 lines
Quoted 15 lines
Quoted 15 lines
drivers/extcon/extcon.c +8 -0
+	edev->cable_names = kasprintf_strarray(GFP_KERNEL, "cable", edev->max_supported);
+	if (!edev->cable_names) {
+		kfree(edev->cables);
+		return -ENOMEM;
+	}
+
 	for (index = 0; index < edev->max_supported; index++) {
 		cable = &edev->cables[index];
 
 
+		str = edev->cable_names[index];
+		strreplace(str, '-', '.');
 
 		cable->edev = edev;
 		cable->cable_index = index;

...

Quoted 8 lines

drivers/extcon/extcon.h struct extcon_dev { · line 61

Quoted 4 lines
drivers/extcon/extcon.h +1 -0
 	/* /sys/class/extcon/.../cable.n/... */
 	struct device_type extcon_dev_type;
 	struct extcon_cable *cables;
+	char **cable_names;

The extcon cable information should be included in struct extcon_cable in order to gather information into one point like encapsulation.

Quoted 6 lines
Quoted 1 line

I don't prefer to add 'cable_names'.

I don't get this. The idea is to allocate the cable names in one call, we have already API for that. The cable names are kept in the struct extcon_cable as before. So, functionally it doesn't change anything, it is a simple cleanup.

Okay, I see now your point. I can redo this a bit better I think.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw

PATCH 9/14 extcon: Use device_match_of_node() helper

In reply to Andy Shevchenko

Instead of open coding, use device_match_of_node() helper.

---
 drivers/extcon/extcon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon.c +1 -1
index a63e7eef02fd..5cadbfc151e6 100644
@@ -1411,7 +1411,7 @@ struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
 
 	mutex_lock(&extcon_dev_list_lock);
 	list_for_each_entry(edev, &extcon_dev_list, entry)
-		if (edev->dev.parent && edev->dev.parent->of_node == node)
+		if (edev->dev.parent && device_match_of_node(edev->dev.parent, node))
 			goto out;
 	edev = ERR_PTR(-EPROBE_DEFER);
 out:
Signature · 1 line
2.40.0.1.gaa8946217a0b
#21 lore raw

Re: [PATCH v1 09/14] extcon: Use device_match_of_node() helper

Quoted 12 lines · Andy Shevchenko

Instead of open coding, use device_match_of_node() helper.

---
 drivers/extcon/extcon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon.c +0 -0
index a63e7eef02fd..5cadbfc151e6 100644

drivers/extcon/extcon.c struct extcon_dev *extcon_find_edev_by_node(struct device_node *node) · line 1417

Quoted 8 lines
drivers/extcon/extcon.c +1 -1
@@ -1411,7 +1411,7 @@ struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
 
 	mutex_lock(&extcon_dev_list_lock);
 	list_for_each_entry(edev, &extcon_dev_list, entry)
-		if (edev->dev.parent && edev->dev.parent->of_node == node)
+		if (edev->dev.parent && device_match_of_node(edev->dev.parent, node))
 			goto out;
 	edev = ERR_PTR(-EPROBE_DEFER);
 out:

Applied it.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#22 lore raw

PATCH 10/14 extcon: use dev_of_node(dev) instead of dev->of_node

In reply to Andy Shevchenko

The dev_of_node function should be preferred.
In the result we may drop unneeded NULL check
of the pointer to the device object.

---
 drivers/extcon/extcon.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/extcon/extcon.c +4 -8
index 5cadbfc151e6..32e96cb49067 100644
@@ -1429,21 +1429,17 @@ struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
  */
 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
 {
-	struct device_node *node;
+	struct device_node *node, *np = dev_of_node(dev);
 	struct extcon_dev *edev;
 
-	if (!dev)
-		return ERR_PTR(-EINVAL);
-
-	if (!dev->of_node) {
+	if (!np) {
 		dev_dbg(dev, "device does not have a device node entry\n");
 		return ERR_PTR(-EINVAL);
 	}
 
-	node = of_parse_phandle(dev->of_node, "extcon", index);
+	node = of_parse_phandle(np, "extcon", index);
 	if (!node) {
-		dev_dbg(dev, "failed to get phandle in %pOF node\n",
-			dev->of_node);
+		dev_dbg(dev, "failed to get phandle in %pOF node\n", np);
 		return ERR_PTR(-ENODEV);
 	}
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
#23 lore raw

Re: [PATCH v1 10/14] extcon: use dev_of_node(dev) instead of dev->of_node

Quoted 29 lines · Andy Shevchenko

The dev_of_node function should be preferred.
In the result we may drop unneeded NULL check
of the pointer to the device object.

---
 drivers/extcon/extcon.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/extcon/extcon.c +2 -5
index 5cadbfc151e6..32e96cb49067 100644
@@ -1429,21 +1429,17 @@ struct extcon_dev *extcon_find_edev_by_node(struct device_node *node)
  */
 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
 {
-	struct device_node *node;
+	struct device_node *node, *np = dev_of_node(dev);
 	struct extcon_dev *edev;
 
-	if (!dev)
-		return ERR_PTR(-EINVAL);
-
-	if (!dev->of_node) {
+	if (!np) {
 		dev_dbg(dev, "device does not have a device node entry\n");
 		return ERR_PTR(-EINVAL);
 	}

drivers/extcon/extcon.c struct extcon_dev *extcon_find_edev_by_node(struct device_node *node) · line 1445

Quoted 10 lines
drivers/extcon/extcon.c +2 -3
 
-	node = of_parse_phandle(dev->of_node, "extcon", index);
+	node = of_parse_phandle(np, "extcon", index);
 	if (!node) {
-		dev_dbg(dev, "failed to get phandle in %pOF node\n",
-			dev->of_node);
+		dev_dbg(dev, "failed to get phandle in %pOF node\n", np);
 		return ERR_PTR(-ENODEV);
 	}
 

Applied it with the following patch title. Just use capital letter at the beginning char of title

- extcon: Use dev_of_node(dev) instead of dev->of_node

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#24 lore raw

PATCH 11/14 extcon: Remove dup device name in the message and unneeded error check

In reply to Andy Shevchenko

The device name is already printed with dev_err(), no need to repeat. The device pointer itself is not supposed to be an error point, drop that check.

---
 drivers/extcon/extcon.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/extcon/extcon.c +2 -3
index 32e96cb49067..0e04ea185c26 100644
@@ -1367,9 +1367,8 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 	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));
+	if (!get_device(&edev->dev)) {
+		dev_err(&edev->dev, "Failed to unregister extcon_dev\n");
 		return;
 	}
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
Applied
#25 lore raw

Re: [PATCH v1 11/14] extcon: Remove dup device name in the message and unneeded error check

Quoted 15 lines · Andy Shevchenko

The device name is already printed with dev_err(), no need to repeat. The device pointer itself is not supposed to be an error point, drop that check.

---
 drivers/extcon/extcon.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/extcon/extcon.c +0 -0
index 32e96cb49067..0e04ea185c26 100644
@@ -1367,9 +1367,8 @@ void extcon_dev_unregister(struct extcon_dev *edev)
 	list_del(&edev->entry);

drivers/extcon/extcon.c void extcon_dev_unregister(struct extcon_dev *edev) · line 1374

Quoted 10 lines
drivers/extcon/extcon.c +2 -3
 	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));
+	if (!get_device(&edev->dev)) {
+		dev_err(&edev->dev, "Failed to unregister extcon_dev\n");
 		return;
 	}
 

Applied it. Thanks.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#26 lore raw

PATCH 12/14 extcon: Use sizeof(*pointer) instead of sizeof(type)

In reply to Andy Shevchenko

It is preferred to use sizeof(*pointer) instead of sizeof(type). The type of the variable can change and one needs not change the former (unlike the latter). No functional change intended.

---
 drivers/extcon/extcon.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/extcon/extcon.c +6 -11
index 0e04ea185c26..b3f038639cd6 100644
@@ -1099,9 +1099,7 @@ static int extcon_alloc_cables(struct extcon_dev *edev)
 	if (!edev->max_supported)
 		return 0;
 
-	edev->cables = kcalloc(edev->max_supported,
-			       sizeof(struct extcon_cable),
-			       GFP_KERNEL);
+	edev->cables = kcalloc(edev->max_supported, sizeof(*edev->cables), GFP_KERNEL);
 	if (!edev->cables)
 		return -ENOMEM;
 
@@ -1160,14 +1158,12 @@ static int extcon_alloc_muex(struct extcon_dev *edev)
 	for (index = 0; edev->mutually_exclusive[index]; index++)
 		;
 
-	edev->attrs_muex = kcalloc(index + 1,
-				   sizeof(struct attribute *),
+	edev->attrs_muex = kcalloc(index + 1, sizeof(*edev->attrs_muex),
 				   GFP_KERNEL);
 	if (!edev->attrs_muex)
 		return -ENOMEM;
 
-	edev->d_attrs_muex = kcalloc(index,
-				     sizeof(struct device_attribute),
+	edev->d_attrs_muex = kcalloc(index, sizeof(*edev->d_attrs_muex),
 				     GFP_KERNEL);
 	if (!edev->d_attrs_muex) {
 		kfree(edev->attrs_muex);
@@ -1213,8 +1209,8 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
 		return 0;
 
 	edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2,
-			sizeof(struct attribute_group *),
-			GFP_KERNEL);
+					       sizeof(*edev->extcon_dev_type.groups),
+					       GFP_KERNEL);
 	if (!edev->extcon_dev_type.groups)
 		return -ENOMEM;
 
@@ -1298,8 +1294,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 
 	spin_lock_init(&edev->lock);
 	if (edev->max_supported) {
-		edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
-				GFP_KERNEL);
+		edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), GFP_KERNEL);
 		if (!edev->nh) {
 			ret = -ENOMEM;
 			goto err_alloc_nh;
Signature · 1 line
2.40.0.1.gaa8946217a0b
#27 lore raw

Re: [PATCH v1 12/14] extcon: Use sizeof(*pointer) instead of sizeof(type)

Quoted 14 lines · Andy Shevchenko

It is preferred to use sizeof(*pointer) instead of sizeof(type). The type of the variable can change and one needs not change the former (unlike the latter). No functional change intended.

---
 drivers/extcon/extcon.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/extcon/extcon.c +0 -0
index 0e04ea185c26..b3f038639cd6 100644

drivers/extcon/extcon.c static int extcon_alloc_cables(struct extcon_dev *edev) · line 1102

Quoted 7 lines
drivers/extcon/extcon.c +1 -3
@@ -1099,9 +1099,7 @@ static int extcon_alloc_cables(struct extcon_dev *edev)
 	if (!edev->max_supported)
 		return 0;
 
-	edev->cables = kcalloc(edev->max_supported,
-			       sizeof(struct extcon_cable),
-			       GFP_KERNEL);
+	edev->cables = kcalloc(edev->max_supported, sizeof(*edev->cables), GFP_KERNEL);

Even if there are strictly not limitation of the number of maximum char at the one line, But, I recommend to keep the 80 char at the one line for the readability as following.

- edev->cables = kcalloc(edev->max_supported, sizeof(*edev->cables), GFP_KERNEL);
+ edev->cables = kcalloc(edev->max_supported,
+ sizeof(*edev->cables), GFP_KERNEL);

Quoted 21 lines
drivers/extcon/extcon.c +2 -4
 	if (!edev->cables)
 		return -ENOMEM;
 
@@ -1160,14 +1158,12 @@ static int extcon_alloc_muex(struct extcon_dev *edev)
 	for (index = 0; edev->mutually_exclusive[index]; index++)
 		;
 
-	edev->attrs_muex = kcalloc(index + 1,
-				   sizeof(struct attribute *),
+	edev->attrs_muex = kcalloc(index + 1, sizeof(*edev->attrs_muex),
 				   GFP_KERNEL);
 	if (!edev->attrs_muex)
 		return -ENOMEM;
 
-	edev->d_attrs_muex = kcalloc(index,
-				     sizeof(struct device_attribute),
+	edev->d_attrs_muex = kcalloc(index, sizeof(*edev->d_attrs_muex),
 				     GFP_KERNEL);
 	if (!edev->d_attrs_muex) {
 		kfree(edev->attrs_muex);

drivers/extcon/extcon.c static int extcon_alloc_groups(struct extcon_dev *edev) · line 1213

Quoted 7 lines
drivers/extcon/extcon.c +2 -2
@@ -1213,8 +1209,8 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
 		return 0;
 
 	edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2,
-			sizeof(struct attribute_group *),
-			GFP_KERNEL);
+					       sizeof(*edev->extcon_dev_type.groups),
+					       GFP_KERNEL);

ditto.

        edev->extcon_dev_type.groups = kcalloc(edev->max_supported + 2,

- sizeof(*edev->extcon_dev_type.groups),
- GFP_KERNEL);
+ sizeof(*edev->extcon_dev_type.groups),
+ GFP_KERNEL);

drivers/extcon/extcon.c int extcon_dev_register(struct extcon_dev *edev) · line 1297

Quoted 10 lines
drivers/extcon/extcon.c +1 -2
 	if (!edev->extcon_dev_type.groups)
 		return -ENOMEM;
 
@@ -1298,8 +1294,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 
 	spin_lock_init(&edev->lock);
 	if (edev->max_supported) {
-		edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh),
-				GFP_KERNEL);
+		edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), GFP_KERNEL);

- edev->nh = kcalloc(edev->max_supported, sizeof(*edev->nh), GFP_KERNEL);
+ edev->nh = kcalloc(edev->max_supported,
+ sizeof(*edev->nh), GFP_KERNEL);

Quoted 3 lines
drivers/extcon/extcon.c +0 -0
 		if (!edev->nh) {
 			ret = -ENOMEM;
 			goto err_alloc_nh;
Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#28 lore raw

PATCH 13/14 extcon: Drop unneeded assignments

In reply to Andy Shevchenko

In one case the assignment is duplicative, in the other, it's better to move it into the loop — the user of it.

---
 drivers/extcon/extcon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/extcon/extcon.c +3 -3
index b3f038639cd6..edfa0450e605 100644
@@ -246,7 +246,7 @@ static DEFINE_MUTEX(extcon_dev_list_lock);
 
 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
 {
-	int i = 0;
+	int i;
 
 	if (!edev->mutually_exclusive)
 		return 0;
@@ -1244,7 +1244,7 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
  */
 int extcon_dev_register(struct extcon_dev *edev)
 {
-	int ret, index = 0;
+	int ret, index;
 
 	ret = create_extcon_class();
 	if (ret < 0)
@@ -1253,7 +1253,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 	if (!edev || !edev->supported_cable)
 		return -EINVAL;
 
-	for (; edev->supported_cable[index] != EXTCON_NONE; index++);
+	for (index = 0; edev->supported_cable[index] != EXTCON_NONE; index++);
 
 	edev->max_supported = index;
 	if (index > SUPPORTED_CABLE_MAX) {
Signature · 1 line
2.40.0.1.gaa8946217a0b
Acked-by on v1 13/14
#29 lore raw

Re: [PATCH v1 13/14] extcon: Drop unneeded assignments

Quoted 31 lines · Andy Shevchenko

In one case the assignment is duplicative, in the other, it's better to move it into the loop — the user of it.

---
 drivers/extcon/extcon.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/extcon/extcon.c +2 -2
index b3f038639cd6..edfa0450e605 100644
@@ -246,7 +246,7 @@ static DEFINE_MUTEX(extcon_dev_list_lock);
 
 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
 {
-	int i = 0;
+	int i;
 
 	if (!edev->mutually_exclusive)
 		return 0;
@@ -1244,7 +1244,7 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
  */
 int extcon_dev_register(struct extcon_dev *edev)
 {
-	int ret, index = 0;
+	int ret, index;
 
 	ret = create_extcon_class();
 	if (ret < 0)

drivers/extcon/extcon.c int extcon_dev_register(struct extcon_dev *edev) · line 1259

Quoted 8 lines
drivers/extcon/extcon.c +1 -1
@@ -1253,7 +1253,7 @@ int extcon_dev_register(struct extcon_dev *edev)
 	if (!edev || !edev->supported_cable)
 		return -EINVAL;
 
-	for (; edev->supported_cable[index] != EXTCON_NONE; index++);
+	for (index = 0; edev->supported_cable[index] != EXTCON_NONE; index++);
 
 	edev->max_supported = index;
 	if (index > SUPPORTED_CABLE_MAX) {

It has the dependency with patch7. When I try to apply it, the conflict happen. When you are sending v2 patches, I'll apply it if there are no conflict.
[1] [PATCH v1 07/14] extcon: Use unique number for the extcon device ID

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#30 lore raw

PATCH 14/14 extcon: Use positive conditional in ternary operator

In reply to Andy Shevchenko

It's easier to parse by a human being the positive conditional.

---
 drivers/extcon/extcon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon.c +1 -1
index edfa0450e605..3e8522d522b4 100644
@@ -1466,7 +1466,7 @@ EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle);
  */
 const char *extcon_get_edev_name(struct extcon_dev *edev)
 {
-	return !edev ? NULL : edev->name;
+	return edev ? edev->name : NULL;
 }
 EXPORT_SYMBOL_GPL(extcon_get_edev_name);
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
#31 lore raw

Re: [PATCH v1 14/14] extcon: Use positive conditional in ternary operator

Quoted 12 lines · Andy Shevchenko

It's easier to parse by a human being the positive conditional.

---
 drivers/extcon/extcon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon.c +0 -0
index edfa0450e605..3e8522d522b4 100644

drivers/extcon/extcon.c EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); · line 1472

Quoted 8 lines
drivers/extcon/extcon.c +1 -1
@@ -1466,7 +1466,7 @@ EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle);
  */
 const char *extcon_get_edev_name(struct extcon_dev *edev)
 {
-	return !edev ? NULL : edev->name;
+	return edev ? edev->name : NULL;
 }
 EXPORT_SYMBOL_GPL(extcon_get_edev_name);
 

It is not fix-up patch and I'm not sure that it is beneficial patch. I will not apply it.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#32 lore raw

Re: [PATCH v1 14/14] extcon: Use positive conditional in ternary operator

Quoted 2 lines · Chanwoo Choi
Quoted 1 line · Andy Shevchenko

It's easier to parse by a human being the positive conditional.

...

Quoted 9 lines

drivers/extcon/extcon.c EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); · line 1471

Quoted 6 lines

const char *extcon_get_edev_name(struct extcon_dev *edev) {

drivers/extcon/extcon.c +1 -1
-	return !edev ? NULL : edev->name;
+	return edev ? edev->name : NULL;
 }
 EXPORT_SYMBOL_GPL(extcon_get_edev_name);

It is not fix-up patch and I'm not sure that it is beneficial patch. I will not apply it.

It improves the cognitive perception of the code, but I'm fine with no patch being applied.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#33 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

A few fixes to the documentation and some cleanups against extcon core module.

Anything I should do with the series?
Any comments on it?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by
#34 lore raw

Hi Andy Shevchenko

Quoted 13 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, March 30, 2023 7:12 PM
To: Bumwoo Lee <[email protected]>; [email protected]
Cc: MyungJoo Ham <[email protected]>; Chanwoo Choi <[email protected]>
Subject: Re: [PATCH v1 00/14] extcon: Core cleanups and documentation fixes

Quoted 2 lines · Andy Shevchenko

A few fixes to the documentation and some cleanups against extcon core module.

Quoted 7 lines

Anything I should do with the series?
Any comments on it?

--
With Best Regards,
Andy Shevchenko

Looks fine to me.

MR. Chanwoo, Would you please take a look at this patch series.

#35 lore raw

Hi,

Quoted 22 lines · Bumwoo Lee

Hi Andy Shevchenko

Quoted 13 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, March 30, 2023 7:12 PM
To: Bumwoo Lee <[email protected]>; [email protected]
Cc: MyungJoo Ham <[email protected]>; Chanwoo Choi <[email protected]>
Subject: Re: [PATCH v1 00/14] extcon: Core cleanups and documentation fixes

Quoted 2 lines · Andy Shevchenko

A few fixes to the documentation and some cleanups against extcon core module.

Quoted 7 lines

Anything I should do with the series?
Any comments on it?

--
With Best Regards,
Andy Shevchenko

Quoted 6 lines

Looks fine to me.

MR. Chanwoo, Would you please take a look at this patch series.

Actually, Acked tag will be replied by Maintainer or the driver owner. If you want to review the mailing list patch, I think that Reviewed-by tag is proper.

Unfortunately, I could not see the any review comment from you even if this patchset have the some review contents. Also you didn't review the any patches of extcon before.

I'm always welcome for many reviewers in order to improve the linux kernel. But, in this case, I'm not sure that you are reviewing this patchset.

So that I'm sorry that I cannot take your acked-tag.

Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#36 lore raw

Hi

Quoted 37 lines

-----Original Message-----
From: Chanwoo Choi <[email protected]>
Sent: Thursday, April 6, 2023 8:17 AM
To: Bumwoo Lee <[email protected]>; 'Andy Shevchenko' <[email protected]>; [email protected]
Cc: 'MyungJoo Ham' <[email protected]>; 'Chanwoo Choi' <[email protected]>
Subject: Re: [PATCH v1 00/14] extcon: Core cleanups and documentation fixes

Hi,

Quoted 24 lines · Bumwoo Lee

Hi Andy Shevchenko

Quoted 13 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Thursday, March 30, 2023 7:12 PM
To: Bumwoo Lee <[email protected]>; [email protected]
Cc: MyungJoo Ham <[email protected]>; Chanwoo Choi <[email protected]>
Subject: Re: [PATCH v1 00/14] extcon: Core cleanups and documentation fixes

Quoted 2 lines · Andy Shevchenko

A few fixes to the documentation and some cleanups against extcon core module.

Quoted 7 lines

Anything I should do with the series?
Any comments on it?

--
With Best Regards,
Andy Shevchenko

Looks fine to me.

Quoted 9 lines
Quoted 4 lines

MR. Chanwoo, Would you please take a look at this patch series.

Actually, Acked tag will be replied by Maintainer or the driver owner. If you want to review the mailing list patch, I think that Reviewed-by tag is proper.

OK.
Thank you for your detail guidance. I will follow this guidance on next time.

Quoted 9 lines

Unfortunately, I could not see the any review comment from you even if this patchset have the some review contents. Also you didn't review the any patches of extcon before.

I'm always welcome for many reviewers in order to improve the linux kernel. But, in this case, I'm not sure that you are reviewing this patchset.

So that I'm sorry that I cannot take your acked-tag.

I agree your comment.
Thank you~

Quoted 4 lines

--
Best Regards,
Samsung Electronics
Chanwoo Choi

#37 lore raw
In reply to Chanwoo Choi
Quoted 1 line · Chanwoo Choi

On 23. 3. 31. 09:48, Bumwoo Lee wrote:

...

Quoted 10 lines
Quoted 5 lines

Looks fine to me.

MR. Chanwoo, Would you please take a look at this patch series.

Actually, Acked tag will be replied by Maintainer or the driver owner. If you want to review the mailing list patch, I think that Reviewed-by tag is proper.

Quoted 8 lines

Unfortunately, I could not see the any review comment from you even if this patchset have the some review contents. Also you didn't review the any patches of extcon before.

I'm always welcome for many reviewers in order to improve the linux kernel. But, in this case, I'm not sure that you are reviewing this patchset.

So that I'm sorry that I cannot take your acked-tag.

I probably need to update this in the v3 of the rest of the patches I have sent as v2. Btw, can you review those before, so if any comments I can address in v3?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#38 lore raw
In reply to Andy Shevchenko

Hi,

I recommend that use the "./scripts/get_maintainer.pl" script to get the accurate maintainer list to send the patches.

Quoted 23 lines · Andy Shevchenko

A few fixes to the documentation and some cleanups against extcon core module.

Andy Shevchenko (14):
extcon: Fix kernel doc of property fields to avoid warnings
extcon: Fix kernel doc of property capability fields to avoid warnings
extcon: Use DECLARE_BITMAP() to declare bit arrays
extcon: use sysfs_emit() to instead of sprintf()
extcon: Amend kernel documentation of struct extcon_dev
extcon: Allow name to be assigned outside of the framework
extcon: Use unique number for the extcon device ID
extcon: Switch to use kasprintf_strarray()
extcon: Use device_match_of_node() helper
extcon: use dev_of_node(dev) instead of dev->of_node
extcon: Remove dup device name in the message and unneeded error check
extcon: Use sizeof(*pointer) instead of sizeof(type)
extcon: Drop unneeded assignments
extcon: Use positive conditional in ternary operator

 drivers/extcon/extcon.c | 126 +++++++++++++++++++++-------------------
 drivers/extcon/extcon.h |   9 ++-
 2 files changed, 71 insertions(+), 64 deletions(-)
Signature · 3 lines
Best Regards,
Samsung Electronics
Chanwoo Choi
#39 lore raw
Quoted 4 lines · Chanwoo Choi

Hi,

I recommend that use the "./scripts/get_maintainer.pl" script to get the accurate maintainer list to send the patches.

That's what I'm using. What's wrong in your opinion with the Cc and/or To lists?

Quoted 19 lines · Andy Shevchenko
Quoted 18 lines

A few fixes to the documentation and some cleanups against extcon core module.

Andy Shevchenko (14):
extcon: Fix kernel doc of property fields to avoid warnings
extcon: Fix kernel doc of property capability fields to avoid warnings
extcon: Use DECLARE_BITMAP() to declare bit arrays
extcon: use sysfs_emit() to instead of sprintf()
extcon: Amend kernel documentation of struct extcon_dev
extcon: Allow name to be assigned outside of the framework
extcon: Use unique number for the extcon device ID
extcon: Switch to use kasprintf_strarray()
extcon: Use device_match_of_node() helper
extcon: use dev_of_node(dev) instead of dev->of_node
extcon: Remove dup device name in the message and unneeded error check
extcon: Use sizeof(*pointer) instead of sizeof(type)
extcon: Drop unneeded assignments
extcon: Use positive conditional in ternary operator

Signature · 2 lines
With Best Regards,
Andy Shevchenko