Skip to contentSkip to conversation

viafb: Use sizeof struct rather than pointer

PATCH In review Roel Kluin 3 participants 4 messages Nov 21, 2009 Framebuffer layer

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 viafb: Use sizeof struct rather than pointer

The sizeof the struct should be used rather than of the pointer

---
 drivers/video/via/viafbdev.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Unless I am mistaken?

drivers/video/via/viafbdev.c +1 -1
index 56ec696..6cf4cb8 100644
@@ -680,7 +680,7 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 		if (!viafb_gamma_table)
 			return -ENOMEM;
 		if (copy_from_user(viafb_gamma_table, argp,
-				sizeof(viafb_gamma_table))) {
+				sizeof(*viafb_gamma_table))) {
 			kfree(viafb_gamma_table);
 			return -EFAULT;
 		}
author
#1 lore raw

The returned error should be negative

---
 drivers/video/via/viafbdev.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Quoted 1 line

Unless I am mistaken?

There was another in the same file:

drivers/video/via/viafbdev.c +2 -2
index 56ec696..7b181e7 100644
@@ -680,7 +680,7 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 		if (!viafb_gamma_table)
 			return -ENOMEM;
 		if (copy_from_user(viafb_gamma_table, argp,
-				sizeof(viafb_gamma_table))) {
+				sizeof(*viafb_gamma_table))) {
 			kfree(viafb_gamma_table);
 			return -EFAULT;
 		}
@@ -694,7 +694,7 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 			return -ENOMEM;
 		viafb_get_gamma_table(viafb_gamma_table);
 		if (copy_to_user(argp, viafb_gamma_table,
-			sizeof(viafb_gamma_table))) {
+			sizeof(*viafb_gamma_table))) {
 			kfree(viafb_gamma_table);
 			return -EFAULT;
 		}
#2 lore raw
Quoted 2 lines · Roel Kluin

The returned error should be negative

Hum? This belong to this patch?

#3 lore raw
In reply to Roel Kluin

Hi,

Quoted 14 lines · Roel Kluin
drivers/video/via/viafbdev.c +1 -1
index 56ec696..7b181e7 100644
@@ -680,7 +680,7 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 		if (!viafb_gamma_table)
 			return -ENOMEM;
 		if (copy_from_user(viafb_gamma_table, argp,
-				sizeof(viafb_gamma_table))) {
+				sizeof(*viafb_gamma_table))) {
 			kfree(viafb_gamma_table);
 			return -EFAULT;
 		}

drivers/video/via/viafbdev.c static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg) · line 700

Quoted 8 lines
drivers/video/via/viafbdev.c +1 -1
@@ -694,7 +694,7 @@ static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
 			return -ENOMEM;
 		viafb_get_gamma_table(viafb_gamma_table);
 		if (copy_to_user(argp, viafb_gamma_table,
-			sizeof(viafb_gamma_table))) {
+			sizeof(*viafb_gamma_table))) {
 			kfree(viafb_gamma_table);
 			return -EFAULT;
 		}

I'm sorry but I fear your fix isn't correct. The reason is a few lines above:

u32 *viafb_gamma_table;
...
viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);

so probably the right solution would look like this:

copy_from_user(viafb_gamma_table, argp, 256 * sizeof(u32)) copy_to_user(argp, viafb_gamma_table, 256 * sizeof(u32))

However viafb has way too many private ioctls. I would be curious whether there exists any program that uses any of them so that they could be tested. As this ioctl didn't work very well I vote to remove it at least temporarily.

Thanks for highlighting this problem,

Florian Tobias Schandinat