linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
To: Marc Kleine-Budde <mkl@pengutronix.de>, linux-can@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Subject: [PATCH v2 1/2] can: netlink: remove redundant check in can_validate()
Date: Fri,  4 Jun 2021 00:15:49 +0900	[thread overview]
Message-ID: <20210603151550.140727-2-mailhol.vincent@wanadoo.fr> (raw)
In-Reply-To: <20210603151550.140727-1-mailhol.vincent@wanadoo.fr>

can_validate() does a first check:
|	if (is_can_fd) {
|		if (!data[IFLA_CAN_BITTIMING] || !data[IFLA_CAN_DATA_BITTIMING])
|			return -EOPNOTSUPP;
|	}

If that first if succeeds, we know that if is_can_fd is true then
data[IFLA_CAN_BITTIMING is set.

However, the next if switch does not leverage on above knowledge and
redoes the check:
| 	if (data[IFLA_CAN_DATA_BITTIMING]) {
|		if (!is_can_fd || !data[IFLA_CAN_BITTIMING])
|		                   ^~~~~~~~~~~~~~~~~~~~~~~~
| 			return -EOPNOTSUPP;
| 	}

This patch removes that redundant check.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
 drivers/net/can/dev/netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index e38c2566aff4..32c603a09809 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -47,7 +47,7 @@ static int can_validate(struct nlattr *tb[], struct nlattr *data[],
 	}
 
 	if (data[IFLA_CAN_DATA_BITTIMING]) {
-		if (!is_can_fd || !data[IFLA_CAN_BITTIMING])
+		if (!is_can_fd)
 			return -EOPNOTSUPP;
 	}
 
-- 
2.31.1


  reply	other threads:[~2021-06-03 15:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-03 15:15 [PATCH v2 0/2] add the netlink interface for CAN-FD Transmitter Delay Compensation (TDC) Vincent Mailhol
2021-06-03 15:15 ` Vincent Mailhol [this message]
2021-06-03 15:15 ` [PATCH v2 2/2] can: netlink: add " Vincent Mailhol
2021-06-16  9:46   ` Marc Kleine-Budde
2021-06-16 13:53     ` Vincent MAILHOL
2021-06-16 14:29       ` Marc Kleine-Budde
2021-06-16 14:43         ` Vincent MAILHOL
2021-06-16 14:46           ` Marc Kleine-Budde
2021-06-16 15:44             ` Vincent MAILHOL
2021-06-17 11:38               ` Marc Kleine-Budde
2021-06-18  9:34   ` Marc Kleine-Budde
2021-06-18 10:23     ` Vincent MAILHOL
2021-06-18 11:17       ` Vincent MAILHOL
2021-06-18 12:44         ` CAN-FD Transmitter Delay Compensation (TDC) on mcp2518fd Marc Kleine-Budde
2021-06-18 14:27           ` Vincent MAILHOL
2021-06-18 15:55             ` Stefan Mätje
2021-06-19 12:34               ` Vincent MAILHOL
2021-06-21 18:42                 ` Stefan Mätje
2021-06-21 23:52                   ` Vincent MAILHOL
2021-06-22  0:04                     ` Vincent MAILHOL

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=20210603151550.140727-2-mailhol.vincent@wanadoo.fr \
    --to=mailhol.vincent@wanadoo.fr \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).