mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Heiko Stuebner <heiko@sntech.de>
To: lee@kernel.org
Cc: heiko@sntech.de, linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] mfd: qnap-mcu: convert to guard(mutex) in qnap_mcu_exec
Date: Mon,  4 Aug 2025 15:07:25 +0200	[thread overview]
Message-ID: <20250804130726.3180806-4-heiko@sntech.de> (raw)
In-Reply-To: <20250804130726.3180806-1-heiko@sntech.de>

guard() makes sure that the mutex gets unlocked when the function returns
and thus removes the need for unlock gotos or similar mechanisms and
therefore allows for a simpler function structure.

So convert the qnap_mcu_exec function to use it.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 drivers/mfd/qnap-mcu.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c
index 6448237c4c35..7bc44c64b7fd 100644
--- a/drivers/mfd/qnap-mcu.c
+++ b/drivers/mfd/qnap-mcu.c
@@ -156,7 +156,7 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
 		return -EINVAL;
 	}
 
-	mutex_lock(&mcu->bus_lock);
+	guard(mutex)(&mcu->bus_lock);
 
 	reply->data = rx;
 	reply->length = length;
@@ -164,30 +164,27 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
 	reinit_completion(&reply->done);
 
 	ret = qnap_mcu_write(mcu, cmd_data, cmd_data_size);
-	if (ret < 0) {
-		mutex_unlock(&mcu->bus_lock);
+	if (ret < 0)
 		return ret;
-	}
 
 	serdev_device_wait_until_sent(mcu->serdev, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS));
 
 	if (!wait_for_completion_timeout(&reply->done, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS))) {
 		dev_err(&mcu->serdev->dev, "Command timeout\n");
-		ret = -ETIMEDOUT;
+		return -ETIMEDOUT;
 	} else {
 		u8 crc = qnap_mcu_csum(rx, reply_data_size);
 
 		if (crc != rx[reply_data_size]) {
 			dev_err(&mcu->serdev->dev,
 				"Invalid Checksum received\n");
-			ret = -EIO;
+			return -EIO;
 		} else {
 			memcpy(reply_data, rx, reply_data_size);
 		}
 	}
 
-	mutex_unlock(&mcu->bus_lock);
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(qnap_mcu_exec);
 
-- 
2.47.2


  parent reply	other threads:[~2025-08-04 13:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 13:07 [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Heiko Stuebner
2025-08-04 13:07 ` [PATCH 1/4] mfd: qnap-mcu: include linux/types.h in qnap-mcu.h shared header Heiko Stuebner
2025-08-04 13:07 ` [PATCH 2/4] mfd: qnap-mcu: handle errors returned from qnap_mcu_write Heiko Stuebner
2025-08-04 13:07 ` Heiko Stuebner [this message]
2025-08-04 13:07 ` [PATCH 4/4] mfd: qnap-mcu: improve structure in qnap_mcu_exec Heiko Stuebner
2025-09-02  7:58 ` [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Lee Jones
2025-09-02  8:00   ` Lee Jones

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=20250804130726.3180806-4-heiko@sntech.de \
    --to=heiko@sntech.de \
    --cc=lee@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

all inboxes | Powered by JetHome®