* [PATCH 1/4] mfd: qnap-mcu: include linux/types.h in qnap-mcu.h shared header
2025-08-04 13:07 [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Heiko Stuebner
@ 2025-08-04 13:07 ` Heiko Stuebner
2025-08-04 13:07 ` [PATCH 2/4] mfd: qnap-mcu: handle errors returned from qnap_mcu_write Heiko Stuebner
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Heiko Stuebner @ 2025-08-04 13:07 UTC (permalink / raw)
To: lee; +Cc: heiko, linux-kernel
Relying on other components to include those basic types is unrelyable
and may cause compile errors like:
../include/linux/mfd/qnap-mcu.h:13:9: error: unknown type name ‘u32’
13 | u32 baud_rate;
| ^~~
../include/linux/mfd/qnap-mcu.h:17:9: error: unknown type name ‘bool’
17 | bool usb_led;
| ^~~~
So make sure, the types used in the header are available.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
include/linux/mfd/qnap-mcu.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/include/linux/mfd/qnap-mcu.h b/include/linux/mfd/qnap-mcu.h
index 8d48c212fd44..42bf523f9a5b 100644
--- a/include/linux/mfd/qnap-mcu.h
+++ b/include/linux/mfd/qnap-mcu.h
@@ -7,6 +7,8 @@
#ifndef _LINUX_QNAP_MCU_H_
#define _LINUX_QNAP_MCU_H_
+#include <linux/types.h>
+
struct qnap_mcu;
struct qnap_mcu_variant {
--
2.47.2
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 2/4] mfd: qnap-mcu: handle errors returned from qnap_mcu_write
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 ` Heiko Stuebner
2025-08-04 13:07 ` [PATCH 3/4] mfd: qnap-mcu: convert to guard(mutex) in qnap_mcu_exec Heiko Stuebner
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Heiko Stuebner @ 2025-08-04 13:07 UTC (permalink / raw)
To: lee; +Cc: heiko, linux-kernel
qnap_mcu_write can return errors and those were not checked before.
So do that now.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/mfd/qnap-mcu.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c
index e340e9337b98..6448237c4c35 100644
--- a/drivers/mfd/qnap-mcu.c
+++ b/drivers/mfd/qnap-mcu.c
@@ -163,7 +163,11 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
reply->received = 0;
reinit_completion(&reply->done);
- qnap_mcu_write(mcu, cmd_data, cmd_data_size);
+ ret = qnap_mcu_write(mcu, cmd_data, cmd_data_size);
+ if (ret < 0) {
+ mutex_unlock(&mcu->bus_lock);
+ return ret;
+ }
serdev_device_wait_until_sent(mcu->serdev, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS));
--
2.47.2
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 3/4] mfd: qnap-mcu: convert to guard(mutex) in qnap_mcu_exec
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
2025-08-04 13:07 ` [PATCH 4/4] mfd: qnap-mcu: improve structure " Heiko Stuebner
2025-09-02 7:58 ` [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Lee Jones
4 siblings, 0 replies; 7+ messages in thread
From: Heiko Stuebner @ 2025-08-04 13:07 UTC (permalink / raw)
To: lee; +Cc: heiko, linux-kernel
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
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 4/4] mfd: qnap-mcu: improve structure in qnap_mcu_exec
2025-08-04 13:07 [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Heiko Stuebner
` (2 preceding siblings ...)
2025-08-04 13:07 ` [PATCH 3/4] mfd: qnap-mcu: convert to guard(mutex) in qnap_mcu_exec Heiko Stuebner
@ 2025-08-04 13:07 ` Heiko Stuebner
2025-09-02 7:58 ` [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Lee Jones
4 siblings, 0 replies; 7+ messages in thread
From: Heiko Stuebner @ 2025-08-04 13:07 UTC (permalink / raw)
To: lee; +Cc: heiko, linux-kernel
Now with guard(mutex) in place, we can make the function's structure
a bit easier to read, by removing the nested if-else-clauses.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/mfd/qnap-mcu.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c
index 7bc44c64b7fd..2be429a50611 100644
--- a/drivers/mfd/qnap-mcu.c
+++ b/drivers/mfd/qnap-mcu.c
@@ -150,6 +150,7 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
size_t length = reply_data_size + QNAP_MCU_CHECKSUM_SIZE;
struct qnap_mcu_reply *reply = &mcu->reply;
int ret = 0;
+ u8 crc;
if (length > sizeof(rx)) {
dev_err(&mcu->serdev->dev, "expected data too big for receive buffer");
@@ -172,18 +173,16 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
if (!wait_for_completion_timeout(&reply->done, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS))) {
dev_err(&mcu->serdev->dev, "Command timeout\n");
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");
- return -EIO;
- } else {
- memcpy(reply_data, rx, reply_data_size);
- }
}
+ crc = qnap_mcu_csum(rx, reply_data_size);
+ if (crc != rx[reply_data_size]) {
+ dev_err(&mcu->serdev->dev, "Invalid Checksum received\n");
+ return -EIO;
+ }
+
+ memcpy(reply_data, rx, reply_data_size);
+
return 0;
}
EXPORT_SYMBOL_GPL(qnap_mcu_exec);
--
2.47.2
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements
2025-08-04 13:07 [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Heiko Stuebner
` (3 preceding siblings ...)
2025-08-04 13:07 ` [PATCH 4/4] mfd: qnap-mcu: improve structure " Heiko Stuebner
@ 2025-09-02 7:58 ` Lee Jones
2025-09-02 8:00 ` Lee Jones
4 siblings, 1 reply; 7+ messages in thread
From: Lee Jones @ 2025-09-02 7:58 UTC (permalink / raw)
To: lee, Heiko Stuebner; +Cc: linux-kernel
On Mon, 04 Aug 2025 15:07:22 +0200, Heiko Stuebner wrote:
> While digging through the mcu functions, I came across some deficits I
> introduced with the initial driver submission, so trying to make that
> a bit nicer with this series.
>
>
> I struggled a bit with the ordering of qnap_mcu_write error-check
> and conversion to guard(mutex). Converting to guard before the
> error check would need dropping the ret variable, just to re-add it
> one patch later - to not cause unused variable warning.
>
> [...]
Applied, thanks!
[1/4] mfd: qnap-mcu: include linux/types.h in qnap-mcu.h shared header
commit: f7ef7c03d8599a0d86b2a05929da73358cd56dcf
[2/4] mfd: qnap-mcu: handle errors returned from qnap_mcu_write
commit: 3d02c538ec5337b66750d83ce6f861aef263fbff
[3/4] mfd: qnap-mcu: convert to guard(mutex) in qnap_mcu_exec
commit: 5fd101541c6d0f0ad3b14d86dfcf9347c3f3bffd
[4/4] mfd: qnap-mcu: improve structure in qnap_mcu_exec
commit: 6cdb0fbe090be966432db041d5650907a4dceac4
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements
2025-09-02 7:58 ` [PATCH 0/4] mfd: qnap-mcu: Some fixes / improvements Lee Jones
@ 2025-09-02 8:00 ` Lee Jones
0 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2025-09-02 8:00 UTC (permalink / raw)
To: Heiko Stuebner; +Cc: linux-kernel
On Tue, 02 Sep 2025, Lee Jones wrote:
> On Mon, 04 Aug 2025 15:07:22 +0200, Heiko Stuebner wrote:
> > While digging through the mcu functions, I came across some deficits I
> > introduced with the initial driver submission, so trying to make that
> > a bit nicer with this series.
> >
> >
> > I struggled a bit with the ordering of qnap_mcu_write error-check
> > and conversion to guard(mutex). Converting to guard before the
> > error check would need dropping the ret variable, just to re-add it
> > one patch later - to not cause unused variable warning.
> >
> > [...]
>
> Applied, thanks!
>
> [1/4] mfd: qnap-mcu: include linux/types.h in qnap-mcu.h shared header
> commit: f7ef7c03d8599a0d86b2a05929da73358cd56dcf
> [2/4] mfd: qnap-mcu: handle errors returned from qnap_mcu_write
> commit: 3d02c538ec5337b66750d83ce6f861aef263fbff
> [3/4] mfd: qnap-mcu: convert to guard(mutex) in qnap_mcu_exec
> commit: 5fd101541c6d0f0ad3b14d86dfcf9347c3f3bffd
> [4/4] mfd: qnap-mcu: improve structure in qnap_mcu_exec
> commit: 6cdb0fbe090be966432db041d5650907a4dceac4
I fixed some issues in the commit messages for you pertaining to
spelling mistakes and expected format. Please not that in future, MFD
and LED (the submissions I've seen from you recently) take a capitalised
word as the start of the subject description.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 7+ messages in thread