Skip to content

Commit d66cdb6

Browse files
committed
drm/ast: Fail probing if DDC channel could not be initialized
Expect the hardware to provide a DDC channel. Fail probing if its initialization fails. Failing to initialize the DDC indicates a larger problem, so there's no point in continuing. v4: * give a rational in the commit message Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Reviewed-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com> Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240325200855.21150-3-tzimmermann@suse.de
1 parent 8463b66 commit d66cdb6

3 files changed

Lines changed: 24 additions & 37 deletions

File tree

drivers/gpu/drm/ast/ast_drv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ struct ast_i2c_chan {
160160

161161
struct ast_vga_connector {
162162
struct drm_connector base;
163-
struct ast_i2c_chan *i2c;
164163
};
165164

166165
static inline struct ast_vga_connector *
@@ -171,7 +170,6 @@ to_ast_vga_connector(struct drm_connector *connector)
171170

172171
struct ast_sil164_connector {
173172
struct drm_connector base;
174-
struct ast_i2c_chan *i2c;
175173
};
176174

177175
static inline struct ast_sil164_connector *

drivers/gpu/drm/ast/ast_i2c.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
117117

118118
i2c = kzalloc(sizeof(struct ast_i2c_chan), GFP_KERNEL);
119119
if (!i2c)
120-
return NULL;
120+
return ERR_PTR(-ENOMEM);
121121

122122
i2c->adapter.owner = THIS_MODULE;
123123
i2c->adapter.dev.parent = dev->dev;
@@ -142,10 +142,11 @@ struct ast_i2c_chan *ast_i2c_create(struct drm_device *dev)
142142

143143
ret = drmm_add_action_or_reset(dev, ast_i2c_release, i2c);
144144
if (ret)
145-
return NULL;
145+
return ERR_PTR(ret);
146+
146147
return i2c;
147148

148149
out_kfree:
149150
kfree(i2c);
150-
return NULL;
151+
return ERR_PTR(ret);
151152
}

drivers/gpu/drm/ast/ast_mode.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,22 +1345,18 @@ static int ast_crtc_init(struct drm_device *dev)
13451345

13461346
static int ast_vga_connector_helper_get_modes(struct drm_connector *connector)
13471347
{
1348-
struct ast_vga_connector *ast_vga_connector = to_ast_vga_connector(connector);
13491348
struct drm_device *dev = connector->dev;
13501349
struct ast_device *ast = to_ast_device(dev);
13511350
struct edid *edid;
13521351
int count;
13531352

1354-
if (!ast_vga_connector->i2c)
1355-
goto err_drm_connector_update_edid_property;
1356-
13571353
/*
13581354
* Protect access to I/O registers from concurrent modesetting
13591355
* by acquiring the I/O-register lock.
13601356
*/
13611357
mutex_lock(&ast->modeset_lock);
13621358

1363-
edid = drm_get_edid(connector, &ast_vga_connector->i2c->adapter);
1359+
edid = drm_get_edid(connector, connector->ddc);
13641360
if (!edid)
13651361
goto err_mutex_unlock;
13661362

@@ -1373,7 +1369,6 @@ static int ast_vga_connector_helper_get_modes(struct drm_connector *connector)
13731369

13741370
err_mutex_unlock:
13751371
mutex_unlock(&ast->modeset_lock);
1376-
err_drm_connector_update_edid_property:
13771372
drm_connector_update_edid_property(connector, NULL);
13781373
return 0;
13791374
}
@@ -1394,19 +1389,18 @@ static int ast_vga_connector_init(struct drm_device *dev,
13941389
struct ast_vga_connector *ast_vga_connector)
13951390
{
13961391
struct drm_connector *connector = &ast_vga_connector->base;
1392+
struct ast_i2c_chan *i2c;
13971393
int ret;
13981394

1399-
ast_vga_connector->i2c = ast_i2c_create(dev);
1400-
if (!ast_vga_connector->i2c)
1401-
drm_err(dev, "failed to add ddc bus for connector\n");
1395+
i2c = ast_i2c_create(dev);
1396+
if (IS_ERR(i2c)) {
1397+
ret = PTR_ERR(i2c);
1398+
drm_err(dev, "failed to add ddc bus for connector; ret=%d\n", ret);
1399+
return ret;
1400+
}
14021401

1403-
if (ast_vga_connector->i2c)
1404-
ret = drm_connector_init_with_ddc(dev, connector, &ast_vga_connector_funcs,
1405-
DRM_MODE_CONNECTOR_VGA,
1406-
&ast_vga_connector->i2c->adapter);
1407-
else
1408-
ret = drm_connector_init(dev, connector, &ast_vga_connector_funcs,
1409-
DRM_MODE_CONNECTOR_VGA);
1402+
ret = drm_connector_init_with_ddc(dev, connector, &ast_vga_connector_funcs,
1403+
DRM_MODE_CONNECTOR_VGA, &i2c->adapter);
14101404
if (ret)
14111405
return ret;
14121406

@@ -1451,22 +1445,18 @@ static int ast_vga_output_init(struct ast_device *ast)
14511445

14521446
static int ast_sil164_connector_helper_get_modes(struct drm_connector *connector)
14531447
{
1454-
struct ast_sil164_connector *ast_sil164_connector = to_ast_sil164_connector(connector);
14551448
struct drm_device *dev = connector->dev;
14561449
struct ast_device *ast = to_ast_device(dev);
14571450
struct edid *edid;
14581451
int count;
14591452

1460-
if (!ast_sil164_connector->i2c)
1461-
goto err_drm_connector_update_edid_property;
1462-
14631453
/*
14641454
* Protect access to I/O registers from concurrent modesetting
14651455
* by acquiring the I/O-register lock.
14661456
*/
14671457
mutex_lock(&ast->modeset_lock);
14681458

1469-
edid = drm_get_edid(connector, &ast_sil164_connector->i2c->adapter);
1459+
edid = drm_get_edid(connector, connector->ddc);
14701460
if (!edid)
14711461
goto err_mutex_unlock;
14721462

@@ -1479,7 +1469,6 @@ static int ast_sil164_connector_helper_get_modes(struct drm_connector *connector
14791469

14801470
err_mutex_unlock:
14811471
mutex_unlock(&ast->modeset_lock);
1482-
err_drm_connector_update_edid_property:
14831472
drm_connector_update_edid_property(connector, NULL);
14841473
return 0;
14851474
}
@@ -1500,19 +1489,18 @@ static int ast_sil164_connector_init(struct drm_device *dev,
15001489
struct ast_sil164_connector *ast_sil164_connector)
15011490
{
15021491
struct drm_connector *connector = &ast_sil164_connector->base;
1492+
struct ast_i2c_chan *i2c;
15031493
int ret;
15041494

1505-
ast_sil164_connector->i2c = ast_i2c_create(dev);
1506-
if (!ast_sil164_connector->i2c)
1507-
drm_err(dev, "failed to add ddc bus for connector\n");
1495+
i2c = ast_i2c_create(dev);
1496+
if (IS_ERR(i2c)) {
1497+
ret = PTR_ERR(i2c);
1498+
drm_err(dev, "failed to add ddc bus for connector; ret=%d\n", ret);
1499+
return ret;
1500+
}
15081501

1509-
if (ast_sil164_connector->i2c)
1510-
ret = drm_connector_init_with_ddc(dev, connector, &ast_sil164_connector_funcs,
1511-
DRM_MODE_CONNECTOR_DVII,
1512-
&ast_sil164_connector->i2c->adapter);
1513-
else
1514-
ret = drm_connector_init(dev, connector, &ast_sil164_connector_funcs,
1515-
DRM_MODE_CONNECTOR_DVII);
1502+
ret = drm_connector_init_with_ddc(dev, connector, &ast_sil164_connector_funcs,
1503+
DRM_MODE_CONNECTOR_DVII, &i2c->adapter);
15161504
if (ret)
15171505
return ret;
15181506

0 commit comments

Comments
 (0)