Skip to content

Commit c3223f5

Browse files
mmindlag-linaro
authored andcommitted
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>
1 parent c94fce3 commit c3223f5

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/mfd/qnap-mcu.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ static u8 qnap_mcu_csum(const u8 *buf, size_t size)
7878
return csum;
7979
}
8080

81+
static bool qnap_mcu_verify_checksum(const u8 *buf, size_t size)
82+
{
83+
u8 crc = qnap_mcu_csum(buf, size - QNAP_MCU_CHECKSUM_SIZE);
84+
85+
return crc == buf[size - QNAP_MCU_CHECKSUM_SIZE];
86+
}
87+
8188
static int qnap_mcu_write(struct qnap_mcu *mcu, const u8 *data, u8 data_size)
8289
{
8390
unsigned char tx[QNAP_MCU_TX_BUFFER_SIZE];
@@ -150,7 +157,6 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
150157
size_t length = reply_data_size + QNAP_MCU_CHECKSUM_SIZE;
151158
struct qnap_mcu_reply *reply = &mcu->reply;
152159
int ret = 0;
153-
u8 crc;
154160

155161
if (length > sizeof(rx)) {
156162
dev_err(&mcu->serdev->dev, "expected data too big for receive buffer");
@@ -175,8 +181,7 @@ int qnap_mcu_exec(struct qnap_mcu *mcu,
175181
return -ETIMEDOUT;
176182
}
177183

178-
crc = qnap_mcu_csum(rx, reply->received - QNAP_MCU_CHECKSUM_SIZE);
179-
if (crc != rx[reply->received - QNAP_MCU_CHECKSUM_SIZE]) {
184+
if (!qnap_mcu_verify_checksum(rx, reply->received)) {
180185
dev_err(&mcu->serdev->dev, "Invalid Checksum received\n");
181186
return -EPROTO;
182187
}

0 commit comments

Comments
 (0)