[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20170423173140.5538-1-maksim.salau@gmail.com>
Date: Sun, 23 Apr 2017 20:31:40 +0300
From: Maksim Salau <maksim.salau@...il.com>
To: Wolfgang Grandegger <wg@...ndegger.com>,
Marc Kleine-Budde <mkl@...gutronix.de>,
Maximilian Schneider <max@...neidersoft.net>,
Hubert Denkmair <hubert@...kmair.de>,
Wolfram Sang <wsa-dev@...g-engineering.com>,
Ethan Zonca <e@...anzonca.com>, linux-can@...r.kernel.org,
netdev@...r.kernel.org, Fabio Estevam <festevam@...il.com>
Cc: Maksim Salau <maksim.salau@...il.com>
Subject: [PATCH v2] net: can: usb: gs_usb: Fix buffer on stack
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@...il.com>
---
Changes in v2:
dropped redundant assignment.
drivers/net/can/usb/gs_usb.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 300349f..eecee7f 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -739,13 +739,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),
@@ -755,10 +760,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;
}
--
2.9.3
Powered by blists - more mailing lists