Use NL_SET_ERR_MSG_FMT() to return meaningfull error messages to the userland whenever the validation of the CAN netlink arguments fails. Signed-off-by: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx> --- See this one as a WIP. I wrote this quickly. I will revisit and rephrase when dropping the RFC tag of this series. Also, do not try to imagine that I wrote this because I forgot how to provide to can bittiming arguments to the ip tool. This patch is only meant to help the newcommers, nothing else :D --- drivers/net/can/dev/netlink.c | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c index 3c89b304c5b8..0a6700194ab0 100644 --- a/drivers/net/can/dev/netlink.c +++ b/drivers/net/can/dev/netlink.c @@ -124,8 +124,11 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], cm->flags & CAN_CTRLMODE_TDC_AUTO, cm->flags & CAN_CTRLMODE_TDC_MANUAL, extack); - if (err) + if (err) { + NL_SET_ERR_MSG_FMT(extack, + "TDC parameters are incorrect"); return err; + } } if (data[IFLA_CAN_BITTIMING]) { @@ -133,26 +136,41 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt)); err = can_validate_bittiming(&bt, extack); - if (err) + if (err) { + NL_SET_ERR_MSG_FMT(extack, + "Nominal bittiming parameters are incorrect"); return err; + } } if (is_can_fd) { - if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_DATA_BITTIMING]) + if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_DATA_BITTIMING]) { + NL_SET_ERR_MSG_FMT(extack, + "Provide both nominal and FD data bittiming"); return -EOPNOTSUPP; + } } if (is_can_xl) { - if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_XL_DATA_BITTIMING]) + if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_XL_DATA_BITTIMING]) { + NL_SET_ERR_MSG_FMT(extack, + "Provide both nominal and XL data bittiming"); return -EOPNOTSUPP; + } } if (data[IFLA_CAN_DATA_BITTIMING] || data[IFLA_CAN_TDC]) { - if (!is_can_fd) + if (!is_can_fd) { + NL_SET_ERR_MSG_FMT(extack, + "CAN FD is required to use FD data bittiming or FD TDC"); return -EOPNOTSUPP; + } } if (data[IFLA_CAN_XL_DATA_BITTIMING] || data[IFLA_CAN_XL_TDC]) { - if (!is_can_xl) + if (!is_can_xl) { + NL_SET_ERR_MSG_FMT(extack, + "CAN XL is required to use XL data bittiming or XL TDC"); return -EOPNOTSUPP; + } } if (data[IFLA_CAN_DATA_BITTIMING]) { @@ -160,16 +178,22 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[], memcpy(&bt, nla_data(data[IFLA_CAN_DATA_BITTIMING]), sizeof(bt)); err = can_validate_bittiming(&bt, extack); - if (err) + if (err) { + NL_SET_ERR_MSG_FMT(extack, + "FD data bittiming parameters are incorrect"); return err; + } } if (data[IFLA_CAN_XL_DATA_BITTIMING]) { struct can_bittiming bt; memcpy(&bt, nla_data(data[IFLA_CAN_XL_DATA_BITTIMING]), sizeof(bt)); err = can_validate_bittiming(&bt, extack); - if (err) + if (err) { + NL_SET_ERR_MSG_FMT(extack, + "FD data bittiming parameters are incorrect"); return err; + } } return 0; -- 2.45.2