]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/display: Check gpio_id before used as array index
authorAlex Hung <alex.hung@amd.com>
Tue, 16 Apr 2024 22:40:00 +0000 (16:40 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 2 May 2024 20:18:16 +0000 (16:18 -0400)
[WHY & HOW]
GPIO_ID_UNKNOWN (-1) is not a valid value for array index and therefore
should be checked in advance.

This fixes 5 OVERRUN issues reported by Coverity.

Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Acked-by: Tom Chung <chiahsuan.chung@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c

index 663c17f52779cccbb866a8b54c6a35a92d6e9b3b..d19d5c177022258c559513e3a415ed5396982674 100644 (file)
@@ -239,6 +239,9 @@ static bool is_pin_busy(
        enum gpio_id id,
        uint32_t en)
 {
+       if (id == GPIO_ID_UNKNOWN)
+               return false;
+
        return service->busyness[id][en];
 }
 
@@ -247,6 +250,9 @@ static void set_pin_busy(
        enum gpio_id id,
        uint32_t en)
 {
+       if (id == GPIO_ID_UNKNOWN)
+               return;
+
        service->busyness[id][en] = true;
 }
 
@@ -255,6 +261,9 @@ static void set_pin_free(
        enum gpio_id id,
        uint32_t en)
 {
+       if (id == GPIO_ID_UNKNOWN)
+               return;
+
        service->busyness[id][en] = false;
 }
 
@@ -263,7 +272,7 @@ enum gpio_result dal_gpio_service_lock(
        enum gpio_id id,
        uint32_t en)
 {
-       if (!service->busyness[id]) {
+       if (id != GPIO_ID_UNKNOWN && !service->busyness[id]) {
                ASSERT_CRITICAL(false);
                return GPIO_RESULT_OPEN_FAILED;
        }
@@ -277,7 +286,7 @@ enum gpio_result dal_gpio_service_unlock(
        enum gpio_id id,
        uint32_t en)
 {
-       if (!service->busyness[id]) {
+       if (id != GPIO_ID_UNKNOWN && !service->busyness[id]) {
                ASSERT_CRITICAL(false);
                return GPIO_RESULT_OPEN_FAILED;
        }