Skip to content

Commit 3776c78

Browse files
shuahkhgregkh
authored andcommitted
misc: rtsx_usb: use separate command and response buffers
rtsx_usb uses same buffer for command and response. There could be a potential conflict using the same buffer for both especially if retries and timeouts are involved. Use separate command and response buffers to avoid conflicts. Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Cc: stable <stable@kernel.org> Link: https://lore.kernel.org/r/07e3721804ff07aaab9ef5b39a5691d0718b9ade.1656642167.git.skhan@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent eb7f8e2 commit 3776c78

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

drivers/misc/cardreader/rtsx_usb.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,18 @@ static int rtsx_usb_probe(struct usb_interface *intf,
631631

632632
ucr->pusb_dev = usb_dev;
633633

634-
ucr->iobuf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
635-
if (!ucr->iobuf)
634+
ucr->cmd_buf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
635+
if (!ucr->cmd_buf)
636636
return -ENOMEM;
637637

638+
ucr->rsp_buf = kmalloc(IOBUF_SIZE, GFP_KERNEL);
639+
if (!ucr->rsp_buf)
640+
goto out_free_cmd_buf;
641+
638642
usb_set_intfdata(intf, ucr);
639643

640644
ucr->vendor_id = id->idVendor;
641645
ucr->product_id = id->idProduct;
642-
ucr->cmd_buf = ucr->rsp_buf = ucr->iobuf;
643646

644647
mutex_init(&ucr->dev_mutex);
645648

@@ -667,9 +670,11 @@ static int rtsx_usb_probe(struct usb_interface *intf,
667670

668671
out_init_fail:
669672
usb_set_intfdata(ucr->pusb_intf, NULL);
670-
kfree(ucr->iobuf);
671-
ucr->iobuf = NULL;
672-
ucr->cmd_buf = ucr->rsp_buf = NULL;
673+
kfree(ucr->rsp_buf);
674+
ucr->rsp_buf = NULL;
675+
out_free_cmd_buf:
676+
kfree(ucr->cmd_buf);
677+
ucr->cmd_buf = NULL;
673678
return ret;
674679
}
675680

@@ -682,9 +687,12 @@ static void rtsx_usb_disconnect(struct usb_interface *intf)
682687
mfd_remove_devices(&intf->dev);
683688

684689
usb_set_intfdata(ucr->pusb_intf, NULL);
685-
kfree(ucr->iobuf);
686-
ucr->iobuf = NULL;
687-
ucr->cmd_buf = ucr->rsp_buf = NULL;
690+
691+
kfree(ucr->cmd_buf);
692+
ucr->cmd_buf = NULL;
693+
694+
kfree(ucr->rsp_buf);
695+
ucr->rsp_buf = NULL;
688696
}
689697

690698
#ifdef CONFIG_PM

include/linux/rtsx_usb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ struct rtsx_ucr {
5454
struct usb_device *pusb_dev;
5555
struct usb_interface *pusb_intf;
5656
struct usb_sg_request current_sg;
57-
unsigned char *iobuf;
5857

5958
struct timer_list sg_timer;
6059
struct mutex dev_mutex;

0 commit comments

Comments
 (0)