summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Hartkopp <socketcan@hartkopp.net>2014-02-28 19:36:21 +0400
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-03-07 12:18:21 +0400
commitd5298dffebae76810a6a942bc6467f893bc11eee (patch)
tree7f9ccb872c6e0f2415595d8ea602121634f1a1df
parentb30749fdfb9b72f4b1f03673cb5e45b8d4331188 (diff)
downloadlinux-d5298dffebae76810a6a942bc6467f893bc11eee.tar.xz
can: move sanity check for bitrate and tq into can_get_bittiming
This patch moves a sanity check in order to have a second user for CAN FD. Also simplify the return value generation in can_get_bittiming() as only correct return values of can_[calc|fixup]_bittiming() lead to a return value of zero. Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Acked-by: Stephane Grosjean <s.grosjean@peak-system.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--drivers/net/can/dev.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index de04eac7c5f3..e5f1faf36d8f 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -260,20 +260,23 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt)
int err;
/* Check if the CAN device has bit-timing parameters */
- if (priv->bittiming_const) {
+ if (!priv->bittiming_const)
+ return 0;
- /* Non-expert mode? Check if the bitrate has been pre-defined */
- if (!bt->tq)
- /* Determine bit-timing parameters */
- err = can_calc_bittiming(dev, bt);
- else
- /* Check bit-timing params and calculate proper brp */
- err = can_fixup_bittiming(dev, bt);
- if (err)
- return err;
- }
+ /*
+ * Depending on the given can_bittiming parameter structure the CAN
+ * timing parameters are calculated based on the provided bitrate OR
+ * alternatively the CAN timing parameters (tq, prop_seg, etc.) are
+ * provided directly which are then checked and fixed up.
+ */
+ if (!bt->tq && bt->bitrate)
+ err = can_calc_bittiming(dev, bt);
+ else if (bt->tq && !bt->bitrate)
+ err = can_fixup_bittiming(dev, bt);
+ else
+ err = -EINVAL;
- return 0;
+ return err;
}
/*
@@ -667,8 +670,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;