Message ID | 20240911115347.899148-9-tzimmermann@suse.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm/ast: Various cleanups | expand |
On 11/09/2024 13:51, Thomas Zimmermann wrote: > Inline ast_vga_connector_init() into its only caller. The helper > currently only does half of the connector-init work and is trivial > enough to be inlined. While at it, remove the error message from the > call to ast_ddc_create(). The function already warns on errors. > > Also set the local variables for encoder and connector as late as > possible, so that the compiler warns if we use them before having > initialized the instance. Thanks, it looks good to me. Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> > > Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> > --- > drivers/gpu/drm/ast/ast_vga.c | 55 +++++++++++++++++------------------ > 1 file changed, 26 insertions(+), 29 deletions(-) > > diff --git a/drivers/gpu/drm/ast/ast_vga.c b/drivers/gpu/drm/ast/ast_vga.c > index 3e815da43fbd..5c79b773af57 100644 > --- a/drivers/gpu/drm/ast/ast_vga.c > +++ b/drivers/gpu/drm/ast/ast_vga.c > @@ -71,52 +71,49 @@ static const struct drm_connector_funcs ast_vga_connector_funcs = { > .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, > }; > > -static int ast_vga_connector_init(struct drm_device *dev, struct drm_connector *connector) > +/* > + * Output > + */ > + > +int ast_vga_output_init(struct ast_device *ast) > { > - struct ast_device *ast = to_ast_device(dev); > + struct drm_device *dev = &ast->base; > + struct drm_crtc *crtc = &ast->crtc; > struct i2c_adapter *ddc; > + struct drm_encoder *encoder; > + struct ast_connector *ast_connector; > + struct drm_connector *connector; > int ret; > > + /* DDC */ > + > ddc = ast_ddc_create(ast); > - if (IS_ERR(ddc)) { > - ret = PTR_ERR(ddc); > - drm_err(dev, "failed to add DDC bus for connector; ret=%d\n", ret); > + if (IS_ERR(ddc)) > + return PTR_ERR(ddc); > + > + /* encoder */ > + > + encoder = &ast->output.vga.encoder; > + ret = drm_encoder_init(dev, encoder, &ast_vga_encoder_funcs, > + DRM_MODE_ENCODER_DAC, NULL); > + if (ret) > return ret; > - } > + encoder->possible_crtcs = drm_crtc_mask(crtc); > + > + /* connector */ > > + ast_connector = &ast->output.vga.connector; > + connector = &ast_connector->base; > ret = drm_connector_init_with_ddc(dev, connector, &ast_vga_connector_funcs, > DRM_MODE_CONNECTOR_VGA, ddc); > if (ret) > return ret; > - > drm_connector_helper_add(connector, &ast_vga_connector_helper_funcs); > > connector->interlace_allowed = 0; > connector->doublescan_allowed = 0; > - > connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; > > - return 0; > -} > - > -int ast_vga_output_init(struct ast_device *ast) > -{ > - struct drm_device *dev = &ast->base; > - struct drm_crtc *crtc = &ast->crtc; > - struct drm_encoder *encoder = &ast->output.vga.encoder; > - struct ast_connector *ast_connector = &ast->output.vga.connector; > - struct drm_connector *connector = &ast_connector->base; > - int ret; > - > - ret = drm_encoder_init(dev, encoder, &ast_vga_encoder_funcs, > - DRM_MODE_ENCODER_DAC, NULL); > - if (ret) > - return ret; > - encoder->possible_crtcs = drm_crtc_mask(crtc); > - > - ret = ast_vga_connector_init(dev, connector); > - if (ret) > - return ret; > ast_connector->physical_status = connector->status; > > ret = drm_connector_attach_encoder(connector, encoder);
diff --git a/drivers/gpu/drm/ast/ast_vga.c b/drivers/gpu/drm/ast/ast_vga.c index 3e815da43fbd..5c79b773af57 100644 --- a/drivers/gpu/drm/ast/ast_vga.c +++ b/drivers/gpu/drm/ast/ast_vga.c @@ -71,52 +71,49 @@ static const struct drm_connector_funcs ast_vga_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_vga_connector_init(struct drm_device *dev, struct drm_connector *connector) +/* + * Output + */ + +int ast_vga_output_init(struct ast_device *ast) { - struct ast_device *ast = to_ast_device(dev); + struct drm_device *dev = &ast->base; + struct drm_crtc *crtc = &ast->crtc; struct i2c_adapter *ddc; + struct drm_encoder *encoder; + struct ast_connector *ast_connector; + struct drm_connector *connector; int ret; + /* DDC */ + ddc = ast_ddc_create(ast); - if (IS_ERR(ddc)) { - ret = PTR_ERR(ddc); - drm_err(dev, "failed to add DDC bus for connector; ret=%d\n", ret); + if (IS_ERR(ddc)) + return PTR_ERR(ddc); + + /* encoder */ + + encoder = &ast->output.vga.encoder; + ret = drm_encoder_init(dev, encoder, &ast_vga_encoder_funcs, + DRM_MODE_ENCODER_DAC, NULL); + if (ret) return ret; - } + encoder->possible_crtcs = drm_crtc_mask(crtc); + + /* connector */ + ast_connector = &ast->output.vga.connector; + connector = &ast_connector->base; ret = drm_connector_init_with_ddc(dev, connector, &ast_vga_connector_funcs, DRM_MODE_CONNECTOR_VGA, ddc); if (ret) return ret; - drm_connector_helper_add(connector, &ast_vga_connector_helper_funcs); connector->interlace_allowed = 0; connector->doublescan_allowed = 0; - connector->polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; - return 0; -} - -int ast_vga_output_init(struct ast_device *ast) -{ - struct drm_device *dev = &ast->base; - struct drm_crtc *crtc = &ast->crtc; - struct drm_encoder *encoder = &ast->output.vga.encoder; - struct ast_connector *ast_connector = &ast->output.vga.connector; - struct drm_connector *connector = &ast_connector->base; - int ret; - - ret = drm_encoder_init(dev, encoder, &ast_vga_encoder_funcs, - DRM_MODE_ENCODER_DAC, NULL); - if (ret) - return ret; - encoder->possible_crtcs = drm_crtc_mask(crtc); - - ret = ast_vga_connector_init(dev, connector); - if (ret) - return ret; ast_connector->physical_status = connector->status; ret = drm_connector_attach_encoder(connector, encoder);
Inline ast_vga_connector_init() into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined. While at it, remove the error message from the call to ast_ddc_create(). The function already warns on errors. Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance. Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> --- drivers/gpu/drm/ast/ast_vga.c | 55 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)