On Wed, Apr 06, 2022 at 06:02:59PM +0800, Lin Ma wrote: > The function rio_karam_init() should return USB_STOR_TRANSPORT_ERROR > instead of 0 (USB_STOR_TRANSPORT_GOOD) when allocation fails. Not exactly. rio_karma_init() is a usb-storage initFunction (see the usb_stor_acquire_resources() routine in usb.c), and these functions are supposed to return either 0 or a negative error code. So you should make the routine return -ENOMEM, not USB_STOR_TRANSPORT_ERROR. You can simplify the patch by changing the line where ret is defined; initialize it to -ENOMEM rather than to 0. And don't forget the error code for when the rio_karma_send_command() call fails. In that case the return value should be -EIO. > Fixes: dfe0d3ba20e8 ("USB Storage: add rio karma eject support") Shouldn't this also be marked for the stable kernels? Alan Stern > Signed-off-by: Lin Ma <linma@xxxxxxxxxx> > --- > drivers/usb/storage/karma.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c > index 05cec81dcd3f..b8a4ae1aa22a 100644 > --- a/drivers/usb/storage/karma.c > +++ b/drivers/usb/storage/karma.c > @@ -178,19 +178,19 @@ static int rio_karma_init(struct us_data *us) > struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO); > > if (!data) > - goto out; > + return USB_STOR_TRANSPORT_ERROR; > > data->recv = kmalloc(RIO_RECV_LEN, GFP_NOIO); > if (!data->recv) { > kfree(data); > - goto out; > + return USB_STOR_TRANSPORT_ERROR; > } > > us->extra = data; > us->extra_destructor = rio_karma_destructor; > ret = rio_karma_send_command(RIO_ENTER_STORAGE, us); > data->in_storage = (ret == 0); > -out: > + > return ret; > } > > -- > 2.35.1 >