From: Maksim Salau <maksim.salau@gmail.com>
To: Wolfgang Grandegger <wg@grandegger.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Maximilian Schneider <max@schneidersoft.net>,
Hubert Denkmair <hubert@denkmair.de>,
Wolfram Sang <wsa-dev@sang-engineering.com>,
Ethan Zonca <e@ethanzonca.com>,
linux-can@vger.kernel.org, netdev@vger.kernel.org
Cc: Maksim Salau <maksim.salau@gmail.com>
Subject: [PATCH] net: can: usb: gs_usb: Fix buffer on stack
Date: Sat, 22 Apr 2017 19:56:26 +0300 [thread overview]
Message-ID: <20170422165626.10534-1-maksim.salau@gmail.com> (raw)
Allocate buffer on HEAP instead of STACK for a local structure
that is to be sent using usb_control_msg().
Signed-off-by: Maksim Salau <maksim.salau@gmail.com>
---
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 a0dabd4..98f972a 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -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 = NULL;
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),
@@ -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;
}
--
2.9.3
next reply other threads:[~2017-04-22 16:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-22 16:56 Maksim Salau [this message]
2017-04-22 17:30 ` [PATCH] net: can: usb: gs_usb: Fix buffer on stack Fabio Estevam
2017-04-23 17:18 ` Maksim Salau
2017-04-23 17:31 ` [PATCH v2] " Maksim Salau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170422165626.10534-1-maksim.salau@gmail.com \
--to=maksim.salau@gmail.com \
--cc=e@ethanzonca.com \
--cc=hubert@denkmair.de \
--cc=linux-can@vger.kernel.org \
--cc=max@schneidersoft.net \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=wg@grandegger.com \
--cc=wsa-dev@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox