]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
greybus: gb-beagleplay: Fix timeout handling in bootloader functions
authorHaotian Zhang <vulab@iscas.ac.cn>
Fri, 21 Nov 2025 06:40:27 +0000 (14:40 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2025 13:40:59 +0000 (14:40 +0100)
wait_for_completion_timeout() returns the remaining jiffies
(at least 1) on success or 0 on timeout, but never negative
error codes. The current code incorrectly checks for negative
values, causing timeouts to be ignored and treated as success.

Check for a zero return value to correctly identify and
handle timeout events.

Fixes: 0cf7befa3ea2 ("greybus: gb-beagleplay: Add firmware upload API")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Link: https://patch.msgid.link/20251121064027.571-1-vulab@iscas.ac.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/greybus/gb-beagleplay.c

index 9610f878da1b682f4de8d3ab8c3632916ad3da7a..87186f891a6acb4d4f48f87b04bf38cdcddcfad3 100644 (file)
@@ -644,8 +644,8 @@ static int cc1352_bootloader_wait_for_ack(struct gb_beagleplay *bg)
 
        ret = wait_for_completion_timeout(
                &bg->fwl_ack_com, msecs_to_jiffies(CC1352_BOOTLOADER_TIMEOUT));
-       if (ret < 0)
-               return dev_err_probe(&bg->sd->dev, ret,
+       if (!ret)
+               return dev_err_probe(&bg->sd->dev, -ETIMEDOUT,
                                     "Failed to acquire ack semaphore");
 
        switch (READ_ONCE(bg->fwl_ack)) {
@@ -683,8 +683,8 @@ static int cc1352_bootloader_get_status(struct gb_beagleplay *bg)
        ret = wait_for_completion_timeout(
                &bg->fwl_cmd_response_com,
                msecs_to_jiffies(CC1352_BOOTLOADER_TIMEOUT));
-       if (ret < 0)
-               return dev_err_probe(&bg->sd->dev, ret,
+       if (!ret)
+               return dev_err_probe(&bg->sd->dev, -ETIMEDOUT,
                                     "Failed to acquire last status semaphore");
 
        switch (READ_ONCE(bg->fwl_cmd_response)) {
@@ -768,8 +768,8 @@ static int cc1352_bootloader_crc32(struct gb_beagleplay *bg, u32 *crc32)
        ret = wait_for_completion_timeout(
                &bg->fwl_cmd_response_com,
                msecs_to_jiffies(CC1352_BOOTLOADER_TIMEOUT));
-       if (ret < 0)
-               return dev_err_probe(&bg->sd->dev, ret,
+       if (!ret)
+               return dev_err_probe(&bg->sd->dev, -ETIMEDOUT,
                                     "Failed to acquire last status semaphore");
 
        *crc32 = READ_ONCE(bg->fwl_cmd_response);