Skip to content

Commit

Permalink
can: dev: register_candev(): ensure that bittiming const are valid
Browse files Browse the repository at this point in the history
Implement the function can_bittiming_const_valid() to check the
validity of the specified bit timing constant. Call this function from
register_candev() to check the bit timing constants during the
registration of the CAN interface.

Link: https://lore.kernel.org/all/20230202110854.2318594-6-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Marc Kleine-Budde committed Feb 6, 2023
1 parent 8e0a0b3 commit d58ac89
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/net/can/dev/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ static int can_get_termination(struct net_device *ndev)
return 0;
}

static bool
can_bittiming_const_valid(const struct can_bittiming_const *btc)
{
if (!btc)
return true;

if (!btc->sjw_max)
return false;

return true;
}

/* Register the CAN network device */
int register_candev(struct net_device *dev)
{
Expand All @@ -518,6 +530,10 @@ int register_candev(struct net_device *dev)
if (!priv->data_bitrate_const != !priv->data_bitrate_const_cnt)
return -EINVAL;

if (!can_bittiming_const_valid(priv->bittiming_const) ||
!can_bittiming_const_valid(priv->data_bittiming_const))
return -EINVAL;

if (!priv->termination_const) {
err = can_get_termination(dev);
if (err)
Expand Down

0 comments on commit d58ac89

Please sign in to comment.