Commit fae37f81 authored by Olivier Sobrie's avatar Olivier Sobrie Committed by Marc Kleine-Budde

net: can: esd_usb2: Do not do dma on the stack

smatch reports the following warnings:
drivers/net/can/usb/esd_usb2.c:640 esd_usb2_start() error: doing dma on the stack (&msg)
drivers/net/can/usb/esd_usb2.c:846 esd_usb2_close() error: doing dma on the stack (&msg)
drivers/net/can/usb/esd_usb2.c:855 esd_usb2_close() error: doing dma on the stack (&msg)
drivers/net/can/usb/esd_usb2.c:923 esd_usb2_set_bittiming() error: doing dma on the stack (&msg)
drivers/net/can/usb/esd_usb2.c:1047 esd_usb2_probe() error: doing dma on the stack (&msg)
drivers/net/can/usb/esd_usb2.c:1053 esd_usb2_probe() error: doing dma on the stack (&msg)

See "Documentation/DMA-API-HOWTO.txt" section "What memory is DMA'able?"
Signed-off-by: default avatarOlivier Sobrie <olivier@sobrie.be>
Cc: Matthias Fuchs <matthias.fuchs@esd.eu>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent a90f13b2
...@@ -612,9 +612,15 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) ...@@ -612,9 +612,15 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv)
{ {
struct esd_usb2 *dev = priv->usb2; struct esd_usb2 *dev = priv->usb2;
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
struct esd_usb2_msg msg; struct esd_usb2_msg *msg;
int err, i; int err, i;
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
if (!msg) {
err = -ENOMEM;
goto out;
}
/* /*
* Enable all IDs * Enable all IDs
* The IDADD message takes up to 64 32 bit bitmasks (2048 bits). * The IDADD message takes up to 64 32 bit bitmasks (2048 bits).
...@@ -628,33 +634,32 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv) ...@@ -628,33 +634,32 @@ static int esd_usb2_start(struct esd_usb2_net_priv *priv)
* the number of the starting bitmask (0..64) to the filter.option * the number of the starting bitmask (0..64) to the filter.option
* field followed by only some bitmasks. * field followed by only some bitmasks.
*/ */
msg.msg.hdr.cmd = CMD_IDADD; msg->msg.hdr.cmd = CMD_IDADD;
msg.msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; msg->msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT;
msg.msg.filter.net = priv->index; msg->msg.filter.net = priv->index;
msg.msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ msg->msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */
for (i = 0; i < ESD_MAX_ID_SEGMENT; i++) for (i = 0; i < ESD_MAX_ID_SEGMENT; i++)
msg.msg.filter.mask[i] = cpu_to_le32(0xffffffff); msg->msg.filter.mask[i] = cpu_to_le32(0xffffffff);
/* enable 29bit extended IDs */ /* enable 29bit extended IDs */
msg.msg.filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001); msg->msg.filter.mask[ESD_MAX_ID_SEGMENT] = cpu_to_le32(0x00000001);
err = esd_usb2_send_msg(dev, &msg); err = esd_usb2_send_msg(dev, msg);
if (err) if (err)
goto failed; goto out;
err = esd_usb2_setup_rx_urbs(dev); err = esd_usb2_setup_rx_urbs(dev);
if (err) if (err)
goto failed; goto out;
priv->can.state = CAN_STATE_ERROR_ACTIVE; priv->can.state = CAN_STATE_ERROR_ACTIVE;
return 0; out:
failed:
if (err == -ENODEV) if (err == -ENODEV)
netif_device_detach(netdev); netif_device_detach(netdev);
if (err)
netdev_err(netdev, "couldn't start device: %d\n", err);
netdev_err(netdev, "couldn't start device: %d\n", err); kfree(msg);
return err; return err;
} }
...@@ -833,26 +838,30 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb, ...@@ -833,26 +838,30 @@ static netdev_tx_t esd_usb2_start_xmit(struct sk_buff *skb,
static int esd_usb2_close(struct net_device *netdev) static int esd_usb2_close(struct net_device *netdev)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb2_net_priv *priv = netdev_priv(netdev);
struct esd_usb2_msg msg; struct esd_usb2_msg *msg;
int i; int i;
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
if (!msg)
return -ENOMEM;
/* Disable all IDs (see esd_usb2_start()) */ /* Disable all IDs (see esd_usb2_start()) */
msg.msg.hdr.cmd = CMD_IDADD; msg->msg.hdr.cmd = CMD_IDADD;
msg.msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT; msg->msg.hdr.len = 2 + ESD_MAX_ID_SEGMENT;
msg.msg.filter.net = priv->index; msg->msg.filter.net = priv->index;
msg.msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */ msg->msg.filter.option = ESD_ID_ENABLE; /* start with segment 0 */
for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++) for (i = 0; i <= ESD_MAX_ID_SEGMENT; i++)
msg.msg.filter.mask[i] = 0; msg->msg.filter.mask[i] = 0;
if (esd_usb2_send_msg(priv->usb2, &msg) < 0) if (esd_usb2_send_msg(priv->usb2, msg) < 0)
netdev_err(netdev, "sending idadd message failed\n"); netdev_err(netdev, "sending idadd message failed\n");
/* set CAN controller to reset mode */ /* set CAN controller to reset mode */
msg.msg.hdr.len = 2; msg->msg.hdr.len = 2;
msg.msg.hdr.cmd = CMD_SETBAUD; msg->msg.hdr.cmd = CMD_SETBAUD;
msg.msg.setbaud.net = priv->index; msg->msg.setbaud.net = priv->index;
msg.msg.setbaud.rsvd = 0; msg->msg.setbaud.rsvd = 0;
msg.msg.setbaud.baud = cpu_to_le32(ESD_USB2_NO_BAUDRATE); msg->msg.setbaud.baud = cpu_to_le32(ESD_USB2_NO_BAUDRATE);
if (esd_usb2_send_msg(priv->usb2, &msg) < 0) if (esd_usb2_send_msg(priv->usb2, msg) < 0)
netdev_err(netdev, "sending setbaud message failed\n"); netdev_err(netdev, "sending setbaud message failed\n");
priv->can.state = CAN_STATE_STOPPED; priv->can.state = CAN_STATE_STOPPED;
...@@ -861,6 +870,8 @@ static int esd_usb2_close(struct net_device *netdev) ...@@ -861,6 +870,8 @@ static int esd_usb2_close(struct net_device *netdev)
close_candev(netdev); close_candev(netdev);
kfree(msg);
return 0; return 0;
} }
...@@ -886,7 +897,8 @@ static int esd_usb2_set_bittiming(struct net_device *netdev) ...@@ -886,7 +897,8 @@ static int esd_usb2_set_bittiming(struct net_device *netdev)
{ {
struct esd_usb2_net_priv *priv = netdev_priv(netdev); struct esd_usb2_net_priv *priv = netdev_priv(netdev);
struct can_bittiming *bt = &priv->can.bittiming; struct can_bittiming *bt = &priv->can.bittiming;
struct esd_usb2_msg msg; struct esd_usb2_msg *msg;
int err;
u32 canbtr; u32 canbtr;
int sjw_shift; int sjw_shift;
...@@ -912,15 +924,22 @@ static int esd_usb2_set_bittiming(struct net_device *netdev) ...@@ -912,15 +924,22 @@ static int esd_usb2_set_bittiming(struct net_device *netdev)
if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
canbtr |= ESD_USB2_3_SAMPLES; canbtr |= ESD_USB2_3_SAMPLES;
msg.msg.hdr.len = 2; msg = kmalloc(sizeof(*msg), GFP_KERNEL);
msg.msg.hdr.cmd = CMD_SETBAUD; if (!msg)
msg.msg.setbaud.net = priv->index; return -ENOMEM;
msg.msg.setbaud.rsvd = 0;
msg.msg.setbaud.baud = cpu_to_le32(canbtr); msg->msg.hdr.len = 2;
msg->msg.hdr.cmd = CMD_SETBAUD;
msg->msg.setbaud.net = priv->index;
msg->msg.setbaud.rsvd = 0;
msg->msg.setbaud.baud = cpu_to_le32(canbtr);
netdev_info(netdev, "setting BTR=%#x\n", canbtr); netdev_info(netdev, "setting BTR=%#x\n", canbtr);
return esd_usb2_send_msg(priv->usb2, &msg); err = esd_usb2_send_msg(priv->usb2, msg);
kfree(msg);
return err;
} }
static int esd_usb2_get_berr_counter(const struct net_device *netdev, static int esd_usb2_get_berr_counter(const struct net_device *netdev,
...@@ -1022,7 +1041,7 @@ static int esd_usb2_probe(struct usb_interface *intf, ...@@ -1022,7 +1041,7 @@ static int esd_usb2_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
struct esd_usb2 *dev; struct esd_usb2 *dev;
struct esd_usb2_msg msg; struct esd_usb2_msg *msg;
int i, err; int i, err;
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
...@@ -1037,27 +1056,33 @@ static int esd_usb2_probe(struct usb_interface *intf, ...@@ -1037,27 +1056,33 @@ static int esd_usb2_probe(struct usb_interface *intf,
usb_set_intfdata(intf, dev); usb_set_intfdata(intf, dev);
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
if (!msg) {
err = -ENOMEM;
goto free_msg;
}
/* query number of CAN interfaces (nets) */ /* query number of CAN interfaces (nets) */
msg.msg.hdr.cmd = CMD_VERSION; msg->msg.hdr.cmd = CMD_VERSION;
msg.msg.hdr.len = 2; msg->msg.hdr.len = 2;
msg.msg.version.rsvd = 0; msg->msg.version.rsvd = 0;
msg.msg.version.flags = 0; msg->msg.version.flags = 0;
msg.msg.version.drv_version = 0; msg->msg.version.drv_version = 0;
err = esd_usb2_send_msg(dev, &msg); err = esd_usb2_send_msg(dev, msg);
if (err < 0) { if (err < 0) {
dev_err(&intf->dev, "sending version message failed\n"); dev_err(&intf->dev, "sending version message failed\n");
goto free_dev; goto free_msg;
} }
err = esd_usb2_wait_msg(dev, &msg); err = esd_usb2_wait_msg(dev, msg);
if (err < 0) { if (err < 0) {
dev_err(&intf->dev, "no version message answer\n"); dev_err(&intf->dev, "no version message answer\n");
goto free_dev; goto free_msg;
} }
dev->net_count = (int)msg.msg.version_reply.nets; dev->net_count = (int)msg->msg.version_reply.nets;
dev->version = le32_to_cpu(msg.msg.version_reply.version); dev->version = le32_to_cpu(msg->msg.version_reply.version);
if (device_create_file(&intf->dev, &dev_attr_firmware)) if (device_create_file(&intf->dev, &dev_attr_firmware))
dev_err(&intf->dev, dev_err(&intf->dev,
...@@ -1075,10 +1100,10 @@ static int esd_usb2_probe(struct usb_interface *intf, ...@@ -1075,10 +1100,10 @@ static int esd_usb2_probe(struct usb_interface *intf,
for (i = 0; i < dev->net_count; i++) for (i = 0; i < dev->net_count; i++)
esd_usb2_probe_one_net(intf, i); esd_usb2_probe_one_net(intf, i);
return 0; free_msg:
kfree(msg);
free_dev: if (err)
kfree(dev); kfree(dev);
done: done:
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment