Re: [PATCH] usb: hub: Set proper message when usb_hub_create_port_device() fails

Chen-Yu Tsai <[email protected]>
Newsgroups gmane.linux.usb.general,gmane.linux.kernel
Message-ID <CAGXv+5HGZwAKpGpyV4=QHfg7yBQPx-syc1Gma2qad_tzW_RLog@mail.gmail.com>
On Tue, Aug 11, 2026 at 12:31 AM Andy Shevchenko
<andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]> wrote:
>
> 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?

I hadn't thought of that.

The scope shouldn't be a problem, since it's declared and used at the top
level. But we'd need a kfree_const() variant of __free(kfree). All the
other error messages are just plain C string constants.


ChenYu
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.