Skip to content

Commit

Permalink
drm/amd/display: Check gpio_id before used as array index
Browse files Browse the repository at this point in the history
[ Upstream commit 2a5626e ]

[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 <[email protected]>
Acked-by: Tom Chung <[email protected]>
Signed-off-by: Alex Hung <[email protected]>
Tested-by: Daniel Wheeler <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Alex Hung authored and gregkh committed Sep 8, 2024
1 parent 30e60db commit 08e7755
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 08e7755

Please sign in to comment.