From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD67D1DB127; Tue, 8 Jul 2025 16:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751993786; cv=none; b=pAMQvNTcpzzgAvyTm6gfG2eRAPqAqDODI1E93o4L+zcyvwhca1u4gvCR0g+1in/IDW8xSv/H18xZI+xpntw5zwLxeIm80DXEsyRvGgDe/fO79nbpMaC6+6UipV8o8S1hHCBQ2nFW2BNj0VUeRrEEH6+k1tDko4atEjNxqUuNwXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751993786; c=relaxed/simple; bh=2NGlPPw4zjKdNWzjKuHE1KRyo+A8C+5HQw6qr+krJhU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AxEAdZfyItUSqvUxbW1BT1CuuAk069cNgnewIZawy5VHNi/dG4g6lcAyg+rjj3buLEGimMfOihIuonxuZ+ZTuhV2AocaGZD5PconFou+pA7DFDlRL/i/aMagLothU/hwAVEKEPclovKJvrYD4I5KORB/t0QOYKc1EM21j704vxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rKHexyh9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rKHexyh9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 446ECC4CEF0; Tue, 8 Jul 2025 16:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1751993786; bh=2NGlPPw4zjKdNWzjKuHE1KRyo+A8C+5HQw6qr+krJhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rKHexyh9JTBjMuw8TQ3dOi/PHLm+1iPbdwdiZqQqXJjZRK/EDGDrEc7Ks30O0bBrE wmWM5LNt2oHFPyR3Mo6xYbvZQK4lOo31q/s7g6d49vzGdFFLj361HZUfkMNA+40yD9 1mWOWjQwQorVQSw8EwT2pHoq9sVv+j/C+CB7QE8U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chance Yang , Sasha Levin Subject: [PATCH 5.15 018/160] usb: common: usb-conn-gpio: use a unique name for usb connector device Date: Tue, 8 Jul 2025 18:20:55 +0200 Message-ID: <20250708162232.012431452@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250708162231.503362020@linuxfoundation.org> References: <20250708162231.503362020@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chance Yang [ Upstream commit d4e5b10c55627e2f3fc9e5b337a28b4e2f02a55e ] The current implementation of the usb-conn-gpio driver uses a fixed "usb-charger" name 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. Use IDA to manage unique IDs for naming usb connectors (e.g., usb-charger-0, usb-charger-1). Signed-off-by: Chance Yang Link: https://lore.kernel.org/r/20250411-work-next-v3-1-7cd9aa80190c@kneron.us Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/common/usb-conn-gpio.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/usb/common/usb-conn-gpio.c b/drivers/usb/common/usb-conn-gpio.c index 521c95935d4c3..9691a1c8d8b0e 100644 --- a/drivers/usb/common/usb-conn-gpio.c +++ b/drivers/usb/common/usb-conn-gpio.c @@ -20,6 +20,9 @@ #include #include #include +#include + +static DEFINE_IDA(usb_conn_ida); #define USB_GPIO_DEB_MS 20 /* ms */ #define USB_GPIO_DEB_US ((USB_GPIO_DEB_MS) * 1000) /* us */ @@ -29,6 +32,7 @@ struct usb_conn_info { struct device *dev; + int conn_id; /* store the IDA-allocated ID */ struct usb_role_switch *role_sw; enum usb_role last_role; struct regulator *vbus; @@ -160,7 +164,17 @@ static int usb_conn_psy_register(struct usb_conn_info *info) .of_node = dev->of_node, }; - desc->name = "usb-charger"; + info->conn_id = ida_alloc(&usb_conn_ida, GFP_KERNEL); + if (info->conn_id < 0) + return info->conn_id; + + desc->name = devm_kasprintf(dev, GFP_KERNEL, "usb-charger-%d", + info->conn_id); + if (!desc->name) { + ida_free(&usb_conn_ida, info->conn_id); + return -ENOMEM; + } + desc->properties = usb_charger_properties; desc->num_properties = ARRAY_SIZE(usb_charger_properties); desc->get_property = usb_charger_get_property; @@ -168,8 +182,10 @@ static int usb_conn_psy_register(struct usb_conn_info *info) cfg.drv_data = info; info->charger = devm_power_supply_register(dev, desc, &cfg); - if (IS_ERR(info->charger)) - dev_err(dev, "Unable to register charger\n"); + if (IS_ERR(info->charger)) { + dev_err(dev, "Unable to register charger %d\n", info->conn_id); + ida_free(&usb_conn_ida, info->conn_id); + } return PTR_ERR_OR_ZERO(info->charger); } @@ -292,6 +308,9 @@ static int usb_conn_remove(struct platform_device *pdev) cancel_delayed_work_sync(&info->dw_det); + if (info->charger) + ida_free(&usb_conn_ida, info->conn_id); + if (info->last_role == USB_ROLE_HOST && info->vbus) regulator_disable(info->vbus); -- 2.39.5