lkml.org 
[lkml]   [2023]   [May]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH 1/4] fbdev: imsttfb: Fix error handling in init_imstt()
From
On 5/23/23 19:38, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 23 May 2023 14:32:39 +0200
>
> The return value was overlooked from a call of
> the function “fb_alloc_cmap”.
>
> * Thus use a corresponding error check.
>
> * Add two jump targets so that a bit of exception handling
> can be better reused at the end of this function.
>
>
> Reported-by: Helge Deller <deller@gmx.de>
> Link: https://lore.kernel.org/dri-devel/069f2f78-01f3-9476-d860-2b695c122649@gmx.de/
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: c75f5a550610 ("fbdev: imsttfb: Fix use after free bug in imsttfb_probe")
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/video/fbdev/imsttfb.c | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c
> index 975dd682fae4..d3532def4707 100644
> --- a/drivers/video/fbdev/imsttfb.c
> +++ b/drivers/video/fbdev/imsttfb.c
> @@ -1351,6 +1351,7 @@ static int init_imstt(struct fb_info *info)
> {
> struct imstt_par *par = info->par;
> __u32 i, tmp, *ip, *end;
> + int ret;
>
> tmp = read_reg_le32(par->dc_regs, PRC);
> if (par->ramdac == IBM)
> @@ -1419,8 +1420,7 @@ static int init_imstt(struct fb_info *info)
> if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len
> || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) {
> printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel);
> - framebuffer_release(info);
> - return -ENODEV;
> + goto e_nodev;
> }
>
> sprintf(info->fix.id, "IMS TT (%s)", par->ramdac == IBM ? "IBM" : "TVP");
> @@ -1452,17 +1452,25 @@ static int init_imstt(struct fb_info *info)
> FBINFO_HWACCEL_FILLRECT |
> FBINFO_HWACCEL_YPAN;
>
> - fb_alloc_cmap(&info->cmap, 0, 0);
> + ret = fb_alloc_cmap(&info->cmap, 0, 0);
> + if (ret)
> + goto release_framebuffer;
>
> if (register_framebuffer(info) < 0) {
> - framebuffer_release(info);
> - return -ENODEV;
> + fb_dealloc_cmap(&info->cmap);
> + goto e_nodev;
> }
>
> tmp = (read_reg_le32(par->dc_regs, SSTATUS) & 0x0f00) >> 8;
> fb_info(info, "%s frame buffer; %uMB vram; chip version %u\n",
> info->fix.id, info->fix.smem_len >> 20, tmp);
> return 0;
> +
> +e_nodev:
> + ret = -ENODEV;

I think the return value isn't checked at all, so you could
simply return below "-ENODEV" for all cases (instead of "return ret").
Then you don't need the e_nodev label and can simplify the flow.

Helge


> +release_framebuffer:
> + framebuffer_release(info);
> + return ret;
> }
>
> static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
> --
> 2.40.1
>

\
 
 \ /
  Last update: 2023-05-24 20:20    [W:0.065 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site