From: Markus Elfring <elfr...@users.sourceforge.net>
Date: Mon, 19 Jan 2015 17:01:25 +0100

The iounmap() function could be called in three cases by the valkyriefb_init()
function during error handling even if the passed data structure element
contained still a null pointer.

This implementation detail could be improved by adjustments for jump labels
(according also to current Linux coding style) and error messages.

Signed-off-by: Markus Elfring <elfr...@users.sourceforge.net>
---
 drivers/video/fbdev/valkyriefb.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/video/fbdev/valkyriefb.c b/drivers/video/fbdev/valkyriefb.c
index 2a9213b..a81a0f1 100644
--- a/drivers/video/fbdev/valkyriefb.c
+++ b/drivers/video/fbdev/valkyriefb.c
@@ -369,40 +369,50 @@ int __init valkyriefb_init(void)
        }
        p->total_vram = 0x100000;
        p->frame_buffer_phys = frame_buffer_phys;
+       err = -ENOMEM;
        p->frame_buffer = __ioremap(frame_buffer_phys, p->total_vram, flags);
+       if (p->frame_buffer == NULL) {
+               pr_err("%s: %s failed\n", __func__, "Frame buffer mapping");
+               goto free_memory;
+       }
        p->cmap_regs_phys = cmap_regs_phys;
        p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000);
+       if (p->cmap_regs == NULL) {
+               pr_err("%s: %s failed\n", __func__, "cmap");
+               goto io_unmap_framebuffer;
+       }
        p->valkyrie_regs_phys = cmap_regs_phys+0x6000;
        p->valkyrie_regs = ioremap(p->valkyrie_regs_phys, 0x1000);
-       err = -ENOMEM;
-       if (p->frame_buffer == NULL || p->cmap_regs == NULL
-           || p->valkyrie_regs == NULL) {
-               printk(KERN_ERR "valkyriefb: couldn't map resources\n");
-               goto out_free;
+       if (p->valkyrie_regs == NULL) {
+               pr_err("%s: %s failed\n", __func__, "ioremap");
+               goto io_unmap_cmap;
        }
 
        valkyrie_choose_mode(p);
        mac_vmode_to_var(default_vmode, default_cmode, &p->info.var);
        err = valkyrie_init_info(&p->info, p);
        if (err < 0)
-               goto out_free;
+               goto io_unmap_valkyrie;
        valkyrie_init_fix(&p->info.fix, p);
        if (valkyriefb_set_par(&p->info))
                /* "can't happen" */
                printk(KERN_ERR "valkyriefb: can't set default video mode\n");
 
        if ((err = register_framebuffer(&p->info)) != 0)
-               goto out_cmap_free;
+               goto dealloc_cmap;
 
        fb_info(&p->info, "valkyrie frame buffer device\n");
        return 0;
 
- out_cmap_free:
+dealloc_cmap:
        fb_dealloc_cmap(&p->info.cmap);
- out_free:
-       iounmap(p->frame_buffer);
-       iounmap(p->cmap_regs);
+io_unmap_valkyrie:
        iounmap(p->valkyrie_regs);
+io_unmap_cmap:
+       iounmap(p->cmap_regs);
+io_unmap_framebuffer:
+       iounmap(p->frame_buffer);
+free_memory:
        kfree(p);
        return err;
 }
-- 
2.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to