[PATCH 02/13] drm/ast: Test if I2C support has been initialized

Sam Ravnborg sam at ravnborg.org
Tue Jul 28 17:38:46 UTC 2020


Hi Thomas.

On Tue, Jul 28, 2020 at 09:44:14AM +0200, Thomas Zimmermann wrote:
> The ast driver is supposed to work without I2C support. This is
> tested by looking at the connector's i2c field being non-NULL.
> 
> After embedding the I2C structure in the connector, the i2c field
> will not be a pointer. So change the test to look at the dev field
> in struct ast_i2c_chan.
> 
> ast_get_modes() did not really test if I2C has been initialized, so
> the patch adds this test as well.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
> ---
>  drivers/gpu/drm/ast/ast_mode.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> index 19f1dfc8e9e0..45be020afcad 100644
> --- a/drivers/gpu/drm/ast/ast_mode.c
> +++ b/drivers/gpu/drm/ast/ast_mode.c
> @@ -603,7 +603,6 @@ static struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
>  	i2c->adapter.owner = THIS_MODULE;
>  	i2c->adapter.class = I2C_CLASS_DDC;
>  	i2c->adapter.dev.parent = &dev->pdev->dev;
> -	i2c->dev = dev;
>  	i2c_set_adapdata(&i2c->adapter, i2c);
>  	snprintf(i2c->adapter.name, sizeof(i2c->adapter.name),
>  		 "AST i2c bit bus");
> @@ -622,17 +621,30 @@ static struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
>  		goto out_free;
>  	}
>  
> +	i2c->dev = dev; /* signals presence of I2C support */
> +
>  	return i2c;
>  out_free:
>  	kfree(i2c);
>  	return NULL;
>  }
>  
> -static void ast_i2c_destroy(struct ast_i2c_chan *i2c)
> +static bool ast_i2c_is_initialized(struct ast_i2c_chan *i2c)
>  {
> -	if (!i2c)
> +	return i2c && !!i2c->dev;
> +}
It seems pointless to convert the pointer to bool here ("!!").

> +
> +static void ast_i2c_fini(struct ast_i2c_chan *i2c)
> +{
> +	if (!ast_i2c_is_initialized(i2c))
>  		return;
Empty line after return?
>  	i2c_del_adapter(&i2c->adapter);
> +	i2c->dev = NULL; /* clear to signal absence of I2C support */
> +}
> +
> +static void ast_i2c_destroy(struct ast_i2c_chan *i2c)
> +{
> +	ast_i2c_fini(i2c);
>  	kfree(i2c);
>  }
>  
> @@ -1054,6 +1066,7 @@ static int ast_get_modes(struct drm_connector *connector)
>  {
>  	struct ast_connector *ast_connector = to_ast_connector(connector);
>  	struct ast_private *ast = to_ast_private(connector->dev);
> +	struct ast_i2c_chan *i2c = ast_connector->i2c;
>  	struct edid *edid;
>  	int ret;
>  	bool flags = false;
> @@ -1069,8 +1082,8 @@ static int ast_get_modes(struct drm_connector *connector)
>  		else
>  			kfree(edid);
>  	}
> -	if (!flags)
> -		edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
> +	if (!flags && ast_i2c_is_initialized(i2c))
> +		edid = drm_get_edid(connector, &i2c->adapter);
>  	if (edid) {
>  		drm_connector_update_edid_property(&ast_connector->base, edid);
>  		ret = drm_add_edid_modes(connector, edid);
> -- 
> 2.27.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


More information about the dri-devel mailing list