Linux CAN drivers development
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: linux-can@vger.kernel.org
Cc: Daniel Trevitz <daniel.trevitz@wika.com>,
	Ryan Edwards <ryan.edwards@gmail.com>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH v2 2/3] can: gs_usb: gs_make_candev(): clean up error handling
Date: Sun, 18 Sep 2022 23:18:01 +0200	[thread overview]
Message-ID: <20220918211802.692405-3-mkl@pengutronix.de> (raw)
In-Reply-To: <20220918211802.692405-1-mkl@pengutronix.de>

Introduce a label to free the allocated candev in case of a error and
make use of if. Fix a memory leak if the extended bit timing cannot be
read. Extend the error messages to print the number of the failing
channel and the symbolic error name.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/gs_usb.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 16e56394ef9b..bfa061687d13 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -1137,8 +1137,8 @@ static struct gs_can *gs_make_candev(unsigned int channel,
 
 	if (rc) {
 		dev_err(&intf->dev,
-			"Couldn't get bit timing const for channel (err=%d)\n",
-			rc);
+			"Couldn't get bit timing const for channel %d (%pe)\n",
+			channel, ERR_PTR(rc));
 		return ERR_PTR(rc);
 	}
 
@@ -1251,9 +1251,9 @@ static struct gs_can *gs_make_candev(unsigned int channel,
 					  1000, GFP_KERNEL);
 		if (rc) {
 			dev_err(&intf->dev,
-				"Couldn't get extended bit timing const for channel (err=%d)\n",
-				rc);
-			return ERR_PTR(rc);
+				"Couldn't get extended bit timing const for channel %d (%pe)\n",
+				channel, ERR_PTR(rc));
+			goto out_free_candev;
 		}
 
 		strcpy(dev->data_bt_const.name, KBUILD_MODNAME);
@@ -1273,12 +1273,17 @@ static struct gs_can *gs_make_candev(unsigned int channel,
 
 	rc = register_candev(dev->netdev);
 	if (rc) {
-		free_candev(dev->netdev);
-		dev_err(&intf->dev, "Couldn't register candev (err=%d)\n", rc);
-		return ERR_PTR(rc);
+		dev_err(&intf->dev,
+			"Couldn't register candev for channel %d (%pe)\n",
+			channel, ERR_PTR(rc));
+		goto out_free_candev;
 	}
 
 	return dev;
+
+ out_free_candev:
+	free_candev(dev->netdev);
+	return ERR_PTR(rc);
 }
 
 static void gs_destroy_candev(struct gs_can *dev)
-- 
2.35.1



  parent reply	other threads:[~2022-09-18 21:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18 21:17 [PATCH v2 0/3] can: gs_usb: cleanups and termination support Marc Kleine-Budde
2022-09-18 21:18 ` [PATCH v2 1/3] can: gs_usb: gs_make_candev(): convert from usb_control_msg() to usb_control_msg_recv() Marc Kleine-Budde
2022-09-18 21:18 ` Marc Kleine-Budde [this message]
2022-09-18 21:18 ` [PATCH v2 3/3] can: gs_usb: add switchable termination support Marc Kleine-Budde
2022-09-19 17:14   ` Trevitz, Daniel
2022-09-19 19:33     ` Marc Kleine-Budde
2022-09-20 11:48       ` Trevitz, Daniel
2022-09-18 22:00 ` [PATCH v2 0/3] can: gs_usb: cleanups and " Trevitz, Daniel
2022-09-19  7:34   ` 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=20220918211802.692405-3-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=daniel.trevitz@wika.com \
    --cc=linux-can@vger.kernel.org \
    --cc=ryan.edwards@gmail.com \
    /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