Skip to content

Commit 9c6f194

Browse files
Dan CarpenterThomas Zimmermann
authored andcommitted
drm: simpledrm: fix a potential NULL dereference
The drm_format_info() function returns NULL if the format is unsupported, but the simplefb_get_validated_format() is expected to return error pointers. If we propagate the NULL return then it will lead to a NULL dereference in the callers. Swap the NULL and trade it in for an ERR_PTR(-EINVAL). Fixes: 11e8f5f ("drm: Add simpledrm driver") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Thomas Zimmermann <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/YJ+aC47XX58ICXax@mwanda
1 parent 527a947 commit 9c6f194

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/gpu/drm/tiny/simpledrm.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,20 @@ simplefb_get_validated_format(struct drm_device *dev, const char *format_name)
7272
static const struct simplefb_format formats[] = SIMPLEFB_FORMATS;
7373
const struct simplefb_format *fmt = formats;
7474
const struct simplefb_format *end = fmt + ARRAY_SIZE(formats);
75+
const struct drm_format_info *info;
7576

7677
if (!format_name) {
7778
drm_err(dev, "simplefb: missing framebuffer format\n");
7879
return ERR_PTR(-EINVAL);
7980
}
8081

8182
while (fmt < end) {
82-
if (!strcmp(format_name, fmt->name))
83-
return drm_format_info(fmt->fourcc);
83+
if (!strcmp(format_name, fmt->name)) {
84+
info = drm_format_info(fmt->fourcc);
85+
if (!info)
86+
return ERR_PTR(-EINVAL);
87+
return info;
88+
}
8489
++fmt;
8590
}
8691

0 commit comments

Comments
 (0)