summaryrefslogtreecommitdiff
path: root/drivers/mfd/qnap-mcu.c
diff options
context:
space:
mode:
authorHeiko Stuebner <heiko@sntech.de>2025-08-04 15:07:25 +0200
committerLee Jones <lee@kernel.org>2025-10-01 10:28:15 +0100
commit21c5ffb4211203de0a91de8a1c4a329e508a2ffb (patch)
tree2bccd2156585901933e74ca722e5013e1fb5bf7c /drivers/mfd/qnap-mcu.c
parentbf2de43060d528e52e372c63182a94b95c80d305 (diff)
mfd: qnap-mcu: Convert to guard(mutex) in qnap_mcu_exec
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> Link: https://lore.kernel.org/r/20250804130726.3180806-4-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/mfd/qnap-mcu.c')
-rw-r--r--drivers/mfd/qnap-mcu.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c
index e794efb6ecb1..6875f27151e9 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);