linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: common: usb-conn-gpio: use a unique names for usb connector devices
@ 2025-04-11  3:27 Chance Yang
  2025-04-11  5:55 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Chance Yang @ 2025-04-11  3:27 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Chunfeng Yun
  Cc: linux-usb, linux-kernel, morgan.chang, Chance Yang

The current implementation uses "usb-charger" as a generic name for
usb connector. This prevents us to have two usb connector devices
attached as the power system will complain about the name which is
already registered.

Use an incremental name for each usb connector attached.

Fixes: 880287910b189 ("usb: common: usb-conn-gpio: fix NULL pointer dereference of charger")
Signed-off-by: Chance Yang <chance.yang@kneron.us>
---
This patch addresses an issue in the usb-conn-gpio driver where the
generic "usb-charger" name is used for all USB connector devices. This
causes conflicts in the power supply subsystem when multiple USB
connectors are present, as duplicate names are not allowed.

The fix introduces an incremental naming scheme (e.g., usb-charger-0,
usb-charger-1) for each USB connector device, ensuring uniqueness and
preventing registration errors.
---
 drivers/usb/common/usb-conn-gpio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
index 1e36be2a28fd5ca5e1495b7923e4d3e25d7cedef..2702e1a26634770500febd567f9d0891e63a8c4c 100644
--- a/drivers/usb/common/usb-conn-gpio.c
+++ b/drivers/usb/common/usb-conn-gpio.c
@@ -155,13 +155,19 @@ static int usb_charger_get_property(struct power_supply *psy,
 
 static int usb_conn_psy_register(struct usb_conn_info *info)
 {
+	static atomic_t usb_conn_no = ATOMIC_INIT(0);
+	unsigned long n;
 	struct device *dev = info->dev;
 	struct power_supply_desc *desc = &info->desc;
 	struct power_supply_config cfg = {
 		.fwnode = dev_fwnode(dev),
 	};
 
-	desc->name = "usb-charger";
+	n = atomic_inc_return(&usb_conn_no) - 1;
+	desc->name = devm_kasprintf(dev, GFP_KERNEL, "usb-charger-%ld", n);
+	if (!desc->name)
+		return -ENOMEM;
+
 	desc->properties = usb_charger_properties;
 	desc->num_properties = ARRAY_SIZE(usb_charger_properties);
 	desc->get_property = usb_charger_get_property;

---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250411-work-next-d817787d63f2

Best regards,
-- 
Chance Yang <chance.yang@kneron.us>


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

* Re: [PATCH] usb: common: usb-conn-gpio: use a unique names for usb connector devices
  2025-04-11  3:27 [PATCH] usb: common: usb-conn-gpio: use a unique names for usb connector devices Chance Yang
@ 2025-04-11  5:55 ` Greg Kroah-Hartman
  2025-04-11  6:45   ` Chance Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2025-04-11  5:55 UTC (permalink / raw)
  To: Chance Yang; +Cc: Chunfeng Yun, linux-usb, linux-kernel, morgan.chang

On Fri, Apr 11, 2025 at 11:27:33AM +0800, Chance Yang wrote:
> The current implementation uses "usb-charger" as a generic name for
> usb connector. This prevents us to have two usb connector devices
> attached as the power system will complain about the name which is
> already registered.
> 
> Use an incremental name for each usb connector attached.
> 
> Fixes: 880287910b189 ("usb: common: usb-conn-gpio: fix NULL pointer dereference of charger")
> Signed-off-by: Chance Yang <chance.yang@kneron.us>
> ---
> This patch addresses an issue in the usb-conn-gpio driver where the
> generic "usb-charger" name is used for all USB connector devices. This
> causes conflicts in the power supply subsystem when multiple USB
> connectors are present, as duplicate names are not allowed.
> 
> The fix introduces an incremental naming scheme (e.g., usb-charger-0,
> usb-charger-1) for each USB connector device, ensuring uniqueness and
> preventing registration errors.
> ---
>  drivers/usb/common/usb-conn-gpio.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
> index 1e36be2a28fd5ca5e1495b7923e4d3e25d7cedef..2702e1a26634770500febd567f9d0891e63a8c4c 100644
> --- a/drivers/usb/common/usb-conn-gpio.c
> +++ b/drivers/usb/common/usb-conn-gpio.c
> @@ -155,13 +155,19 @@ static int usb_charger_get_property(struct power_supply *psy,
>  
>  static int usb_conn_psy_register(struct usb_conn_info *info)
>  {
> +	static atomic_t usb_conn_no = ATOMIC_INIT(0);

Please use a proper data structure for this (hint, not an atomic_t, but
rather a idr, or is it ida?)

thanks,

greg k-h

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

* Re: [PATCH] usb: common: usb-conn-gpio: use a unique names for usb connector devices
  2025-04-11  5:55 ` Greg Kroah-Hartman
@ 2025-04-11  6:45   ` Chance Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Chance Yang @ 2025-04-11  6:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Chunfeng Yun, linux-usb, linux-kernel, morgan.chang

Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

> On Fri, Apr 11, 2025 at 11:27:33AM +0800, Chance Yang wrote:
>> The current implementation uses "usb-charger" as a generic name for
>> usb connector. This prevents us to have two usb connector devices
>> attached as the power system will complain about the name which is
>> already registered.
>> 
>> Use an incremental name for each usb connector attached.
>> 
>> Fixes: 880287910b189 ("usb: common: usb-conn-gpio: fix NULL pointer dereference of charger")
>> Signed-off-by: Chance Yang <chance.yang@kneron.us>
>> ---
>> This patch addresses an issue in the usb-conn-gpio driver where the
>> generic "usb-charger" name is used for all USB connector devices. This
>> causes conflicts in the power supply subsystem when multiple USB
>> connectors are present, as duplicate names are not allowed.
>> 
>> The fix introduces an incremental naming scheme (e.g., usb-charger-0,
>> usb-charger-1) for each USB connector device, ensuring uniqueness and
>> preventing registration errors.
>> ---
>>  drivers/usb/common/usb-conn-gpio.c | 8 +++++++-
>>  1 file changed, 7 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c
>> index 1e36be2a28fd5ca5e1495b7923e4d3e25d7cedef..2702e1a26634770500febd567f9d0891e63a8c4c 100644
>> --- a/drivers/usb/common/usb-conn-gpio.c
>> +++ b/drivers/usb/common/usb-conn-gpio.c
>> @@ -155,13 +155,19 @@ static int usb_charger_get_property(struct power_supply *psy,
>>  
>>  static int usb_conn_psy_register(struct usb_conn_info *info)
>>  {
>> +	static atomic_t usb_conn_no = ATOMIC_INIT(0);
>
> Please use a proper data structure for this (hint, not an atomic_t, but
> rather a idr, or is it ida?)
>
> thanks,
>
> greg k-h

Thanks for the feedback !

I will use ida to genrate unique name (e.g., usb-charger-0,
usb-charger-1) and send v2 version of this patch.


-- 
Sincerely,
Chance Yang

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

end of thread, other threads:[~2025-04-11  6:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11  3:27 [PATCH] usb: common: usb-conn-gpio: use a unique names for usb connector devices Chance Yang
2025-04-11  5:55 ` Greg Kroah-Hartman
2025-04-11  6:45   ` Chance Yang

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