drm/amd/display: refactor gpio to allocate hw_container in constructor

[why]
if dynamic allocation fails during gpio_open, it will cause crash due to
page fault.

[how]
handle allocation when gpio object gets created and prevent from calling
gpio_open if allocation failed

Signed-off-by: Su Sung Chung <Su.Chung@amd.com>
Reviewed-by: Jun Lei <Jun.Lei@amd.com>
Acked-by: Leo Li <sunpeng.li@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Su Sung Chung
2019-07-08 11:31:39 -04:00
committed by Alex Deucher
parent 37495fbdf1
commit 91db931194
18 changed files with 247 additions and 139 deletions

View File

@@ -67,10 +67,14 @@ enum gpio_result dal_gpio_open_ex(
return GPIO_RESULT_ALREADY_OPENED;
}
// No action if allocation failed during gpio construct
if (!gpio->hw_container.ddc) {
ASSERT_CRITICAL(false);
return GPIO_RESULT_NON_SPECIFIC_ERROR;
}
gpio->mode = mode;
return dal_gpio_service_open(
gpio->service, gpio->id, gpio->en, mode, &gpio->pin);
return dal_gpio_service_open(gpio);
}
enum gpio_result dal_gpio_get_value(
@@ -231,6 +235,21 @@ enum gpio_pin_output_state dal_gpio_get_output_state(
return gpio->output_state;
}
struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio)
{
return gpio->hw_container.ddc;
}
struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio)
{
return gpio->hw_container.hpd;
}
struct hw_generic *dal_gpio_get_generic(struct gpio *gpio)
{
return gpio->hw_container.generic;
}
void dal_gpio_close(
struct gpio *gpio)
{
@@ -267,6 +286,30 @@ struct gpio *dal_gpio_create(
gpio->mode = GPIO_MODE_UNKNOWN;
gpio->output_state = output_state;
//initialize hw_container union based on id
switch (gpio->id) {
case GPIO_ID_DDC_DATA:
gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
break;
case GPIO_ID_DDC_CLOCK:
gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
break;
case GPIO_ID_GENERIC:
gpio->service->factory.funcs->init_generic(&gpio->hw_container.generic, service->ctx, id, en);
break;
case GPIO_ID_HPD:
gpio->service->factory.funcs->init_hpd(&gpio->hw_container.hpd, service->ctx, id, en);
break;
// TODO: currently gpio for sync and gsl does not get created, might need it later
case GPIO_ID_SYNC:
break;
case GPIO_ID_GSL:
break;
default:
ASSERT_CRITICAL(false);
gpio->pin = NULL;
}
return gpio;
}
@@ -280,6 +323,33 @@ void dal_gpio_destroy(
dal_gpio_close(*gpio);
switch ((*gpio)->id) {
case GPIO_ID_DDC_DATA:
kfree((*gpio)->hw_container.ddc);
(*gpio)->hw_container.ddc = NULL;
break;
case GPIO_ID_DDC_CLOCK:
//TODO: might want to change it to init_ddc_clock
kfree((*gpio)->hw_container.ddc);
(*gpio)->hw_container.ddc = NULL;
break;
case GPIO_ID_GENERIC:
kfree((*gpio)->hw_container.generic);
(*gpio)->hw_container.generic = NULL;
break;
case GPIO_ID_HPD:
kfree((*gpio)->hw_container.hpd);
(*gpio)->hw_container.hpd = NULL;
break;
// TODO: currently gpio for sync and gsl does not get created, might need it later
case GPIO_ID_SYNC:
break;
case GPIO_ID_GSL:
break;
default:
break;
}
kfree(*gpio);
*gpio = NULL;