Commit d5298dff authored by Oliver Hartkopp's avatar Oliver Hartkopp Committed by Marc Kleine-Budde

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: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Acked-by: default avatarStephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent b30749fd
...@@ -260,20 +260,23 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt) ...@@ -260,20 +260,23 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt)
int err; int err;
/* Check if the CAN device has bit-timing parameters */ /* 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) * Depending on the given can_bittiming parameter structure the CAN
/* Determine bit-timing parameters */ * timing parameters are calculated based on the provided bitrate OR
err = can_calc_bittiming(dev, bt); * alternatively the CAN timing parameters (tq, prop_seg, etc.) are
else * provided directly which are then checked and fixed up.
/* Check bit-timing params and calculate proper brp */ */
err = can_fixup_bittiming(dev, bt); if (!bt->tq && bt->bitrate)
if (err) err = can_calc_bittiming(dev, bt);
return err; 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, ...@@ -667,8 +670,6 @@ static int can_changelink(struct net_device *dev,
if (dev->flags & IFF_UP) if (dev->flags & IFF_UP)
return -EBUSY; return -EBUSY;
memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); 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); err = can_get_bittiming(dev, &bt);
if (err) if (err)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment