]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fbdev: imxfb: Check fb_add_videomode to prevent null-ptr-deref
authorChenyuan Yang <chenyuan0y@gmail.com>
Thu, 24 Jul 2025 03:25:34 +0000 (22:25 -0500)
committerHelge Deller <deller@gmx.de>
Sun, 27 Jul 2025 17:56:51 +0000 (19:56 +0200)
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 17186f1f90d3 ("fbdev:
Fix do_register_framebuffer to prevent null-ptr-deref in fb_videomode_to_var").

Fixes: 1b6c79361ba5 ("video: imxfb: Add DT support")
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/imxfb.c

index f30da32cdaed4d6f007ff3041d6cd923f5c4f245..a077bf346bdf4be2f123d3cc8ab237181fd92ea4 100644 (file)
@@ -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