Re: [PATCH v2] usbcore: Add quirk for 255-bytes initial config read

From: Alan Stern

Date: Mon Jun 29 2026 - 13:03:15 EST


On Mon, Jun 29, 2026 at 11:00:44AM +0530, Nikhil Solanke wrote:
> On that note, I discovered that usb_get_descriptor just blindly trusts
> the caller with the allocation of buf, it never checks if buf is null
> or not. There is only a check for the size. and then there is a
> memset(buf, 0, size). This results in a segfault if buf is NULL and
> size > 0. Perhaps it's time for a new patch to fix this?

There's nothing wrong with trusting the caller to do the right thing.
Besides, if a segfault does occur then it will be pretty obvious that
the caller needs to be fixed.

What would you do if buf is NULL? Return an error code? That won't
help anyone locate the bug. Put an error message in the log? Segfaults
are much more visible.

Not to mention that nobody has complained about this code failing, so it
seems unlikely that buf ever is NULL.

Alan Stern