Skip to content

Commit 48f05c3

Browse files
mszyprowlucaceresoli
authored andcommitted
drm/bridge: analogix_dp: Use 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. Analogix DP driver somehow missed the automated conversion in commit 9c39971 ("drm: convert many bridge drivers from devm_kzalloc() to devm_drm_bridge_alloc() API"), what causes the following warning: ------------[ cut here ]------------ WARNING: lib/refcount.c:25 at drm_bridge_attach+0x2c/0x248, CPU#1: kworker/u8:1/34 refcount_t: addition on 0; use-after-free. Modules linked in: CPU: 1 UID: 0 PID: 34 Comm: kworker/u8:1 Not tainted 6.16.0-rc3-next-20250627-dirty #15839 PREEMPT Hardware name: Samsung Exynos (Flattened Device Tree) Workqueue: events_unbound deferred_probe_work_func Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x68/0x88 dump_stack_lvl from __warn+0x94/0x1f0 __warn from warn_slowpath_fmt+0x124/0x1bc warn_slowpath_fmt from drm_bridge_attach+0x2c/0x248 drm_bridge_attach from analogix_dp_bind+0x70/0xc8 analogix_dp_bind from exynos_dp_bind+0x58/0xc4 exynos_dp_bind from component_bind_all+0x11c/0x27c component_bind_all from exynos_drm_bind+0xe8/0x198 exynos_drm_bind from try_to_bring_up_aggregate_device+0x200/0x2d8 try_to_bring_up_aggregate_device from __component_add+0xb0/0x170 __component_add from exynos_dp_probe+0xc0/0x164 exynos_dp_probe from platform_probe+0x5c/0xb8 platform_probe from really_probe+0xe0/0x3d8 really_probe from __driver_probe_device+0x9c/0x1e0 __driver_probe_device from driver_probe_device+0x30/0xc0 driver_probe_device from __device_attach_driver+0xa8/0x120 __device_attach_driver from bus_for_each_drv+0x84/0xdc bus_for_each_drv from __device_attach+0xb0/0x20c __device_attach from bus_probe_device+0x8c/0x90 bus_probe_device from deferred_probe_work_func+0x98/0xe0 deferred_probe_work_func from process_one_work+0x24c/0x70c process_one_work from worker_thread+0x1b8/0x3bc worker_thread from kthread+0x13c/0x264 kthread from ret_from_fork+0x14/0x28 ... ---[ end trace 0000000000000000 ]--- Fix this by switching the driver to the new API. Note the above warning only appears starting with 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. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Fixes: a7748dd ("drm/bridge: get/put the bridge reference in drm_bridge_add/remove()") Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Link: https://lore.kernel.org/r/20250627165652.580798-1-m.szyprowski@samsung.com [Luca: add Fixes tag and mention the reason in commit message] Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
1 parent e33f256 commit 48f05c3

2 files changed

Lines changed: 13 additions & 30 deletions

File tree

drivers/gpu/drm/bridge/analogix/analogix_dp_core.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ static int analogix_dp_bridge_attach(struct drm_bridge *bridge,
10411041
struct drm_encoder *encoder,
10421042
enum drm_bridge_attach_flags flags)
10431043
{
1044-
struct analogix_dp_device *dp = bridge->driver_private;
1044+
struct analogix_dp_device *dp = to_dp(bridge);
10451045
struct drm_connector *connector = NULL;
10461046
int ret = 0;
10471047

@@ -1125,7 +1125,7 @@ struct drm_crtc *analogix_dp_get_new_crtc(struct analogix_dp_device *dp,
11251125
static void analogix_dp_bridge_atomic_pre_enable(struct drm_bridge *bridge,
11261126
struct drm_atomic_state *old_state)
11271127
{
1128-
struct analogix_dp_device *dp = bridge->driver_private;
1128+
struct analogix_dp_device *dp = to_dp(bridge);
11291129
struct drm_crtc *crtc;
11301130
struct drm_crtc_state *old_crtc_state;
11311131

@@ -1180,7 +1180,7 @@ static int analogix_dp_set_bridge(struct analogix_dp_device *dp)
11801180
static void analogix_dp_bridge_atomic_enable(struct drm_bridge *bridge,
11811181
struct drm_atomic_state *old_state)
11821182
{
1183-
struct analogix_dp_device *dp = bridge->driver_private;
1183+
struct analogix_dp_device *dp = to_dp(bridge);
11841184
struct drm_crtc *crtc;
11851185
struct drm_crtc_state *old_crtc_state;
11861186
int timeout_loop = 0;
@@ -1217,7 +1217,7 @@ static void analogix_dp_bridge_atomic_enable(struct drm_bridge *bridge,
12171217

12181218
static void analogix_dp_bridge_disable(struct drm_bridge *bridge)
12191219
{
1220-
struct analogix_dp_device *dp = bridge->driver_private;
1220+
struct analogix_dp_device *dp = to_dp(bridge);
12211221

12221222
if (dp->dpms_mode != DRM_MODE_DPMS_ON)
12231223
return;
@@ -1240,7 +1240,7 @@ static void analogix_dp_bridge_disable(struct drm_bridge *bridge)
12401240
static void analogix_dp_bridge_atomic_disable(struct drm_bridge *bridge,
12411241
struct drm_atomic_state *old_state)
12421242
{
1243-
struct analogix_dp_device *dp = bridge->driver_private;
1243+
struct analogix_dp_device *dp = to_dp(bridge);
12441244
struct drm_crtc *old_crtc, *new_crtc;
12451245
struct drm_crtc_state *old_crtc_state = NULL;
12461246
struct drm_crtc_state *new_crtc_state = NULL;
@@ -1278,7 +1278,7 @@ static void analogix_dp_bridge_atomic_disable(struct drm_bridge *bridge,
12781278
static void analogix_dp_bridge_atomic_post_disable(struct drm_bridge *bridge,
12791279
struct drm_atomic_state *old_state)
12801280
{
1281-
struct analogix_dp_device *dp = bridge->driver_private;
1281+
struct analogix_dp_device *dp = to_dp(bridge);
12821282
struct drm_crtc *crtc;
12831283
struct drm_crtc_state *new_crtc_state;
12841284
int ret;
@@ -1300,7 +1300,7 @@ static void analogix_dp_bridge_mode_set(struct drm_bridge *bridge,
13001300
const struct drm_display_mode *orig_mode,
13011301
const struct drm_display_mode *mode)
13021302
{
1303-
struct analogix_dp_device *dp = bridge->driver_private;
1303+
struct analogix_dp_device *dp = to_dp(bridge);
13041304
struct drm_display_info *display_info = &dp->connector.display_info;
13051305
struct video_info *video = &dp->video_info;
13061306
struct device_node *dp_node = dp->dev->of_node;
@@ -1385,25 +1385,6 @@ static const struct drm_bridge_funcs analogix_dp_bridge_funcs = {
13851385
.attach = analogix_dp_bridge_attach,
13861386
};
13871387

1388-
static int analogix_dp_create_bridge(struct drm_device *drm_dev,
1389-
struct analogix_dp_device *dp)
1390-
{
1391-
struct drm_bridge *bridge;
1392-
1393-
bridge = devm_kzalloc(drm_dev->dev, sizeof(*bridge), GFP_KERNEL);
1394-
if (!bridge) {
1395-
DRM_ERROR("failed to allocate for drm bridge\n");
1396-
return -ENOMEM;
1397-
}
1398-
1399-
dp->bridge = bridge;
1400-
1401-
bridge->driver_private = dp;
1402-
bridge->funcs = &analogix_dp_bridge_funcs;
1403-
1404-
return drm_bridge_attach(dp->encoder, bridge, NULL, 0);
1405-
}
1406-
14071388
static int analogix_dp_dt_parse_pdata(struct analogix_dp_device *dp)
14081389
{
14091390
struct device_node *dp_node = dp->dev->of_node;
@@ -1491,7 +1472,8 @@ analogix_dp_probe(struct device *dev, struct analogix_dp_plat_data *plat_data)
14911472
return ERR_PTR(-EINVAL);
14921473
}
14931474

1494-
dp = devm_kzalloc(dev, sizeof(struct analogix_dp_device), GFP_KERNEL);
1475+
dp = devm_drm_bridge_alloc(dev, struct analogix_dp_device, bridge,
1476+
&analogix_dp_bridge_funcs);
14951477
if (!dp)
14961478
return ERR_PTR(-ENOMEM);
14971479

@@ -1643,7 +1625,7 @@ int analogix_dp_bind(struct analogix_dp_device *dp, struct drm_device *drm_dev)
16431625
return ret;
16441626
}
16451627

1646-
ret = analogix_dp_create_bridge(drm_dev, dp);
1628+
ret = drm_bridge_attach(dp->encoder, &dp->bridge, NULL, 0);
16471629
if (ret) {
16481630
DRM_ERROR("failed to create bridge (%d)\n", ret);
16491631
goto err_unregister_aux;
@@ -1660,7 +1642,7 @@ EXPORT_SYMBOL_GPL(analogix_dp_bind);
16601642

16611643
void analogix_dp_unbind(struct analogix_dp_device *dp)
16621644
{
1663-
analogix_dp_bridge_disable(dp->bridge);
1645+
analogix_dp_bridge_disable(&dp->bridge);
16641646
dp->connector.funcs->destroy(&dp->connector);
16651647

16661648
drm_panel_unprepare(dp->plat_data->panel);

drivers/gpu/drm/bridge/analogix/analogix_dp_core.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <drm/display/drm_dp_helper.h>
1313
#include <drm/drm_crtc.h>
14+
#include <drm/drm_bridge.h>
1415

1516
#define DP_TIMEOUT_LOOP_COUNT 100
1617
#define MAX_CR_LOOP 5
@@ -154,7 +155,7 @@ struct analogix_dp_device {
154155
struct device *dev;
155156
struct drm_device *drm_dev;
156157
struct drm_connector connector;
157-
struct drm_bridge *bridge;
158+
struct drm_bridge bridge;
158159
struct drm_dp_aux aux;
159160
struct clk *clock;
160161
unsigned int irq;

0 commit comments

Comments
 (0)