linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: linux-can@vger.kernel.org
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
	Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
Subject: [PATCH] can: netlink: can_tdc_changelink(): assign tdc only after complete validation
Date: Tue, 17 Aug 2021 22:04:41 +0200	[thread overview]
Message-ID: <20210817200441.434270-1-mkl@pengutronix.de> (raw)

Cc: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
Feel free to squash into you series.

Marc

 drivers/net/can/dev/netlink.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/can/dev/netlink.c b/drivers/net/can/dev/netlink.c
index ba644f120573..f16a98998f45 100644
--- a/drivers/net/can/dev/netlink.c
+++ b/drivers/net/can/dev/netlink.c
@@ -109,7 +109,7 @@ static int can_tdc_changelink(struct net_device *dev, const struct nlattr *nla,
 {
 	struct nlattr *tb_tdc[IFLA_CAN_TDC_MAX + 1];
 	struct can_priv *priv = netdev_priv(dev);
-	struct can_tdc *tdc = &priv->tdc;
+	struct can_tdc tdc = { };
 	const struct can_tdc_const *tdc_const = priv->tdc_const;
 	int err;
 
@@ -130,7 +130,7 @@ static int can_tdc_changelink(struct net_device *dev, const struct nlattr *nla,
 		if (tdcv < tdc_const->tdcv_min || tdcv > tdc_const->tdcv_max)
 			return -EINVAL;
 
-		tdc->tdcv = tdcv;
+		tdc.tdcv = tdcv;
 	}
 
 	if (tb_tdc[IFLA_CAN_TDC_TDCO]) {
@@ -139,7 +139,7 @@ static int can_tdc_changelink(struct net_device *dev, const struct nlattr *nla,
 		if (tdco < tdc_const->tdco_min || tdco > tdc_const->tdco_max)
 			return -EINVAL;
 
-		tdc->tdco = tdco;
+		tdc.tdco = tdco;
 	}
 
 	if (tb_tdc[IFLA_CAN_TDC_TDCF]) {
@@ -148,9 +148,11 @@ static int can_tdc_changelink(struct net_device *dev, const struct nlattr *nla,
 		if (tdcf < tdc_const->tdcf_min || tdcf > tdc_const->tdcf_max)
 			return -EINVAL;
 
-		tdc->tdcf = tdcf;
+		tdc.tdcf = tdcf;
 	}
 
+	priv->tdc = tdc;
+
 	return 0;
 }
 
-- 
2.32.0



                 reply	other threads:[~2021-08-17 20:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210817200441.434270-1-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    /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).