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: 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>

authored by

Heiko Stuebner and committed by
Lee Jones
21c5ffb4 bf2de430

+5 -8
+5 -8
drivers/mfd/qnap-mcu.c
··· 156 156 return -EINVAL; 157 157 } 158 158 159 - mutex_lock(&mcu->bus_lock); 159 + guard(mutex)(&mcu->bus_lock); 160 160 161 161 reply->data = rx; 162 162 reply->length = length; ··· 164 164 reinit_completion(&reply->done); 165 165 166 166 ret = qnap_mcu_write(mcu, cmd_data, cmd_data_size); 167 - if (ret < 0) { 168 - mutex_unlock(&mcu->bus_lock); 167 + if (ret < 0) 169 168 return ret; 170 - } 171 169 172 170 serdev_device_wait_until_sent(mcu->serdev, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS)); 173 171 174 172 if (!wait_for_completion_timeout(&reply->done, msecs_to_jiffies(QNAP_MCU_TIMEOUT_MS))) { 175 173 dev_err(&mcu->serdev->dev, "Command timeout\n"); 176 - ret = -ETIMEDOUT; 174 + return -ETIMEDOUT; 177 175 } else { 178 176 u8 crc = qnap_mcu_csum(rx, reply_data_size); 179 177 180 178 if (crc != rx[reply_data_size]) { 181 179 dev_err(&mcu->serdev->dev, 182 180 "Invalid Checksum received\n"); 183 - ret = -EIO; 181 + return -EIO; 184 182 } else { 185 183 memcpy(reply_data, rx, reply_data_size); 186 184 } 187 185 } 188 186 189 - mutex_unlock(&mcu->bus_lock); 190 - return ret; 187 + return 0; 191 188 } 192 189 EXPORT_SYMBOL_GPL(qnap_mcu_exec); 193 190