Skip to content

Commit f002abc

Browse files
committed
drm/tegra: Properly cleanup and zero out resources
When the DRM driver is unloaded, all the associated resources must be cleaned up and zeroed out. This is necessary because of the architecture of the Tegra DRM driver, where not all subdrivers are unloaded along with the DRM driver. Therefore device-managed managed won't be freed and memory cannot be assumed to have been cleared (because it hasn't been reallocated using kzalloc()) by the time the DRM driver is reloaded. It is therefore necessary to zero out the structures to prevent strange errors (such as slab corruptions) from occurring. Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent dee8268 commit f002abc

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

‎drivers/gpu/drm/tegra/dc.c‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@ static int tegra_plane_disable(struct drm_plane *plane)
9393

9494
static void tegra_plane_destroy(struct drm_plane *plane)
9595
{
96+
struct tegra_plane *p = to_tegra_plane(plane);
97+
9698
tegra_plane_disable(plane);
9799
drm_plane_cleanup(plane);
100+
kfree(p);
98101
}
99102

100103
static const struct drm_plane_funcs tegra_plane_funcs = {
@@ -120,7 +123,7 @@ static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc)
120123
for (i = 0; i < 2; i++) {
121124
struct tegra_plane *plane;
122125

123-
plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL);
126+
plane = kzalloc(sizeof(*plane), GFP_KERNEL);
124127
if (!plane)
125128
return -ENOMEM;
126129

@@ -129,8 +132,10 @@ static int tegra_dc_add_planes(struct drm_device *drm, struct tegra_dc *dc)
129132
err = drm_plane_init(drm, &plane->base, 1 << dc->pipe,
130133
&tegra_plane_funcs, plane_formats,
131134
ARRAY_SIZE(plane_formats), false);
132-
if (err < 0)
135+
if (err < 0) {
136+
kfree(plane);
133137
return err;
138+
}
134139
}
135140

136141
return 0;
@@ -251,14 +256,26 @@ static int tegra_dc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
251256
return 0;
252257
}
253258

259+
static void drm_crtc_clear(struct drm_crtc *crtc)
260+
{
261+
memset(crtc, 0, sizeof(*crtc));
262+
}
263+
264+
static void tegra_dc_destroy(struct drm_crtc *crtc)
265+
{
266+
drm_crtc_cleanup(crtc);
267+
drm_crtc_clear(crtc);
268+
}
269+
254270
static const struct drm_crtc_funcs tegra_crtc_funcs = {
255271
.page_flip = tegra_dc_page_flip,
256272
.set_config = drm_crtc_helper_set_config,
257-
.destroy = drm_crtc_cleanup,
273+
.destroy = tegra_dc_destroy,
258274
};
259275

260276
static void tegra_crtc_disable(struct drm_crtc *crtc)
261277
{
278+
struct tegra_dc *dc = to_tegra_dc(crtc);
262279
struct drm_device *drm = crtc->dev;
263280
struct drm_plane *plane;
264281

@@ -273,6 +290,8 @@ static void tegra_crtc_disable(struct drm_crtc *crtc)
273290
}
274291
}
275292
}
293+
294+
drm_vblank_off(drm, dc->pipe);
276295
}
277296

278297
static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc,

‎drivers/gpu/drm/tegra/drm.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ static int tegra_drm_unload(struct drm_device *drm)
7272

7373
drm_kms_helper_poll_fini(drm);
7474
tegra_drm_fb_exit(drm);
75+
drm_vblank_cleanup(drm);
76+
drm_mode_config_cleanup(drm);
7577

7678
err = host1x_device_exit(device);
7779
if (err < 0)
7880
return err;
7981

80-
drm_mode_config_cleanup(drm);
81-
8282
return 0;
8383
}
8484

‎drivers/gpu/drm/tegra/output.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ tegra_connector_detect(struct drm_connector *connector, bool force)
7979
return status;
8080
}
8181

82+
static void drm_connector_clear(struct drm_connector *connector)
83+
{
84+
memset(connector, 0, sizeof(*connector));
85+
}
86+
8287
static void tegra_connector_destroy(struct drm_connector *connector)
8388
{
8489
drm_sysfs_connector_remove(connector);
8590
drm_connector_cleanup(connector);
91+
drm_connector_clear(connector);
8692
}
8793

8894
static const struct drm_connector_funcs connector_funcs = {
@@ -92,9 +98,15 @@ static const struct drm_connector_funcs connector_funcs = {
9298
.destroy = tegra_connector_destroy,
9399
};
94100

101+
static void drm_encoder_clear(struct drm_encoder *encoder)
102+
{
103+
memset(encoder, 0, sizeof(*encoder));
104+
}
105+
95106
static void tegra_encoder_destroy(struct drm_encoder *encoder)
96107
{
97108
drm_encoder_cleanup(encoder);
109+
drm_encoder_clear(encoder);
98110
}
99111

100112
static const struct drm_encoder_funcs encoder_funcs = {

0 commit comments

Comments
 (0)