From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Robert Nawrath <mbro1689@gmail.com>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Subject: [RFC PATCH 13/14] can: netlink: add userland error messages
Date: Mon, 11 Nov 2024 00:56:02 +0900 [thread overview]
Message-ID: <20241110155902.72807-29-mailhol.vincent@wanadoo.fr> (raw)
In-Reply-To: <20241110155902.72807-16-mailhol.vincent@wanadoo.fr>
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@wanadoo.fr>
---
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
next prev parent reply other threads:[~2024-11-10 15:59 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-10 15:55 [RFC PATCH 00/14] can: netlink: add CAN XL Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 01/14] can: dev: add struct data_bittiming_params to group FD parameters Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 02/14] can: netlink: replace tabulation by space in assignement Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 03/14] can: bittiming: rename CAN_CTRLMODE_TDC_MASK into CAN_CTRLMODE_FD_TDC_MASK Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 04/14] can: bittiming: rename can_tdc_is_enabled() into can_fd_tdc_is_enabled() Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 05/14] can: netlink: can_changelink(): rename tdc_mask into fd_tdc_flag_provided Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 06/14] can: netlink: make can_tdc_changelink() FD agnostic Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 07/14] can: netlink: add can_dtb_changelink() Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 08/14] can: netlink: add can_validate_tdc() Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 09/14] can: netlink: make can_tdc_get_size() FD agnostic Vincent Mailhol
2024-11-10 15:55 ` [RFC PATCH 10/14] can: netlink: make can_tdc_fill_info() " Vincent Mailhol
2024-11-10 15:56 ` [RFC PATCH 11/14] can: netlink: document which symbols are FD specific Vincent Mailhol
2024-11-10 15:56 ` [RFC PATCH 12/14] can: netlink: add CAN XL support Vincent Mailhol
2024-11-12 8:09 ` Marc Kleine-Budde
2024-11-12 8:31 ` Vincent Mailhol
2024-11-12 8:41 ` Marc Kleine-Budde
2024-12-04 10:56 ` Oliver Hartkopp
2024-12-04 11:15 ` Marc Kleine-Budde
2024-12-04 11:35 ` Oliver Hartkopp
2024-12-04 11:44 ` Marc Kleine-Budde
2024-12-05 8:16 ` Oliver Hartkopp
2024-12-05 9:15 ` Marc Kleine-Budde
2024-12-09 13:13 ` Oliver Hartkopp
2024-12-10 11:58 ` Marc Kleine-Budde
2024-12-15 8:05 ` Vincent Mailhol
2024-11-10 15:56 ` Vincent Mailhol [this message]
2024-11-10 15:56 ` [RFC PATCH 14/14] !!! DO NOT MERGE !!! can: add dummyxl driver Vincent Mailhol
2024-11-11 14:08 ` [RFC PATCH 00/14] can: netlink: add CAN XL Oliver Hartkopp
2024-11-11 15:17 ` Vincent Mailhol
2024-11-11 15:32 ` Oliver Hartkopp
2024-11-21 20:10 ` Oliver Hartkopp
2024-12-01 11:32 ` Oliver Hartkopp
2024-12-03 9:45 ` Vincent Mailhol
2024-12-04 7:56 ` Oliver Hartkopp
2024-12-15 9:21 ` Vincent Mailhol
2024-12-17 9:53 ` Oliver Hartkopp
2024-12-17 18:17 ` Vincent Mailhol
2024-12-17 20:03 ` Oliver Hartkopp
2024-12-18 9:13 ` Oliver Hartkopp
2025-01-30 5:42 ` Vincent Mailhol
2025-01-30 7:34 ` Marc Kleine-Budde
2024-11-12 8:53 ` Marc Kleine-Budde
2024-11-12 9:24 ` Vincent Mailhol
2024-11-12 10:12 ` Marc Kleine-Budde
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241110155902.72807-29-mailhol.vincent@wanadoo.fr \
--to=mailhol.vincent@wanadoo.fr \
--cc=linux-can@vger.kernel.org \
--cc=mbro1689@gmail.com \
--cc=mkl@pengutronix.de \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox