lkml.org 
[lkml]   [2021]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v5 5/7] can: netlink: add interface for CAN-FD Transmitter Delay Compensation (TDC)
On 15.08.2021 12:32:46, Vincent Mailhol wrote:
> +static int can_tdc_changelink(struct net_device *dev, const struct nlattr *nla,
> + struct netlink_ext_ack *extack)
> +{
> + struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX + 1];
> + struct can_priv *priv = netdev_priv(dev);
> + struct can_tdc *tdc = &priv->tdc;
> + const struct can_tdc_const *tdc_const = priv->tdc_const;
> + int err;
> +
> + if (!tdc_const || !can_tdc_is_enabled(priv))
> + return -EOPNOTSUPP;
> +
> + if (dev->flags & IFF_UP)
> + return -EBUSY;
> +
> + err = nla_parse_nested(tb_tdc, IFLA_CAN_TDC_MAX, nla,
> + can_tdc_policy, extack);
> + if (err)
> + return err;
> +
> + if (tb_tdc[IFLA_CAN_TDC_TDCV]) {
> + u32 tdcv = nla_get_u32(tb_tdc[IFLA_CAN_TDC_TDCV]);
> +
> + if (tdcv < tdc_const->tdcv_min || tdcv > tdc_const->tdcv_max)
> + return -EINVAL;
> +
> + tdc->tdcv = tdcv;

You have to assign to a temporary struct first, and set the priv->tdc
after complete validation, otherwise you end up with inconsistent
values.

> + }
> +
> + if (tb_tdc[IFLA_CAN_TDC_TDCO]) {
> + u32 tdco = nla_get_u32(tb_tdc[IFLA_CAN_TDC_TDCO]);
> +
> + if (tdco < tdc_const->tdco_min || tdco > tdc_const->tdco_max)
> + return -EINVAL;
> +
> + tdc->tdco = tdco;
> + }
> +
> + if (tb_tdc[IFLA_CAN_TDC_TDCF]) {
> + u32 tdcf = nla_get_u32(tb_tdc[IFLA_CAN_TDC_TDCF]);
> +
> + if (tdcf < tdc_const->tdcf_min || tdcf > tdc_const->tdcf_max)
> + return -EINVAL;
> +
> + tdc->tdcf = tdcf;
> + }
> +
> + return 0;
> +}

To reproduce (ip pseudo-code only :D ):

ip down
ip up tdc-mode manual tdco 111 tdcv 33 # 111 is out of range, 33 is valid
ip down
ip up # results in tdco=0 tdcv=33 mode=manual

Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2021-08-17 21:57    [W:0.189 / U:1.740 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site