From: Olivier Sobrie <olivier@sobrie.be>
To: Marc Kleine-Budde <mkl@pengutronix.de>, linux-can@vger.kernel.org
Cc: Greg KH <gregkh@linuxfoundation.org>,
Wolfgang Grandegge <wg@grandegger.com>,
netdev@vger.kernel.org, linux-usb@vger.kernel.org,
Daniel Berglund <db@kvaser.com>
Subject: Re: [PATCH] kvaser_usb: fix "dma on the stack" errors
Date: Fri, 23 Nov 2012 14:40:27 +0100 [thread overview]
Message-ID: <20121123134027.GA32098@hposo> (raw)
In-Reply-To: <1353677428-15805-1-git-send-email-olivier@sobrie.be>
On Fri, Nov 23, 2012 at 02:30:28PM +0100, Olivier Sobrie wrote:
> The dma buffer given to usb_bulk_msg() must be allocated and not on
> the stack.
> See Documentation/DMA-API-HOWTO.txt section "What memory is DMA'able?"
>
> Signed-off-by: Olivier Sobrie <olivier@sobrie.be>
> ---
> Here is the incremental patch.
> Thank you Greg !
>
> Olivier
>
> drivers/net/can/usb/kvaser_usb.c | 110 ++++++++++++++++++++++++--------------
> 1 file changed, 69 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/net/can/usb/kvaser_usb.c b/drivers/net/can/usb/kvaser_usb.c
> index 8807bf8..7ac6e82 100644
> --- a/drivers/net/can/usb/kvaser_usb.c
> +++ b/drivers/net/can/usb/kvaser_usb.c
> @@ -421,14 +421,21 @@ end:
> static int kvaser_usb_send_simple_msg(const struct kvaser_usb *dev,
> u8 msg_id, int channel)
> {
> - struct kvaser_msg msg = {
> - .len = MSG_HEADER_LEN + sizeof(struct kvaser_msg_simple),
> - .id = msg_id,
> - .u.simple.channel = channel,
> - .u.simple.tid = 0xff,
> - };
> -
> - return kvaser_usb_send_msg(dev, &msg);
> + struct kvaser_msg *msg;
> + int rc;
> +
> + msg = kmalloc(sizeof(*msg), GFP_KERNEL);
> + if (!msg)
> + return -ENOMEM;
> +
Doh! I removed by mistake the line "msg->id = msg_id"... grr
> + msg->len = MSG_HEADER_LEN + sizeof(struct kvaser_msg_simple);
> + msg->u.simple.channel = channel;
> + msg->u.simple.tid = 0xff;
> +
> + rc = kvaser_usb_send_msg(dev, msg);
> +
> + kfree(msg);
> + return rc;
> }
>
> static int kvaser_usb_get_software_info(struct kvaser_usb *dev)
> @@ -1057,20 +1064,27 @@ static int kvaser_usb_setup_rx_urbs(struct kvaser_usb *dev)
>
> static int kvaser_usb_set_opt_mode(const struct kvaser_usb_net_priv *priv)
> {
> - struct kvaser_msg msg = {
> - .id = CMD_SET_CTRL_MODE,
> - .len = MSG_HEADER_LEN +
> - sizeof(struct kvaser_msg_ctrl_mode),
> - .u.ctrl_mode.tid = 0xff,
> - .u.ctrl_mode.channel = priv->channel,
> - };
> + struct kvaser_msg *msg;
> + int rc;
> +
> + msg = kmalloc(sizeof(*msg), GFP_KERNEL);
> + if (!msg)
> + return -ENOMEM;
> +
> + msg->id = CMD_SET_CTRL_MODE;
> + msg->len = MSG_HEADER_LEN + sizeof(struct kvaser_msg_ctrl_mode);
> + msg->u.ctrl_mode.tid = 0xff;
> + msg->u.ctrl_mode.channel = priv->channel;
>
> if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
> - msg.u.ctrl_mode.ctrl_mode = KVASER_CTRL_MODE_SILENT;
> + msg->u.ctrl_mode.ctrl_mode = KVASER_CTRL_MODE_SILENT;
> else
> - msg.u.ctrl_mode.ctrl_mode = KVASER_CTRL_MODE_NORMAL;
> + msg->u.ctrl_mode.ctrl_mode = KVASER_CTRL_MODE_NORMAL;
> +
> + rc = kvaser_usb_send_msg(priv->dev, msg);
>
> - return kvaser_usb_send_msg(priv->dev, &msg);
> + kfree(msg);
> + return rc;
> }
>
> static int kvaser_usb_start_chip(struct kvaser_usb_net_priv *priv)
> @@ -1163,15 +1177,22 @@ static int kvaser_usb_stop_chip(struct kvaser_usb_net_priv *priv)
>
> static int kvaser_usb_flush_queue(struct kvaser_usb_net_priv *priv)
> {
> - struct kvaser_msg msg = {
> - .id = CMD_FLUSH_QUEUE,
> - .len = MSG_HEADER_LEN +
> - sizeof(struct kvaser_msg_flush_queue),
> - .u.flush_queue.channel = priv->channel,
> - .u.flush_queue.flags = 0x00,
> - };
> -
> - return kvaser_usb_send_msg(priv->dev, &msg);
> + struct kvaser_msg *msg;
> + int rc;
> +
> + msg = kmalloc(sizeof(*msg), GFP_KERNEL);
> + if (!msg)
> + return -ENOMEM;
> +
> + msg->id = CMD_FLUSH_QUEUE;
> + msg->len = MSG_HEADER_LEN + sizeof(struct kvaser_msg_flush_queue);
> + msg->u.flush_queue.channel = priv->channel;
> + msg->u.flush_queue.flags = 0x00;
> +
> + rc = kvaser_usb_send_msg(priv->dev, msg);
> +
> + kfree(msg);
> + return rc;
> }
>
> static int kvaser_usb_close(struct net_device *netdev)
> @@ -1364,24 +1385,31 @@ static int kvaser_usb_set_bittiming(struct net_device *netdev)
> struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
> struct can_bittiming *bt = &priv->can.bittiming;
> struct kvaser_usb *dev = priv->dev;
> - struct kvaser_msg msg = {
> - .id = CMD_SET_BUS_PARAMS,
> - .len = MSG_HEADER_LEN +
> - sizeof(struct kvaser_msg_busparams),
> - .u.busparams.channel = priv->channel,
> - .u.busparams.tid = 0xff,
> - .u.busparams.bitrate = cpu_to_le32(bt->bitrate),
> - .u.busparams.sjw = bt->sjw,
> - .u.busparams.tseg1 = bt->prop_seg + bt->phase_seg1,
> - .u.busparams.tseg2 = bt->phase_seg2,
> - };
> + struct kvaser_msg *msg;
> + int rc;
> +
> + msg = kmalloc(sizeof(*msg), GFP_KERNEL);
> + if (!msg)
> + return -ENOMEM;
> +
> + msg->id = CMD_SET_BUS_PARAMS;
> + msg->len = MSG_HEADER_LEN + sizeof(struct kvaser_msg_busparams);
> + msg->u.busparams.channel = priv->channel;
> + msg->u.busparams.tid = 0xff;
> + msg->u.busparams.bitrate = cpu_to_le32(bt->bitrate);
> + msg->u.busparams.sjw = bt->sjw;
> + msg->u.busparams.tseg1 = bt->prop_seg + bt->phase_seg1;
> + msg->u.busparams.tseg2 = bt->phase_seg2;
>
> if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
> - msg.u.busparams.no_samp = 3;
> + msg->u.busparams.no_samp = 3;
> else
> - msg.u.busparams.no_samp = 1;
> + msg->u.busparams.no_samp = 1;
> +
> + rc = kvaser_usb_send_msg(dev, msg);
>
> - return kvaser_usb_send_msg(dev, &msg);
> + kfree(msg);
> + return rc;
> }
>
> static int kvaser_usb_set_mode(struct net_device *netdev,
> --
> 1.7.9.5
>
--
Olivier
next prev parent reply other threads:[~2012-11-23 13:40 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-30 5:32 [PATCH] can: kvaser_usb: Add support for Kvaser CAN/USB devices Olivier Sobrie
2012-07-30 11:11 ` Marc Kleine-Budde
2012-07-30 13:33 ` Olivier Sobrie
2012-07-31 9:56 ` Marc Kleine-Budde
2012-07-31 13:06 ` Olivier Sobrie
2012-07-31 13:27 ` Marc Kleine-Budde
2012-08-02 10:53 ` Olivier Sobrie
2012-08-02 11:56 ` Marc Kleine-Budde
2012-08-02 12:16 ` Olivier Sobrie
2012-08-02 12:33 ` Marc Kleine-Budde
2012-08-02 13:20 ` Olivier Sobrie
2012-08-05 20:43 ` Wolfgang Grandegger
2012-08-06 5:27 ` Olivier Sobrie
2012-07-31 13:43 ` Wolfgang Grandegger
2012-08-05 20:41 ` Wolfgang Grandegger
2012-08-06 5:21 ` [PATCH v2] " Olivier Sobrie
2012-08-06 8:10 ` Oliver Neukum
2012-08-08 5:28 ` Olivier Sobrie
2012-08-07 6:26 ` Wolfgang Grandegger
2012-08-08 6:14 ` Olivier Sobrie
2012-08-08 8:25 ` Wolfgang Grandegger
[not found] ` <5022227F.60800-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2012-08-08 13:30 ` Olivier Sobrie
2012-08-08 15:02 ` Wolfgang Grandegger
2012-08-13 13:51 ` [PATCH v3] " Olivier Sobrie
2012-09-20 5:06 ` [PATCH v4] " Olivier Sobrie
[not found] ` <1348117587-2905-1-git-send-email-olivier-Ui3EtX6WB9GzQB+pC5nmwQ@public.gmane.org>
2012-09-21 9:54 ` Marc Kleine-Budde
2012-09-22 16:02 ` Wolfgang Grandegger
[not found] ` <505DE106.6060405-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2012-10-02 7:14 ` Olivier Sobrie
2012-10-02 7:16 ` [PATCH v5] " Olivier Sobrie
2012-11-07 20:29 ` Marc Kleine-Budde
2012-11-20 8:46 ` Olivier Sobrie
2012-11-20 10:59 ` Marc Kleine-Budde
[not found] ` <1343626352-24760-1-git-send-email-olivier-Ui3EtX6WB9GzQB+pC5nmwQ@public.gmane.org>
2012-11-21 7:11 ` [PATCH v6] " Olivier Sobrie
2012-11-22 11:01 ` Marc Kleine-Budde
2012-11-22 15:01 ` Olivier Sobrie
2012-11-22 21:30 ` Greg KH
2012-11-23 8:48 ` Marc Kleine-Budde
2012-11-23 13:30 ` [PATCH] kvaser_usb: fix "dma on the stack" errors Olivier Sobrie
2012-11-23 13:40 ` Olivier Sobrie [this message]
2012-11-23 13:48 ` Marc Kleine-Budde
2012-11-23 13:54 ` [PATCH v2] " Olivier Sobrie
2012-11-23 14:08 ` Marc Kleine-Budde
2012-11-23 14:16 ` Olivier Sobrie
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=20121123134027.GA32098@hposo \
--to=olivier@sobrie.be \
--cc=db@kvaser.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=wg@grandegger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.