Skip to content

Commit ac45314

Browse files
committed
drm/sti: hdmi: convert to devm_drm_bridge_alloc() API
devm_drm_bridge_alloc() is the new API to be used for allocating (and partially initializing) a private driver struct embedding a struct drm_bridge. This driver was missed during the automated conversion in commit 9c39971 ("drm: convert many bridge drivers from devm_kzalloc() to devm_drm_bridge_alloc() API") and following commits. The lack of conversion for this driver is a bug since commit a7748dd ("drm/bridge: get/put the bridge reference in drm_bridge_add/remove()") which is the first commmit having added a drm_bridge_get/put() pair and thus exposing the incorrect initial refcount issue. Fix this by switching the driver to the new API. Reported-by: Marek Szyprowski <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: a7748dd ("drm/bridge: get/put the bridge reference in drm_bridge_add/remove()") Reviewed-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/20250708-drm-bridge-convert-to-alloc-api-leftovers-v1-1-6285de8c3759@bootlin.com Signed-off-by: Luca Ceresoli <[email protected]>
1 parent 03d5236 commit ac45314

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

drivers/gpu/drm/sti/sti_hdmi.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ struct sti_hdmi_connector {
168168
#define to_sti_hdmi_connector(x) \
169169
container_of(x, struct sti_hdmi_connector, drm_connector)
170170

171+
static struct sti_hdmi *drm_bridge_to_sti_hdmi(struct drm_bridge *bridge)
172+
{
173+
return container_of(bridge, struct sti_hdmi, bridge);
174+
}
175+
171176
static const struct drm_prop_enum_list colorspace_mode_names[] = {
172177
{ HDMI_COLORSPACE_RGB, "rgb" },
173178
{ HDMI_COLORSPACE_YUV422, "yuv422" },
@@ -749,7 +754,7 @@ static void hdmi_debugfs_init(struct sti_hdmi *hdmi, struct drm_minor *minor)
749754

750755
static void sti_hdmi_disable(struct drm_bridge *bridge)
751756
{
752-
struct sti_hdmi *hdmi = bridge->driver_private;
757+
struct sti_hdmi *hdmi = drm_bridge_to_sti_hdmi(bridge);
753758

754759
u32 val = hdmi_read(hdmi, HDMI_CFG);
755760

@@ -881,7 +886,7 @@ static int hdmi_audio_configure(struct sti_hdmi *hdmi)
881886

882887
static void sti_hdmi_pre_enable(struct drm_bridge *bridge)
883888
{
884-
struct sti_hdmi *hdmi = bridge->driver_private;
889+
struct sti_hdmi *hdmi = drm_bridge_to_sti_hdmi(bridge);
885890

886891
DRM_DEBUG_DRIVER("\n");
887892

@@ -936,7 +941,7 @@ static void sti_hdmi_set_mode(struct drm_bridge *bridge,
936941
const struct drm_display_mode *mode,
937942
const struct drm_display_mode *adjusted_mode)
938943
{
939-
struct sti_hdmi *hdmi = bridge->driver_private;
944+
struct sti_hdmi *hdmi = drm_bridge_to_sti_hdmi(bridge);
940945
int ret;
941946

942947
DRM_DEBUG_DRIVER("\n");
@@ -1273,7 +1278,6 @@ static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
12731278
struct sti_hdmi_connector *connector;
12741279
struct cec_connector_info conn_info;
12751280
struct drm_connector *drm_connector;
1276-
struct drm_bridge *bridge;
12771281
int err;
12781282

12791283
/* Set the drm device handle */
@@ -1289,13 +1293,7 @@ static int sti_hdmi_bind(struct device *dev, struct device *master, void *data)
12891293

12901294
connector->hdmi = hdmi;
12911295

1292-
bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL);
1293-
if (!bridge)
1294-
return -EINVAL;
1295-
1296-
bridge->driver_private = hdmi;
1297-
bridge->funcs = &sti_hdmi_bridge_funcs;
1298-
drm_bridge_attach(encoder, bridge, NULL, 0);
1296+
drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0);
12991297

13001298
connector->encoder = encoder;
13011299

@@ -1385,9 +1383,9 @@ static int sti_hdmi_probe(struct platform_device *pdev)
13851383

13861384
DRM_INFO("%s\n", __func__);
13871385

1388-
hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
1389-
if (!hdmi)
1390-
return -ENOMEM;
1386+
hdmi = devm_drm_bridge_alloc(dev, struct sti_hdmi, bridge, &sti_hdmi_bridge_funcs);
1387+
if (IS_ERR(hdmi))
1388+
return PTR_ERR(hdmi);
13911389

13921390
ddc = of_parse_phandle(pdev->dev.of_node, "ddc", 0);
13931391
if (ddc) {

drivers/gpu/drm/sti/sti_hdmi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <media/cec-notifier.h>
1414

15+
#include <drm/drm_bridge.h>
1516
#include <drm/drm_modes.h>
1617
#include <drm/drm_property.h>
1718

@@ -86,6 +87,7 @@ struct sti_hdmi {
8687
struct hdmi_audio_params audio;
8788
struct drm_connector *drm_connector;
8889
struct cec_notifier *notifier;
90+
struct drm_bridge bridge;
8991
};
9092

9193
u32 hdmi_read(struct sti_hdmi *hdmi, int offset);

0 commit comments

Comments
 (0)