Skip to content

Commit dfb49ea

Browse files
tombagregkh
authored andcommitted
drm/omap: Fix possible NULL dereference
[ Upstream commit a88fee2 ] smatch reports: drivers/gpu/drm/omapdrm/dss/base.c:176 omapdss_device_disconnect() error: we previously assumed 'src' could be null (see line 169) This code is mostly from a time when omapdrm had its own display device model. I can't honestly remember the details, and I don't think it's worth digging in deeply into that for a legacy driver. However, it looks like we only call omapdss_device_disconnect() and omapdss_device_connect() with NULL as the src parameter. We can thus drop the src parameter from both functions, and fix the smatch warning. I don't think omapdss_device_disconnect() ever gets NULL for the dst parameter (if it did, we'd crash soon after returning from the function), but I have kept the !dst check, just in case, but I added a WARN_ON() there. Also, if the dst parameter can be NULL, we can't always get the struct dss_device pointer from dst->dss (which is only used for a debug print). To make sure we can't hit that issue, do it similarly to the omapdss_device_connect() function: add 'struct dss_device *dss' as the first parameter, so that we always have it regardless of the dst. Fixes: 79107f2 ("drm/omap: Add support for drm_bridge") Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240806-omapdrm-misc-fixes-v1-1-15d31aea0831@ideasonboard.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent bc98117 commit dfb49ea

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

drivers/gpu/drm/omapdrm/dss/base.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,13 @@ static bool omapdss_device_is_connected(struct omap_dss_device *dssdev)
139139
}
140140

141141
int omapdss_device_connect(struct dss_device *dss,
142-
struct omap_dss_device *src,
143142
struct omap_dss_device *dst)
144143
{
145-
dev_dbg(&dss->pdev->dev, "connect(%s, %s)\n",
146-
src ? dev_name(src->dev) : "NULL",
144+
dev_dbg(&dss->pdev->dev, "connect(%s)\n",
147145
dst ? dev_name(dst->dev) : "NULL");
148146

149-
if (!dst) {
150-
/*
151-
* The destination is NULL when the source is connected to a
152-
* bridge instead of a DSS device. Stop here, we will attach
153-
* the bridge later when we will have a DRM encoder.
154-
*/
155-
return src && src->bridge ? 0 : -EINVAL;
156-
}
147+
if (!dst)
148+
return -EINVAL;
157149

158150
if (omapdss_device_is_connected(dst))
159151
return -EBUSY;
@@ -163,19 +155,14 @@ int omapdss_device_connect(struct dss_device *dss,
163155
return 0;
164156
}
165157

166-
void omapdss_device_disconnect(struct omap_dss_device *src,
158+
void omapdss_device_disconnect(struct dss_device *dss,
167159
struct omap_dss_device *dst)
168160
{
169-
struct dss_device *dss = src ? src->dss : dst->dss;
170-
171-
dev_dbg(&dss->pdev->dev, "disconnect(%s, %s)\n",
172-
src ? dev_name(src->dev) : "NULL",
161+
dev_dbg(&dss->pdev->dev, "disconnect(%s)\n",
173162
dst ? dev_name(dst->dev) : "NULL");
174163

175-
if (!dst) {
176-
WARN_ON(!src->bridge);
164+
if (WARN_ON(!dst))
177165
return;
178-
}
179166

180167
if (!dst->id && !omapdss_device_is_connected(dst)) {
181168
WARN_ON(1);

drivers/gpu/drm/omapdrm/dss/omapdss.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev);
242242
void omapdss_device_put(struct omap_dss_device *dssdev);
243243
struct omap_dss_device *omapdss_find_device_by_node(struct device_node *node);
244244
int omapdss_device_connect(struct dss_device *dss,
245-
struct omap_dss_device *src,
246245
struct omap_dss_device *dst);
247-
void omapdss_device_disconnect(struct omap_dss_device *src,
246+
void omapdss_device_disconnect(struct dss_device *dss,
248247
struct omap_dss_device *dst);
249248

250249
int omap_dss_get_num_overlay_managers(void);

drivers/gpu/drm/omapdrm/omap_drv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static void omap_disconnect_pipelines(struct drm_device *ddev)
307307
for (i = 0; i < priv->num_pipes; i++) {
308308
struct omap_drm_pipeline *pipe = &priv->pipes[i];
309309

310-
omapdss_device_disconnect(NULL, pipe->output);
310+
omapdss_device_disconnect(priv->dss, pipe->output);
311311

312312
omapdss_device_put(pipe->output);
313313
pipe->output = NULL;
@@ -325,7 +325,7 @@ static int omap_connect_pipelines(struct drm_device *ddev)
325325
int r;
326326

327327
for_each_dss_output(output) {
328-
r = omapdss_device_connect(priv->dss, NULL, output);
328+
r = omapdss_device_connect(priv->dss, output);
329329
if (r == -EPROBE_DEFER) {
330330
omapdss_device_put(output);
331331
return r;

0 commit comments

Comments
 (0)