From: Andri Yngvason <andri.yngvason@marel.com>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
Stephane Grosjean <s.grosjean@peak-system.com>
Subject: Re: [PATCH v5] can/peak_usb: add support for PEAK new CANFD USB adapters
Date: Tue, 20 Jan 2015 13:08:46 +0000 [thread overview]
Message-ID: <20150120130846.13173.9714@shannon> (raw)
In-Reply-To: <1421757005-17271-1-git-send-email-s.grosjean@peak-system.com>
Quoting Stephane Grosjean (2015-01-20 12:30:05)
> +/* handle uCAN status message */
> +static int pcan_usb_fd_decode_status(struct pcan_usb_fd_if *usb_if,
> + struct pucan_msg *rx_msg)
> +{
> + struct pucan_status_msg *sm = (struct pucan_status_msg *)rx_msg;
> + struct peak_usb_device *dev = usb_if->dev[pucan_stmsg_get_channel(sm)];
> + struct pcan_usb_fd_device *pdev =
> + container_of(dev, struct pcan_usb_fd_device, dev);
> + enum can_state new_state = CAN_STATE_ERROR_ACTIVE;
> + struct net_device *netdev = dev->netdev;
> + struct can_frame *cf;
> + struct sk_buff *skb = NULL;
> +
> + /* nothing should be sent while in BUS_OFF state */
> + if (dev->can.state == CAN_STATE_BUS_OFF)
> + return 0;
> +
> + if (sm->channel_p_w_b & PUCAN_BUS_BUSOFF) {
> + new_state = CAN_STATE_BUS_OFF;
> + } else if (sm->channel_p_w_b & PUCAN_BUS_PASSIVE) {
> + new_state = CAN_STATE_ERROR_PASSIVE;
> + } else if (sm->channel_p_w_b & PUCAN_BUS_WARNING) {
> + new_state = CAN_STATE_ERROR_WARNING;
> + } else {
> + /* no error bit (so, no error skb, back to active state) */
> + dev->can.state = CAN_STATE_ERROR_ACTIVE;
> + pdev->bec.txerr = 0;
> + pdev->bec.rxerr = 0;
> + return 0;
> + }
> +
> + if (new_state != dev->can.state) {
> + enum can_state rx_state, tx_state;
> +
> + tx_state = (pdev->bec.txerr >= pdev->bec.rxerr) ?
> + new_state : 0;
> + rx_state = (pdev->bec.txerr <= pdev->bec.rxerr) ?
> + new_state : 0;
> +
> + /* allocate an skb to store the error frame */
> + skb = alloc_can_err_skb(netdev, &cf);
> + if (skb)
> + can_change_state(netdev, cf, tx_state, rx_state);
> +
> + if (new_state == CAN_STATE_BUS_OFF)
> + can_bus_off(netdev);
> + }
> +
> + if (!skb)
> + return -ENOMEM;
Consider if new_state != dev->can.state, then skb == NULL, ergo function will
return -ENOMEM here.
> +
> + peak_usb_netif_rx(skb, &usb_if->time_ref,
> + le32_to_cpu(sm->ts_low), le32_to_cpu(sm->ts_high));
Nothing is applied to skb/cf outside of the scope within which it is allocated.
Placing this rx call inside the if-statement's scope would solve the problem
that I described above. The OOM check should of course also be moved into said
scope.
> +
> + netdev->stats.rx_packets++;
> + netdev->stats.rx_bytes += cf->can_dlc;
> +
> + return 0;
> +}
See comments above.
Best regards,
Andri
next prev parent reply other threads:[~2015-01-20 13:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 12:30 [PATCH v5] can/peak_usb: add support for PEAK new CANFD USB adapters Stephane Grosjean
2015-01-20 13:08 ` Andri Yngvason [this message]
2015-01-20 14:21 ` Marc Kleine-Budde
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=20150120130846.13173.9714@shannon \
--to=andri.yngvason@marel.com \
--cc=linux-can@vger.kernel.org \
--cc=s.grosjean@peak-system.com \
--cc=socketcan@hartkopp.net \
/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;
as well as URLs for NNTP newsgroup(s).