Skip to contentSkip to conversation

fb: handle NULL pointers in framebuffer release

PATCH Applied Dan Carpenter 4 participants 5 messages May 14, 2012 – May 29, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fb: handle NULL pointers in framebuffer release

This function is called with a potential NULL pointer in picolcd_init_framebuffer() and it causes a static checker warning. This used to handle NULL pointers when the picolcd code was written, but a couple months later we added the "info->apertures" dereference.

drivers/video/fbsysfs.c +2 -0
index 67afa9c..a55e366 100644
@@ -80,6 +80,8 @@ EXPORT_SYMBOL(framebuffer_alloc);
  */
 void framebuffer_release(struct fb_info *info)
 {
+	if (!info)
+		return;
 	kfree(info->apertures);
 	kfree(info);
 }
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dan Carpenter

This function is called with a potential NULL pointer in picolcd_init_framebuffer() and it causes a static checker warning. This used to handle NULL pointers when the picolcd code was written, but a couple months later we added the "info->apertures" dereference.

Quoted 13 lines
drivers/video/fbsysfs.c +2 -0
index 67afa9c..a55e366 100644
@@ -80,6 +80,8 @@ EXPORT_SYMBOL(framebuffer_alloc);
  */
 void framebuffer_release(struct fb_info *info)
 {
+	if (!info)
+		return;
 	kfree(info->apertures);
 	kfree(info);
 }
#2 lore raw
In reply to Dan Carpenter
Quoted 12 lines · Dan Carpenter

This function is called with a potential NULL pointer in picolcd_init_framebuffer() and it causes a static checker warning. This used to handle NULL pointers when the picolcd code was written, but a couple months later we added the "info->apertures" dereference.

drivers/video/fbsysfs.c +0 -0
index 67afa9c..a55e366 100644

drivers/video/fbsysfs.c EXPORT_SYMBOL(framebuffer_alloc); · line 87

Quoted 8 lines
drivers/video/fbsysfs.c +2 -0
@@ -80,6 +80,8 @@ EXPORT_SYMBOL(framebuffer_alloc);
  */
 void framebuffer_release(struct fb_info *info)
 {
+	if (!info)
+		return;
 	kfree(info->apertures);
 	kfree(info);
 }

And not like this:

+ if (info) {
+ if (info->apertures)
+ kfree(info->apertures);
+ kfree(info);
+ }

?

- Hein

#3 lore raw
In reply to Dan Carpenter
Quoted 24 lines · Hein Tibosch
Quoted 12 lines · Dan Carpenter

This function is called with a potential NULL pointer in picolcd_init_framebuffer() and it causes a static checker warning. This used to handle NULL pointers when the picolcd code was written, but a couple months later we added the "info->apertures" dereference.

drivers/video/fbsysfs.c +0 -0
index 67afa9c..a55e366 100644

drivers/video/fbsysfs.c EXPORT_SYMBOL(framebuffer_alloc); · line 87

Quoted 8 lines
drivers/video/fbsysfs.c +2 -0
@@ -80,6 +80,8 @@ EXPORT_SYMBOL(framebuffer_alloc);
  */
 void framebuffer_release(struct fb_info *info)
 {
+	if (!info)
+		return;
 	kfree(info->apertures);
 	kfree(info);
 }

And not like this:

Review

Quoted 5 lines
(quoted diff) +5 -0
+	if (info) {
+		if (info->apertures)
+			kfree(info->apertures);
+		kfree(info);
+	}

Nah. kfree() has a NULL check built in. I think it would trigger a checkpatch.pl warning?

regards,
dan carpenter

#4 lore raw
In reply to Dan Carpenter
Quoted 6 lines · Dan Carpenter

This function is called with a potential NULL pointer in picolcd_init_framebuffer() and it causes a static checker warning. This used to handle NULL pointers when the picolcd code was written, but a couple months later we added the "info->apertures" dereference.

Applied.

Thanks,

Florian Tobias Schandinat

Quoted 15 lines
drivers/video/fbsysfs.c +2 -0
index 67afa9c..a55e366 100644
@@ -80,6 +80,8 @@ EXPORT_SYMBOL(framebuffer_alloc);
  */
 void framebuffer_release(struct fb_info *info)
 {
+	if (!info)
+		return;
 	kfree(info->apertures);
 	kfree(info);
 }