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 v8 3/7] can: move sanity check for bitrate and tq into can_get_bittiming
Date: Fri, 28 Feb 2014 14:19:05 +0100	[thread overview]
Message-ID: <1393593549-23072-4-git-send-email-socketcan@hartkopp.net> (raw)
In-Reply-To: <1393593549-23072-1-git-send-email-socketcan@hartkopp.net>

This patch moves a sanity check in order to have a second user for CAN FD.

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

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index de04eac..89fc798 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -263,12 +263,19 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt)
 	if (priv->bittiming_const) {
 
 		/* Non-expert mode? Check if the bitrate has been pre-defined */
-		if (!bt->tq)
+		if (!bt->tq) {
 			/* Determine bit-timing parameters */
-			err = can_calc_bittiming(dev, bt);
-		else
+			if (bt->bitrate)
+				err = can_calc_bittiming(dev, bt);
+			else
+				return -EINVAL;
+		} else {
 			/* Check bit-timing params and calculate proper brp */
-			err = can_fixup_bittiming(dev, bt);
+			if (!bt->bitrate)
+				err = can_fixup_bittiming(dev, bt);
+			else
+				return -EINVAL;
+		}
 		if (err)
 			return err;
 	}
@@ -667,8 +674,6 @@ static int can_changelink(struct net_device *dev,
 		if (dev->flags & IFF_UP)
 			return -EBUSY;
 		memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt));
-		if ((!bt.bitrate && !bt.tq) || (bt.bitrate && bt.tq))
-			return -EINVAL;
 		err = can_get_bittiming(dev, &bt);
 		if (err)
 			return err;
-- 
1.9.0


  parent reply	other threads:[~2014-02-28 13:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28 13:19 [PATCH v8 0/7] Add CAN FD infrastructure for CAN driver Oliver Hartkopp
2014-02-28 13:19 ` [PATCH v8 1/7] can: preserve skbuff protocol in can_put_echo_skb Oliver Hartkopp
2014-02-28 13:19 ` [PATCH v8 2/7] can: only send bitrate data via netlink when available Oliver Hartkopp
2014-02-28 13:19 ` Oliver Hartkopp [this message]
2014-02-28 13:19 ` [PATCH v8 4/7] can: provide a separate bittiming_const parameter to bittiming functions Oliver Hartkopp
2014-02-28 15:15   ` Oliver Hartkopp
2014-02-28 15:16     ` Marc Kleine-Budde
2014-02-28 13:19 ` [PATCH v8 5/7] can: introduce the data bitrate configuration for CAN FD Oliver Hartkopp
2014-02-28 13:19 ` [PATCH v8 6/7] can: allow to change the device mtu for CAN FD capable devices Oliver Hartkopp
2014-02-28 13:19 ` [PATCH v8 7/7] can: add bittiming check at interface open for CAN FD Oliver Hartkopp
2014-02-28 15:18 ` [PATCH v8 0/7] Add CAN FD infrastructure for CAN driver Stephane Grosjean

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=1393593549-23072-4-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).