Expect the hardware to provide a DDC channel. Fail probing if its initialization fails. Signed-off-by: Thomas Zimmermann <tzimmermann@xxxxxxx> Reviewed-by: Patrik Jakobsson <patrik.r.jakobsson@xxxxxxxxx> --- drivers/gpu/drm/ast/ast_drv.h | 2 -- drivers/gpu/drm/ast/ast_i2c.c | 7 ++++--- drivers/gpu/drm/ast/ast_mode.c | 38 ++++++++++++++++------------------ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h index a34db4380f68..bc01090d0ad1 100644 --- a/drivers/gpu/drm/ast/ast_drv.h +++ b/drivers/gpu/drm/ast/ast_drv.h @@ -137,7 +137,6 @@ struct ast_i2c_chan { struct ast_vga_connector { struct drm_connector base; - struct ast_i2c_chan *i2c; }; static inline struct ast_vga_connector * @@ -148,7 +147,6 @@ to_ast_vga_connector(struct drm_connector *connector) struct ast_sil164_connector { struct drm_connector base; - struct ast_i2c_chan *i2c; }; static inline struct ast_sil164_connector * diff --git a/drivers/gpu/drm/ast/ast_i2c.c b/drivers/gpu/drm/ast/ast_i2c.c index 93e91c36d649..1d039ff1396e 100644 --- a/drivers/gpu/drm/ast/ast_i2c.c +++ b/drivers/gpu/drm/ast/ast_i2c.c @@ -117,7 +117,7 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev) i2c = kzalloc(sizeof(struct ast_i2c_chan), GFP_KERNEL); if (!i2c) - return NULL; + return ERR_PTR(-ENOMEM); i2c->adapter.owner = THIS_MODULE; i2c->adapter.class = I2C_CLASS_DDC; @@ -143,10 +143,11 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev) ret = drmm_add_action_or_reset(dev, ast_i2c_release, i2c); if (ret) - return NULL; + return ERR_PTR(ret); + return i2c; out_kfree: kfree(i2c); - return NULL; + return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c index 582f278436ea..364035d22463 100644 --- a/drivers/gpu/drm/ast/ast_mode.c +++ b/drivers/gpu/drm/ast/ast_mode.c @@ -1334,19 +1334,18 @@ static int ast_vga_connector_init(struct drm_device *dev, struct ast_vga_connector *ast_vga_connector) { struct drm_connector *connector = &ast_vga_connector->base; + struct ast_i2c_chan *i2c; int ret; - ast_vga_connector->i2c = ast_i2c_create(dev); - if (!ast_vga_connector->i2c) - drm_err(dev, "failed to add ddc bus for connector\n"); + i2c = ast_i2c_create(dev); + if (IS_ERR(i2c)) { + ret = PTR_ERR(i2c); + drm_err(dev, "failed to add ddc bus for connector; ret=%d\n", ret); + return ret; + } - if (ast_vga_connector->i2c) - ret = drm_connector_init_with_ddc(dev, connector, &ast_vga_connector_funcs, - DRM_MODE_CONNECTOR_VGA, - &ast_vga_connector->i2c->adapter); - else - ret = drm_connector_init(dev, connector, &ast_vga_connector_funcs, - DRM_MODE_CONNECTOR_VGA); + ret = drm_connector_init_with_ddc(dev, connector, &ast_vga_connector_funcs, + DRM_MODE_CONNECTOR_VGA, &i2c->adapter); if (ret) return ret; @@ -1406,19 +1405,18 @@ static int ast_sil164_connector_init(struct drm_device *dev, struct ast_sil164_connector *ast_sil164_connector) { struct drm_connector *connector = &ast_sil164_connector->base; + struct ast_i2c_chan *i2c; int ret; - ast_sil164_connector->i2c = ast_i2c_create(dev); - if (!ast_sil164_connector->i2c) - drm_err(dev, "failed to add ddc bus for connector\n"); + i2c = ast_i2c_create(dev); + if (IS_ERR(i2c)) { + ret = PTR_ERR(i2c); + drm_err(dev, "failed to add ddc bus for connector; ret=%d\n", ret); + return ret; + } - if (ast_sil164_connector->i2c) - ret = drm_connector_init_with_ddc(dev, connector, &ast_sil164_connector_funcs, - DRM_MODE_CONNECTOR_DVII, - &ast_sil164_connector->i2c->adapter); - else - ret = drm_connector_init(dev, connector, &ast_sil164_connector_funcs, - DRM_MODE_CONNECTOR_DVII); + ret = drm_connector_init_with_ddc(dev, connector, &ast_sil164_connector_funcs, + DRM_MODE_CONNECTOR_DVII, &i2c->adapter); if (ret) return ret; -- 2.36.1