Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: storage: karma: fix rio_karma_init return

The function rio_karam_init() should return -ENOMEM instead of
value 0 (USB_STOR_TRANSPORT_GOOD) when allocation fails.

Similarly, it should return -EIO when rio_karma_send_command() fails.

Fixes: dfe0d3ba20e8 ("USB Storage: add rio karma eject support")
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Link: https://lore.kernel.org/r/20220412144359.28447-1-linma@zju.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Lin Ma and committed by
Greg Kroah-Hartman
b92ffb1e 67ec2c75

+8 -7
+8 -7
drivers/usb/storage/karma.c
··· 174 174 175 175 static int rio_karma_init(struct us_data *us) 176 176 { 177 - int ret = 0; 178 177 struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO); 179 178 180 179 if (!data) 181 - goto out; 180 + return -ENOMEM; 182 181 183 182 data->recv = kmalloc(RIO_RECV_LEN, GFP_NOIO); 184 183 if (!data->recv) { 185 184 kfree(data); 186 - goto out; 185 + return -ENOMEM; 187 186 } 188 187 189 188 us->extra = data; 190 189 us->extra_destructor = rio_karma_destructor; 191 - ret = rio_karma_send_command(RIO_ENTER_STORAGE, us); 192 - data->in_storage = (ret == 0); 193 - out: 194 - return ret; 190 + if (rio_karma_send_command(RIO_ENTER_STORAGE, us)) 191 + return -EIO; 192 + 193 + data->in_storage = 1; 194 + 195 + return 0; 195 196 } 196 197 197 198 static struct scsi_host_template karma_host_template;