linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: linux-input@vger.kernel.org,
	Benjamin Tissoires <bentiss@kernel.org>,
	David Rheinsberg <david@readahead.eu>,
	Jiri Kosina <jikos@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] HID: wiimote: Improve error handling in two functions
Date: Wed, 18 Sep 2024 14:00:17 +0200	[thread overview]
Message-ID: <d7dd0c6c-a840-4a90-8b80-b1cb36941bf6@web.de> (raw)

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 18 Sep 2024 13:51:29 +0200

Add jump targets so that a bit of exception handling can be better reused
at the end of two function implementations.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/hid/hid-wiimote-modules.c | 34 ++++++++++++++++---------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/hid/hid-wiimote-modules.c b/drivers/hid/hid-wiimote-modules.c
index dbccdfa63916..3c10b1c68984 100644
--- a/drivers/hid/hid-wiimote-modules.c
+++ b/drivers/hid/hid-wiimote-modules.c
@@ -1424,15 +1424,12 @@ static ssize_t wiimod_bboard_calib_show(struct device *dev,
 		return ret;

 	ret = wiimote_cmd_read(wdata, 0xa40024, buf, 12);
-	if (ret != 12) {
-		wiimote_cmd_release(wdata);
-		return ret < 0 ? ret : -EIO;
-	}
+	if (ret != 12)
+		goto release_wdata;
+
 	ret = wiimote_cmd_read(wdata, 0xa40024 + 12, buf + 12, 12);
-	if (ret != 12) {
-		wiimote_cmd_release(wdata);
-		return ret < 0 ? ret : -EIO;
-	}
+	if (ret != 12)
+		goto release_wdata;

 	wiimote_cmd_release(wdata);

@@ -1460,6 +1457,10 @@ static ssize_t wiimod_bboard_calib_show(struct device *dev,
 	}

 	return ret;
+
+release_wdata:
+	wiimote_cmd_release(wdata);
+	return ret < 0 ? ret : -EIO;
 }

 static DEVICE_ATTR(bboard_calib, S_IRUGO, wiimod_bboard_calib_show, NULL);
@@ -1473,15 +1474,12 @@ static int wiimod_bboard_probe(const struct wiimod_ops *ops,
 	wiimote_cmd_acquire_noint(wdata);

 	ret = wiimote_cmd_read(wdata, 0xa40024, buf, 12);
-	if (ret != 12) {
-		wiimote_cmd_release(wdata);
-		return ret < 0 ? ret : -EIO;
-	}
+	if (ret != 12)
+		goto release_wdata;
+
 	ret = wiimote_cmd_read(wdata, 0xa40024 + 12, buf + 12, 12);
-	if (ret != 12) {
-		wiimote_cmd_release(wdata);
-		return ret < 0 ? ret : -EIO;
-	}
+	if (ret != 12)
+		goto release_wdata;

 	wiimote_cmd_release(wdata);

@@ -1546,6 +1544,10 @@ static int wiimod_bboard_probe(const struct wiimod_ops *ops,
 	input_free_device(wdata->extension.input);
 	wdata->extension.input = NULL;
 	return ret;
+
+release_wdata:
+	wiimote_cmd_release(wdata);
+	return ret < 0 ? ret : -EIO;
 }

 static void wiimod_bboard_remove(const struct wiimod_ops *ops,
--
2.46.0


                 reply	other threads:[~2024-09-18 12:00 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=d7dd0c6c-a840-4a90-8b80-b1cb36941bf6@web.de \
    --to=markus.elfring@web.de \
    --cc=bentiss@kernel.org \
    --cc=david@readahead.eu \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).