[PATCH] usb: hub: Set proper message when usb_hub_create_port_device() fails
Chen-Yu Tsai <[email protected]>
| Newsgroups | org.kernel.vger.linux-usb,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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