Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: hub: Set proper message when usb_hub_create_port_device() fails
@ 2026-07-28 10:00 Chen-Yu Tsai
  2026-08-10 16:31 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Chen-Yu Tsai @ 2026-07-28 10:00 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Chen-Yu Tsai, Bartosz Golaszewski, Andy Shevchenko, linux-usb,
	linux-kernel

Right now when usb_hub_create_port_device() fails, it prints a separate
error message to say which port failed, but otherwise leaves 'message'
set to the default "out of memory", which is somewhat misleading.

Allocate some memory and put the currently separate error message in
it, and use it as the error message. If the allocation fails, use a
generic version of the error message. The allocation uses devres
helpers, and will be freed after the message is printed and the device
is cleaned up.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/usb/core/hub.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index b09b43669658..fc4879d9c623 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1751,8 +1751,15 @@ static int hub_configure(struct usb_hub *hub,
 	for (i = 0; i < maxchild; i++) {
 		ret = usb_hub_create_port_device(hub, i + 1);
 		if (ret < 0) {
-			dev_err(hub->intfdev,
-				"couldn't create port%d device.\n", i + 1);
+			char *msg;
+
+			msg = devm_kasprintf(hub->intfdev, GFP_KERNEL,
+					     "couldn't create port%d device",
+					     i + 1);
+			if (msg)
+				message = msg;
+			else
+				message = "couldn't create port device";
 			break;
 		}
 	}
-- 
2.55.0.229.g6434b31f56-goog


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

* Re: [PATCH] usb: hub: Set proper message when usb_hub_create_port_device() fails
  2026-07-28 10:00 [PATCH] usb: hub: Set proper message when usb_hub_create_port_device() fails Chen-Yu Tsai
@ 2026-08-10 16:31 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2026-08-10 16:31 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Greg Kroah-Hartman, Bartosz Golaszewski, linux-usb, linux-kernel

On Tue, Jul 28, 2026 at 06:00:04PM +0800, Chen-Yu Tsai wrote:
> Right now when usb_hub_create_port_device() fails, it prints a separate
> error message to say which port failed, but otherwise leaves 'message'
> set to the default "out of memory", which is somewhat misleading.
> 
> Allocate some memory and put the currently separate error message in
> it, and use it as the error message. If the allocation fails, use a
> generic version of the error message. The allocation uses devres
> helpers, and will be freed after the message is printed and the device
> is cleaned up.

The 'message' is local to the function, why devm?
Shouldn't __free() be sufficient?

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2026-08-10 16:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 10:00 [PATCH] usb: hub: Set proper message when usb_hub_create_port_device() fails Chen-Yu Tsai
2026-08-10 16:31 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox