Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Heiko Stuebner and committed by
Lee Jones
c3223f56 c94fce30

+8 -3
+8 -3
drivers/mfd/qnap-mcu.c
··· 78 78 return csum; 79 79 } 80 80 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 + 81 88 static int qnap_mcu_write(struct qnap_mcu *mcu, const u8 *data, u8 data_size) 82 89 { 83 90 unsigned char tx[QNAP_MCU_TX_BUFFER_SIZE]; ··· 157 150 size_t length = reply_data_size + QNAP_MCU_CHECKSUM_SIZE; 158 151 struct qnap_mcu_reply *reply = &mcu->reply; 159 152 int ret = 0; 160 - u8 crc; 161 153 162 154 if (length > sizeof(rx)) { 163 155 dev_err(&mcu->serdev->dev, "expected data too big for receive buffer"); ··· 181 175 return -ETIMEDOUT; 182 176 } 183 177 184 - crc = qnap_mcu_csum(rx, reply->received - QNAP_MCU_CHECKSUM_SIZE); 185 - if (crc != rx[reply->received - QNAP_MCU_CHECKSUM_SIZE]) { 178 + if (!qnap_mcu_verify_checksum(rx, reply->received)) { 186 179 dev_err(&mcu->serdev->dev, "Invalid Checksum received\n"); 187 180 return -EPROTO; 188 181 }