]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:06:39 +0000 (11:06 +0200)
[ Upstream commit 2a5626eeb3b5eec7a36886f9556113dd93ec8ed6 ]

[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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c

index dae8e489c8cf40410947d88842303af1cacb8a71..a7c92c64490c55a73f765812886e01bc521ee2e1 100644 (file)
@@ -241,6 +241,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];
 }
 
@@ -249,6 +252,9 @@ static void set_pin_busy(
        enum gpio_id id,
        uint32_t en)
 {
+       if (id == GPIO_ID_UNKNOWN)
+               return;
+
        service->busyness[id][en] = true;
 }
 
@@ -257,6 +263,9 @@ static void set_pin_free(
        enum gpio_id id,
        uint32_t en)
 {
+       if (id == GPIO_ID_UNKNOWN)
+               return;
+
        service->busyness[id][en] = false;
 }
 
@@ -265,7 +274,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;
        }
@@ -279,7 +288,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;
        }