From: Chenyuan Yang Date: Thu, 24 Jul 2025 03:25:34 +0000 (-0500) Subject: fbdev: imxfb: Check fb_add_videomode to prevent null-ptr-deref X-Git-Tag: v5.10.241~383 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f00c29e6755ead56baf2a9c1d3c4c0bb40af3612;p=thirdparty%2Fkernel%2Fstable.git fbdev: imxfb: Check fb_add_videomode to prevent null-ptr-deref [ Upstream commit da11e6a30e0bb8e911288bdc443b3dc8f6a7cac7 ] 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 Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- diff --git a/drivers/video/fbdev/imxfb.c b/drivers/video/fbdev/imxfb.c index d663e080b1571..91f041f3a56f2 100644 --- a/drivers/video/fbdev/imxfb.c +++ b/drivers/video/fbdev/imxfb.c @@ -1007,8 +1007,13 @@ static int imxfb_probe(struct platform_device *pdev) 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