Skip to content

Commit 602d565

Browse files
committed
drm/sti: hda: 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-2-6285de8c3759@bootlin.com Signed-off-by: Luca Ceresoli <[email protected]>
1 parent ac45314 commit 602d565

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

drivers/gpu/drm/sti/sti_hda.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ struct sti_hda {
246246
struct device dev;
247247
struct drm_device *drm_dev;
248248
struct drm_display_mode mode;
249+
struct drm_bridge bridge;
249250
void __iomem *regs;
250251
void __iomem *video_dacs_ctrl;
251252
struct clk *clk_pix;
@@ -262,6 +263,11 @@ struct sti_hda_connector {
262263
#define to_sti_hda_connector(x) \
263264
container_of(x, struct sti_hda_connector, drm_connector)
264265

266+
static struct sti_hda *drm_bridge_to_sti_hda(struct drm_bridge *bridge)
267+
{
268+
return container_of(bridge, struct sti_hda, bridge);
269+
}
270+
265271
static u32 hda_read(struct sti_hda *hda, int offset)
266272
{
267273
return readl(hda->regs + offset);
@@ -401,7 +407,7 @@ static void sti_hda_configure_awg(struct sti_hda *hda, u32 *awg_instr, int nb)
401407

402408
static void sti_hda_disable(struct drm_bridge *bridge)
403409
{
404-
struct sti_hda *hda = bridge->driver_private;
410+
struct sti_hda *hda = drm_bridge_to_sti_hda(bridge);
405411
u32 val;
406412

407413
if (!hda->enabled)
@@ -426,7 +432,7 @@ static void sti_hda_disable(struct drm_bridge *bridge)
426432

427433
static void sti_hda_pre_enable(struct drm_bridge *bridge)
428434
{
429-
struct sti_hda *hda = bridge->driver_private;
435+
struct sti_hda *hda = drm_bridge_to_sti_hda(bridge);
430436
u32 val, i, mode_idx;
431437
u32 src_filter_y, src_filter_c;
432438
u32 *coef_y, *coef_c;
@@ -517,7 +523,7 @@ static void sti_hda_set_mode(struct drm_bridge *bridge,
517523
const struct drm_display_mode *mode,
518524
const struct drm_display_mode *adjusted_mode)
519525
{
520-
struct sti_hda *hda = bridge->driver_private;
526+
struct sti_hda *hda = drm_bridge_to_sti_hda(bridge);
521527
u32 mode_idx;
522528
int hddac_rate;
523529
int ret;
@@ -677,7 +683,6 @@ static int sti_hda_bind(struct device *dev, struct device *master, void *data)
677683
struct drm_encoder *encoder;
678684
struct sti_hda_connector *connector;
679685
struct drm_connector *drm_connector;
680-
struct drm_bridge *bridge;
681686
int err;
682687

683688
/* Set the drm device handle */
@@ -693,13 +698,7 @@ static int sti_hda_bind(struct device *dev, struct device *master, void *data)
693698

694699
connector->hda = hda;
695700

696-
bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL);
697-
if (!bridge)
698-
return -ENOMEM;
699-
700-
bridge->driver_private = hda;
701-
bridge->funcs = &sti_hda_bridge_funcs;
702-
drm_bridge_attach(encoder, bridge, NULL, 0);
701+
drm_bridge_attach(encoder, &hda->bridge, NULL, 0);
703702

704703
connector->encoder = encoder;
705704

@@ -745,9 +744,9 @@ static int sti_hda_probe(struct platform_device *pdev)
745744

746745
DRM_INFO("%s\n", __func__);
747746

748-
hda = devm_kzalloc(dev, sizeof(*hda), GFP_KERNEL);
749-
if (!hda)
750-
return -ENOMEM;
747+
hda = devm_drm_bridge_alloc(dev, struct sti_hda, bridge, &sti_hda_bridge_funcs);
748+
if (IS_ERR(hda))
749+
return PTR_ERR(hda);
751750

752751
hda->dev = pdev->dev;
753752
hda->regs = devm_platform_ioremap_resource_byname(pdev, "hda-reg");

0 commit comments

Comments
 (0)