aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can
diff options
context:
space:
mode:
authorOliver Hartkopp <socketcan@hartkopp.net>2014-02-28 10:36:21 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-03-07 03:18:21 -0500
commitd5298dffebae76810a6a942bc6467f893bc11eee (patch)
tree7f9ccb872c6e0f2415595d8ea602121634f1a1df /drivers/net/can
parentb30749fdfb9b72f4b1f03673cb5e45b8d4331188 (diff)
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>
Diffstat (limited to 'drivers/net/can')
-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)
260 int err; 260 int err;
261 261
262 /* Check if the CAN device has bit-timing parameters */ 262 /* Check if the CAN device has bit-timing parameters */
263 if (priv->bittiming_const) { 263 if (!priv->bittiming_const)
264 return 0;
264 265
265 /* Non-expert mode? Check if the bitrate has been pre-defined */ 266 /*
266 if (!bt->tq) 267 * Depending on the given can_bittiming parameter structure the CAN
267 /* Determine bit-timing parameters */ 268 * timing parameters are calculated based on the provided bitrate OR
268 err = can_calc_bittiming(dev, bt); 269 * alternatively the CAN timing parameters (tq, prop_seg, etc.) are
269 else 270 * provided directly which are then checked and fixed up.
270 /* Check bit-timing params and calculate proper brp */ 271 */
271 err = can_fixup_bittiming(dev, bt); 272 if (!bt->tq && bt->bitrate)
272 if (err) 273 err = can_calc_bittiming(dev, bt);
273 return err; 274 else if (bt->tq && !bt->bitrate)
274 } 275 err = can_fixup_bittiming(dev, bt);
276 else
277 err = -EINVAL;
275 278
276 return 0; 279 return err;
277} 280}
278 281
279/* 282/*
@@ -667,8 +670,6 @@ static int can_changelink(struct net_device *dev,
667 if (dev->flags & IFF_UP) 670 if (dev->flags & IFF_UP)
668 return -EBUSY; 671 return -EBUSY;
669 memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); 672 memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt));
670 if ((!bt.bitrate && !bt.tq) || (bt.bitrate && bt.tq))
671 return -EINVAL;
672 err = can_get_bittiming(dev, &bt); 673 err = can_get_bittiming(dev, &bt);
673 if (err) 674 if (err)
674 return err; 675 return err;