linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Subject: [PATCH 2/4] can: netlink send bittiming data only when bittiming_const is available
Date: Fri, 14 Feb 2014 21:57:25 +0100	[thread overview]
Message-ID: <1392411447-9105-2-git-send-email-socketcan@hartkopp.net> (raw)
In-Reply-To: <1392411447-9105-1-git-send-email-socketcan@hartkopp.net>

The bittiming information is only valid when the CAN driver has a valid
structure of bittiming_const. Therefore provide the information of the
bittiming only when bittiming_const exists.

This is also a preparation for the CAN FD specific bittiming_const structure
which is not existing in non-FD drivers. Therefore all the CAN FD bittiming
stuff has to be disabled when the CAN FD specific bittiming_const structure is
missing.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 drivers/net/can/dev.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index e1a3741..b0b950f 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -719,9 +719,10 @@ static size_t can_get_size(const struct net_device *dev)
 	struct can_priv *priv = netdev_priv(dev);
 	size_t size = 0;
 
-	size += nla_total_size(sizeof(struct can_bittiming));	/* IFLA_CAN_BITTIMING */
-	if (priv->bittiming_const)				/* IFLA_CAN_BITTIMING_CONST */
+	if (priv->bittiming_const) { /* IFLA_CAN_BITTIMING[_CONST] */
+		size += nla_total_size(sizeof(struct can_bittiming));
 		size += nla_total_size(sizeof(struct can_bittiming_const));
+	}
 	size += nla_total_size(sizeof(struct can_clock));	/* IFLA_CAN_CLOCK */
 	size += nla_total_size(sizeof(u32));			/* IFLA_CAN_STATE */
 	size += nla_total_size(sizeof(struct can_ctrlmode));	/* IFLA_CAN_CTRLMODE */
@@ -741,15 +742,20 @@ static int can_fill_info(struct sk_buff *skb, const struct net_device *dev)
 
 	if (priv->do_get_state)
 		priv->do_get_state(dev, &state);
-	if (nla_put(skb, IFLA_CAN_BITTIMING,
-		    sizeof(priv->bittiming), &priv->bittiming) ||
+
+	if ((priv->bittiming_const &&
+	     nla_put(skb, IFLA_CAN_BITTIMING,
+		     sizeof(priv->bittiming), &priv->bittiming)) ||
+
 	    (priv->bittiming_const &&
 	     nla_put(skb, IFLA_CAN_BITTIMING_CONST,
 		     sizeof(*priv->bittiming_const), priv->bittiming_const)) ||
+
 	    nla_put(skb, IFLA_CAN_CLOCK, sizeof(cm), &priv->clock) ||
 	    nla_put_u32(skb, IFLA_CAN_STATE, state) ||
 	    nla_put(skb, IFLA_CAN_CTRLMODE, sizeof(cm), &cm) ||
 	    nla_put_u32(skb, IFLA_CAN_RESTART_MS, priv->restart_ms) ||
+
 	    (priv->do_get_berr_counter &&
 	     !priv->do_get_berr_counter(dev, &bec) &&
 	     nla_put(skb, IFLA_CAN_BERR_COUNTER, sizeof(bec), &bec)))
-- 
1.9.0.rc3


  reply	other threads:[~2014-02-14 20:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-14 20:57 [PATCH 1/4] can: preserve skbuff protocol in can_put_echo_skb Oliver Hartkopp
2014-02-14 20:57 ` Oliver Hartkopp [this message]
2014-02-14 21:26   ` [PATCH 2/4] can: netlink send bittiming data only when bittiming_const is available Marc Kleine-Budde
2014-02-15  7:10     ` Oliver Hartkopp
2014-02-15 10:06       ` Marc Kleine-Budde
2014-02-14 20:57 ` [PATCH 3/4] can: provide a separate bittiming_const parameter to bittiming functions Oliver Hartkopp
2014-02-14 20:57 ` [PATCH 4/4] can: introduce a second bitrate for CAN FD data bitrate configuration Oliver Hartkopp

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=1392411447-9105-2-git-send-email-socketcan@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=linux-can@vger.kernel.org \
    /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).