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

From: Greg Kroah-Hartman

Date: Fri Jul 10 2026 - 09:17:27 EST


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