Skip to contentSkip to conversation

usb: hub: Set proper message when usb_hub_create_port_device() fails

PATCH Superseded Chen-Yu Tsai 3 participants 4 messages Oct 12 USB

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 usb: hub: Set proper message when usb_hub_create_port_device() fails

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.

Set |message| to an error message that is more specific to this error path instead of using the default "out of memory" message.

Assisted-by LLM # local reviews

---
Changes since v3:
- Print custom error message directly and use generic error message for later, instead of using more stack space

Changes since v2:
- Simplify to just using a small buffer on the stack (Alan)

Changes since v1:
- Explicitly track and free the allocated custom error message instead of using devm_kasprintf()
- Link to v1:
https://lore.kernel.org/all/[email protected]/

Sorry Andy, I ended up not using your __free(kfree_const) patch. My LLM was telling me that it won't work correctly if CONFIG_USB=m.

---
 drivers/usb/core/hub.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/core/hub.c +1 -0
index 0e929a4c9fa1..4c85fdf7a233 100644
@@ -1758,6 +1758,7 @@ static int hub_configure(struct usb_hub *hub,
 		if (ret < 0) {
 			dev_err(hub->intfdev,
 				"couldn't create port%d device.\n", i + 1);
+			message = "couldn't create port device";
 			break;
 		}
 	}
Signature · 1 line
2.56.0.385.gd3acb90ef8-goog
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

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.

Set |message| to an error message that is more specific to this error path instead of using the default "out of memory" message.

Assisted-by LLM # local reviews

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Chen-Yu Tsai
Quoted 6 lines · Chen-Yu Tsai

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.

Set |message| to an error message that is more specific to this error path instead of using the default "out of memory" message.

...

drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1762

Quoted 5 lines
drivers/usb/core/hub.c +1 -0
 		if (ret < 0) {
 			dev_err(hub->intfdev,
 				"couldn't create port%d device.\n", i + 1);
+			message = "couldn't create port device";
 			break;

We can now even use

			message = "couldn't create port device";
			dev_err(hub->intfdev, "%s %d.\n", message, + 1);
Quoted 1 line

}

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 1 line · Andy Shevchenko

On Mon, Oct 12, 2026 at 05:27:24PM +0800, Chen-Yu Tsai wrote:

...

Quoted 10 lines

drivers/usb/core/hub.c static int hub_configure(struct usb_hub *hub, · line 1762

Quoted 5 lines
drivers/usb/core/hub.c +1 -0
 		if (ret < 0) {
 			dev_err(hub->intfdev,
 				"couldn't create port%d device.\n", i + 1);
+			message = "couldn't create port device";
 			break;

We can now even use

			message = "couldn't create port device";
			dev_err(hub->intfdev, "%s %d.\n", message, + 1);

Of course this has to be

			dev_err(hub->intfdev, "%s %d.\n", message, i + 1);

but in any case it's up to you depending on the template used for the rest of the messages in this function.

Quoted 1 line
Quoted 1 line

}

Signature · 2 lines
With Best Regards,
Andy Shevchenko