[PATCH v2] staging: sm750fb: free cmap on framebuffer release
From: Lucas Costa
Date: Tue Sep 22 2026 - 12:43:12 EST
The cmap is allocated by lynxfb_set_fbinfo() but never freed, so it is
leaked when the framebuffer is torn down. This happens on every unbind,
and on the register_framebuffer() error path in
sm750fb_framebuffer_alloc().
Add a lynxfb_unset_fbinfo() cleanup counterpart to lynxfb_set_fbinfo()
which deallocates the cmap, and call it on teardown. In the alloc error
path it is only called once lynxfb_set_fbinfo() has succeeded, so the
cmap is only freed when it was actually allocated.
Fixes: 81dee67e215b ("staging: sm750fb: add sm750 to staging")
Suggested-by: Dan Carpenter <error27@xxxxxxxxx>
Signed-off-by: Lucas Costa <2000.costalucas@xxxxxxxxx>
---
v2:
- Move the cmap deallocation into a lynxfb_unset_fbinfo() cleanup
counterpart to lynxfb_set_fbinfo(), instead of open-coding
fb_dealloc_cmap() at each call site.
- In the alloc error path, only unwind the cmap once
lynxfb_set_fbinfo() has succeeded (Dan Carpenter).
drivers/staging/sm750fb/sm750.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index 8b93bfeb217b..68b6d4fe79ca 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -825,6 +825,11 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
return ret;
}
+static void lynxfb_unset_fbinfo(struct fb_info *info)
+{
+ fb_dealloc_cmap(&info->cmap);
+}
+
/* chip specific g_option configuration routine */
static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
{
@@ -910,6 +915,7 @@ static void sm750fb_framebuffer_release(struct sm750_dev *sm750_dev)
while (sm750_dev->fb_count) {
fb_info = sm750_dev->fbinfo[sm750_dev->fb_count - 1];
unregister_framebuffer(fb_info);
+ lynxfb_unset_fbinfo(fb_info);
framebuffer_release(fb_info);
sm750_dev->fb_count--;
}
@@ -936,12 +942,14 @@ static int sm750fb_framebuffer_alloc(struct sm750_dev *sm750_dev, int fbidx)
err = register_framebuffer(fb_info);
if (err < 0)
- goto release_fb;
+ goto unset_fb;
sm750_dev->fb_count++;
return 0;
+unset_fb:
+ lynxfb_unset_fbinfo(fb_info);
release_fb:
framebuffer_release(fb_info);
return err;
--
2.43.0