Skip to content

Commit

Permalink
net: can: usb: gs_usb: Fix buffer on stack
Browse files Browse the repository at this point in the history
commit b05c73b upstream.

Allocate buffers on HEAP instead of STACK for local structures
that are to be sent using usb_control_msg().

Signed-off-by: Maksim Salau <maksim.salau@gmail.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Maksim Salau authored and Greg Kroah-Hartman committed May 3, 2017
1 parent 43a35e6 commit bd7c4f5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions drivers/net/can/usb/gs_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,18 @@ static const struct net_device_ops gs_usb_netdev_ops = {
static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
{
struct gs_can *dev = netdev_priv(netdev);
struct gs_identify_mode imode;
struct gs_identify_mode *imode;
int rc;

imode = kmalloc(sizeof(*imode), GFP_KERNEL);

if (!imode)
return -ENOMEM;

if (do_identify)
imode.mode = GS_CAN_IDENTIFY_ON;
imode->mode = GS_CAN_IDENTIFY_ON;
else
imode.mode = GS_CAN_IDENTIFY_OFF;
imode->mode = GS_CAN_IDENTIFY_OFF;

rc = usb_control_msg(interface_to_usbdev(dev->iface),
usb_sndctrlpipe(interface_to_usbdev(dev->iface),
Expand All @@ -756,10 +761,12 @@ static int gs_usb_set_identify(struct net_device *netdev, bool do_identify)
USB_RECIP_INTERFACE,
dev->channel,
0,
&imode,
sizeof(imode),
imode,
sizeof(*imode),
100);

kfree(imode);

return (rc > 0) ? 0 : rc;
}

Expand Down

0 comments on commit bd7c4f5

Please sign in to comment.