Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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
9c399719cfb9 ("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 a7748dd127ea
("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 <m.szyprowski@samsung.com>
Closes: https://lore.kernel.org/all/ce9c6aa3-5372-468f-a4bf-5a261259e459@samsung.com/
Fixes: a7748dd127ea ("drm/bridge: get/put the bridge reference in drm_bridge_add/remove()")
Reviewed-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250708-drm-bridge-convert-to-alloc-api-leftovers-v1-1-6285de8c3759@bootlin.com
Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>

+14 -14
+12 -14
drivers/gpu/drm/sti/sti_hdmi.c
··· 168 168 #define to_sti_hdmi_connector(x) \ 169 169 container_of(x, struct sti_hdmi_connector, drm_connector) 170 170 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 + 171 176 static const struct drm_prop_enum_list colorspace_mode_names[] = { 172 177 { HDMI_COLORSPACE_RGB, "rgb" }, 173 178 { HDMI_COLORSPACE_YUV422, "yuv422" }, ··· 754 749 755 750 static void sti_hdmi_disable(struct drm_bridge *bridge) 756 751 { 757 - struct sti_hdmi *hdmi = bridge->driver_private; 752 + struct sti_hdmi *hdmi = drm_bridge_to_sti_hdmi(bridge); 758 753 759 754 u32 val = hdmi_read(hdmi, HDMI_CFG); 760 755 ··· 886 881 887 882 static void sti_hdmi_pre_enable(struct drm_bridge *bridge) 888 883 { 889 - struct sti_hdmi *hdmi = bridge->driver_private; 884 + struct sti_hdmi *hdmi = drm_bridge_to_sti_hdmi(bridge); 890 885 891 886 DRM_DEBUG_DRIVER("\n"); 892 887 ··· 941 936 const struct drm_display_mode *mode, 942 937 const struct drm_display_mode *adjusted_mode) 943 938 { 944 - struct sti_hdmi *hdmi = bridge->driver_private; 939 + struct sti_hdmi *hdmi = drm_bridge_to_sti_hdmi(bridge); 945 940 int ret; 946 941 947 942 DRM_DEBUG_DRIVER("\n"); ··· 1278 1273 struct sti_hdmi_connector *connector; 1279 1274 struct cec_connector_info conn_info; 1280 1275 struct drm_connector *drm_connector; 1281 - struct drm_bridge *bridge; 1282 1276 int err; 1283 1277 1284 1278 /* Set the drm device handle */ ··· 1293 1289 1294 1290 connector->hdmi = hdmi; 1295 1291 1296 - bridge = devm_kzalloc(dev, sizeof(*bridge), GFP_KERNEL); 1297 - if (!bridge) 1298 - return -EINVAL; 1299 - 1300 - bridge->driver_private = hdmi; 1301 - bridge->funcs = &sti_hdmi_bridge_funcs; 1302 - drm_bridge_attach(encoder, bridge, NULL, 0); 1292 + drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0); 1303 1293 1304 1294 connector->encoder = encoder; 1305 1295 ··· 1383 1385 1384 1386 DRM_INFO("%s\n", __func__); 1385 1387 1386 - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); 1387 - if (!hdmi) 1388 - return -ENOMEM; 1388 + hdmi = devm_drm_bridge_alloc(dev, struct sti_hdmi, bridge, &sti_hdmi_bridge_funcs); 1389 + if (IS_ERR(hdmi)) 1390 + return PTR_ERR(hdmi); 1389 1391 1390 1392 ddc = of_parse_phandle(pdev->dev.of_node, "ddc", 0); 1391 1393 if (ddc) {
+2
drivers/gpu/drm/sti/sti_hdmi.h
··· 12 12 13 13 #include <media/cec-notifier.h> 14 14 15 + #include <drm/drm_bridge.h> 15 16 #include <drm/drm_modes.h> 16 17 #include <drm/drm_property.h> 17 18 ··· 87 86 struct hdmi_audio_params audio; 88 87 struct drm_connector *drm_connector; 89 88 struct cec_notifier *notifier; 89 + struct drm_bridge bridge; 90 90 }; 91 91 92 92 u32 hdmi_read(struct sti_hdmi *hdmi, int offset);