aboutsummaryrefslogtreecommitdiff
path: root/drivers/mfd
diff options
context:
space:
mode:
authorHeiko Stuebner <heiko@sntech.de>2025-11-13 17:52:17 +0100
committerLee Jones <lee@kernel.org>2025-11-20 10:14:07 +0000
commitc3223f562586307b1bcb014475d0b71913972145 (patch)
tree4424280ebe6976a56ac83bfa8ffdc5b900970add /drivers/mfd
parentc94fce30e190555d74e2769b5fe4a932d0ad432e (diff)
mfd: qnap-mcu: Move checksum verification to its own function
We'll need the checksum check in a second place in the future, so move the verification code to a separate function. Signed-off-by: Heiko Stuebner <heiko@sntech.de> Link: https://patch.msgid.link/20251113165218.449616-4-heiko@sntech.de Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/qnap-mcu.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c
index 1f4741cad875..558c3bc07ed3 100644
--- a/drivers/mfd/qnap-mcu.c
+++ b/drivers/mfd/qnap-mcu.c
@@ -78,6 +78,13 @@ static u8 qnap_mcu_csum(const u8 *buf, size_t size)
return csum;
}
+static bool qnap_mcu_verify_checksum(const u8 *buf, size_t size)
+{
+ u8 crc = qnap_mcu_csum(buf, size - QNAP_MCU_CHECKSUM_SIZE);
+
+ return crc == buf[size - QNAP_MCU_CHECKSUM_SIZE];
+}
+
static int qnap_mcu_write(struct qnap_mcu *mcu, const u8 *data, u8 data_size)
{
unsigned char tx[QNAP_MCU_TX_BUFFER_SIZE];
@@ -150,7 +157,6 @@ 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");
@@ -175,8 +181,7 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
return -ETIMEDOUT;
}
- crc = qnap_mcu_csum(rx, reply->received - QNAP_MCU_CHECKSUM_SIZE);
- if (crc != rx[reply->received - QNAP_MCU_CHECKSUM_SIZE]) {
+ if (!qnap_mcu_verify_checksum(rx, reply->received)) {
dev_err(&mcu->serdev->dev, "Invalid Checksum received\n");
return -EPROTO;
}