Re: [PATCH] usb: core: devio: validate device and interface before buffer allocation

From: Andre Moreira

Date: Fri Jul 10 2026 - 16:34:27 EST


Thanks, Greg! Glad to help.

Em sex., 10 de jul. de 2026 às 10:14, Greg Kroah-Hartman
<gregkh@xxxxxxxxxxxxxxxxxxx> escreveu:
>
> On Tue, Jun 23, 2026 at 11:35:31PM -0300, André Moreira wrote:
> > The proc_ioctl() function currently allocates a buffer using kmalloc()
> > before checking the USB device state and resolving the interface number.
> > If either validation fails, the function must free the buffer and return
> > an error.
> >
> > Move these checks to the top of the function to fail early. This avoids
> > unnecessary memory allocation and deallocation on error paths, removes
> > the nested 'else' structure, and eliminates redundant kfree() calls,
> > making the code cleaner and easier to maintain.
>
> Nice find and cleanup, thanks!
>
> greg k-h