Skip to content

Commit c919a30

Browse files
Ethan Zoncamarckleinebudde
authored andcommitted
can: gs_usb: Don't use stack memory for USB transfers
Fixes: 05ca527 can: gs_usb: add ethtool set_phys_id callback to locate physical device The gs_usb driver is performing USB transfers using buffers allocated on the stack. This causes the driver to not function with vmapped stacks. Instead, allocate memory for the transfer buffers. Signed-off-by: Ethan Zonca <[email protected]> Cc: linux-stable <[email protected]> # >= v4.8 Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 9f674e4 commit c919a30

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

drivers/net/can/usb/gs_usb.c

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,14 @@ static int gs_usb_probe(struct usb_interface *intf,
908908
struct gs_usb *dev;
909909
int rc = -ENOMEM;
910910
unsigned int icount, i;
911-
struct gs_host_config hconf = {
912-
.byte_order = 0x0000beef,
913-
};
914-
struct gs_device_config dconf;
911+
struct gs_host_config *hconf;
912+
struct gs_device_config *dconf;
913+
914+
hconf = kmalloc(sizeof(*hconf), GFP_KERNEL);
915+
if (!hconf)
916+
return -ENOMEM;
917+
918+
hconf->byte_order = 0x0000beef;
915919

916920
/* send host config */
917921
rc = usb_control_msg(interface_to_usbdev(intf),
@@ -920,45 +924,56 @@ static int gs_usb_probe(struct usb_interface *intf,
920924
USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
921925
1,
922926
intf->altsetting[0].desc.bInterfaceNumber,
923-
&hconf,
924-
sizeof(hconf),
927+
hconf,
928+
sizeof(*hconf),
925929
1000);
926930

931+
kfree(hconf);
932+
927933
if (rc < 0) {
928934
dev_err(&intf->dev, "Couldn't send data format (err=%d)\n",
929935
rc);
930936
return rc;
931937
}
932938

939+
dconf = kmalloc(sizeof(*dconf), GFP_KERNEL);
940+
if (!dconf)
941+
return -ENOMEM;
942+
933943
/* read device config */
934944
rc = usb_control_msg(interface_to_usbdev(intf),
935945
usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
936946
GS_USB_BREQ_DEVICE_CONFIG,
937947
USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
938948
1,
939949
intf->altsetting[0].desc.bInterfaceNumber,
940-
&dconf,
941-
sizeof(dconf),
950+
dconf,
951+
sizeof(*dconf),
942952
1000);
943953
if (rc < 0) {
944954
dev_err(&intf->dev, "Couldn't get device config: (err=%d)\n",
945955
rc);
956+
kfree(dconf);
946957
return rc;
947958
}
948959

949-
icount = dconf.icount + 1;
960+
icount = dconf->icount + 1;
950961
dev_info(&intf->dev, "Configuring for %d interfaces\n", icount);
951962

952963
if (icount > GS_MAX_INTF) {
953964
dev_err(&intf->dev,
954965
"Driver cannot handle more that %d CAN interfaces\n",
955966
GS_MAX_INTF);
967+
kfree(dconf);
956968
return -EINVAL;
957969
}
958970

959971
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
960-
if (!dev)
972+
if (!dev) {
973+
kfree(dconf);
961974
return -ENOMEM;
975+
}
976+
962977
init_usb_anchor(&dev->rx_submitted);
963978

964979
atomic_set(&dev->active_channels, 0);
@@ -967,7 +982,7 @@ static int gs_usb_probe(struct usb_interface *intf,
967982
dev->udev = interface_to_usbdev(intf);
968983

969984
for (i = 0; i < icount; i++) {
970-
dev->canch[i] = gs_make_candev(i, intf, &dconf);
985+
dev->canch[i] = gs_make_candev(i, intf, dconf);
971986
if (IS_ERR_OR_NULL(dev->canch[i])) {
972987
/* save error code to return later */
973988
rc = PTR_ERR(dev->canch[i]);
@@ -978,12 +993,15 @@ static int gs_usb_probe(struct usb_interface *intf,
978993
gs_destroy_candev(dev->canch[i]);
979994

980995
usb_kill_anchored_urbs(&dev->rx_submitted);
996+
kfree(dconf);
981997
kfree(dev);
982998
return rc;
983999
}
9841000
dev->canch[i]->parent = dev;
9851001
}
9861002

1003+
kfree(dconf);
1004+
9871005
return 0;
9881006
}
9891007

0 commit comments

Comments
 (0)