Commit 0e1c42fd authored by Dave Airlie's avatar Dave Airlie Committed by Alex Deucher

amdgpu/dc: cleanup construct returns in gpio.

This is similiar to previous patches, don't return when we don't
need to, also do error checking before allocating memory, makes
it simpler to cleanup after.
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Reviewed-by: default avatarHarry Wentland <harry.wentland@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent b08c3ca4
...@@ -199,25 +199,14 @@ static const struct hw_gpio_pin_funcs funcs = { ...@@ -199,25 +199,14 @@ static const struct hw_gpio_pin_funcs funcs = {
.close = dal_hw_gpio_close, .close = dal_hw_gpio_close,
}; };
static bool construct( static void construct(
struct hw_ddc *ddc, struct hw_ddc *ddc,
enum gpio_id id, enum gpio_id id,
uint32_t en, uint32_t en,
struct dc_context *ctx) struct dc_context *ctx)
{ {
if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) { dal_hw_gpio_construct(&ddc->base, id, en, ctx);
ASSERT_CRITICAL(false);
return false;
}
if (!dal_hw_gpio_construct(&ddc->base, id, en, ctx)) {
ASSERT_CRITICAL(false);
return false;
}
ddc->base.base.funcs = &funcs; ddc->base.base.funcs = &funcs;
return true;
} }
struct hw_gpio_pin *dal_hw_ddc_create( struct hw_gpio_pin *dal_hw_ddc_create(
...@@ -225,19 +214,19 @@ struct hw_gpio_pin *dal_hw_ddc_create( ...@@ -225,19 +214,19 @@ struct hw_gpio_pin *dal_hw_ddc_create(
enum gpio_id id, enum gpio_id id,
uint32_t en) uint32_t en)
{ {
struct hw_ddc *pin = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL); struct hw_ddc *pin;
if (!pin) { if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; return NULL;
} }
if (construct(pin, id, en, ctx)) pin = kzalloc(sizeof(struct hw_ddc), GFP_KERNEL);
return &pin->base.base; if (!pin) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
kfree(pin);
return NULL; return NULL;
}
construct(pin, id, en, ctx);
return &pin->base.base;
} }
...@@ -176,7 +176,7 @@ enum gpio_result dal_hw_gpio_config_mode( ...@@ -176,7 +176,7 @@ enum gpio_result dal_hw_gpio_config_mode(
} }
} }
bool dal_hw_gpio_construct( void dal_hw_gpio_construct(
struct hw_gpio *pin, struct hw_gpio *pin,
enum gpio_id id, enum gpio_id id,
uint32_t en, uint32_t en,
...@@ -194,8 +194,6 @@ bool dal_hw_gpio_construct( ...@@ -194,8 +194,6 @@ bool dal_hw_gpio_construct(
pin->store.mux = 0; pin->store.mux = 0;
pin->mux_supported = false; pin->mux_supported = false;
return true;
} }
void dal_hw_gpio_destruct( void dal_hw_gpio_destruct(
......
...@@ -109,7 +109,7 @@ struct hw_gpio { ...@@ -109,7 +109,7 @@ struct hw_gpio {
#define HW_GPIO_FROM_BASE(hw_gpio_pin) \ #define HW_GPIO_FROM_BASE(hw_gpio_pin) \
container_of((hw_gpio_pin), struct hw_gpio, base) container_of((hw_gpio_pin), struct hw_gpio, base)
bool dal_hw_gpio_construct( void dal_hw_gpio_construct(
struct hw_gpio *pin, struct hw_gpio *pin,
enum gpio_id id, enum gpio_id id,
uint32_t en, uint32_t en,
......
...@@ -41,15 +41,13 @@ ...@@ -41,15 +41,13 @@
#define REG(reg)\ #define REG(reg)\
(hpd->regs->reg) (hpd->regs->reg)
static bool dal_hw_hpd_construct( static void dal_hw_hpd_construct(
struct hw_hpd *pin, struct hw_hpd *pin,
enum gpio_id id, enum gpio_id id,
uint32_t en, uint32_t en,
struct dc_context *ctx) struct dc_context *ctx)
{ {
if (!dal_hw_gpio_construct(&pin->base, id, en, ctx)) dal_hw_gpio_construct(&pin->base, id, en, ctx);
return false;
return true;
} }
static void dal_hw_hpd_destruct( static void dal_hw_hpd_destruct(
...@@ -126,30 +124,14 @@ static const struct hw_gpio_pin_funcs funcs = { ...@@ -126,30 +124,14 @@ static const struct hw_gpio_pin_funcs funcs = {
.close = dal_hw_gpio_close, .close = dal_hw_gpio_close,
}; };
static bool construct( static void construct(
struct hw_hpd *hpd, struct hw_hpd *hpd,
enum gpio_id id, enum gpio_id id,
uint32_t en, uint32_t en,
struct dc_context *ctx) struct dc_context *ctx)
{ {
if (id != GPIO_ID_HPD) { dal_hw_hpd_construct(hpd, id, en, ctx);
ASSERT_CRITICAL(false);
return false;
}
if ((en < GPIO_HPD_MIN) || (en > GPIO_HPD_MAX)) {
ASSERT_CRITICAL(false);
return false;
}
if (!dal_hw_hpd_construct(hpd, id, en, ctx)) {
ASSERT_CRITICAL(false);
return false;
}
hpd->base.base.funcs = &funcs; hpd->base.base.funcs = &funcs;
return true;
} }
struct hw_gpio_pin *dal_hw_hpd_create( struct hw_gpio_pin *dal_hw_hpd_create(
...@@ -157,19 +139,24 @@ struct hw_gpio_pin *dal_hw_hpd_create( ...@@ -157,19 +139,24 @@ struct hw_gpio_pin *dal_hw_hpd_create(
enum gpio_id id, enum gpio_id id,
uint32_t en) uint32_t en)
{ {
struct hw_hpd *hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL); struct hw_hpd *hpd;
if (!hpd) { if (id != GPIO_ID_HPD) {
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL; return NULL;
} }
if (construct(hpd, id, en, ctx)) if ((en < GPIO_HPD_MIN) || (en > GPIO_HPD_MAX)) {
return &hpd->base.base;
ASSERT_CRITICAL(false); ASSERT_CRITICAL(false);
return NULL;
}
kfree(hpd); hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL);
if (!hpd) {
ASSERT_CRITICAL(false);
return NULL; return NULL;
}
construct(hpd, id, en, ctx);
return &hpd->base.base;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment