Commit da11e6a3 authored by Chenyuan Yang's avatar Chenyuan Yang Committed by Helge Deller
Browse files

fbdev: imxfb: Check fb_add_videomode to prevent null-ptr-deref



fb_add_videomode() can fail with -ENOMEM when its internal kmalloc() cannot
allocate a struct fb_modelist.  If that happens, the modelist stays empty but
the driver continues to register.  Add a check for its return value to prevent
poteintial null-ptr-deref, which is similar to the commit 17186f1f ("fbdev:
Fix do_register_framebuffer to prevent null-ptr-deref in fb_videomode_to_var").

Fixes: 1b6c7936 ("video: imxfb: Add DT support")
Signed-off-by: default avatarChenyuan Yang <chenyuan0y@gmail.com>
Signed-off-by: default avatarHelge Deller <deller@gmx.de>
parent 57ba4d53
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -996,8 +996,13 @@ static int imxfb_probe(struct platform_device *pdev)
	info->fix.smem_start = fbi->map_dma;

	INIT_LIST_HEAD(&info->modelist);
	for (i = 0; i < fbi->num_modes; i++)
		fb_add_videomode(&fbi->mode[i].mode, &info->modelist);
	for (i = 0; i < fbi->num_modes; i++) {
		ret = fb_add_videomode(&fbi->mode[i].mode, &info->modelist);
		if (ret) {
			dev_err(&pdev->dev, "Failed to add videomode\n");
			goto failed_cmap;
		}
	}

	/*
	 * This makes sure that our colour bitfield