Skip to contentSkip to conversation

drm/nouveau/disp: sizeof() wrong pointer

PATCH Superseded Dan Carpenter 3 participants 5 messages Jan 22, 2013 – Jan 23, 2013

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

PATCH 1/1 drm/nouveau/disp: sizeof() wrong pointer

"data" is a void pointer and "args" is "data" after we have casted it to a struct. We care about the sizeof the struct here. Btw, sizeof(*data) is 1.

drivers/gpu/drm/nouveau/core/engine/disp/nv50.c +2 -2
index ca1a7d7..eb9c489 100644
@@ -335,7 +335,7 @@ nv50_disp_sync_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head > 1)
+	if (size < sizeof(*args) || args->head > 1)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
@@ -374,7 +374,7 @@ nv50_disp_ovly_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head > 1)
+	if (size < sizeof(*args) || args->head > 1)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
drivers/gpu/drm/nouveau/core/engine/disp/nvd0.c +2 -2
index 9e38ebf..f28725a 100644
@@ -230,7 +230,7 @@ nvd0_disp_sync_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head >= priv->head.nr)
+	if (size < sizeof(*args) || args->head >= priv->head.nr)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
@@ -270,7 +270,7 @@ nvd0_disp_ovly_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head >= priv->head.nr)
+	if (size < sizeof(*args) || args->head >= priv->head.nr)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
Acked-by on v1 1/1
#1 lore raw

Dear Dan,

Am Dienstag, den 22.01.2013, 10:20 +0300 schrieb Dan Carpenter:

Quoted 2 lines

"data" is a void pointer and "args" is "data" after we have casted it to a struct. We care about the sizeof the struct here. Btw, sizeof(*data)

s,sizeof the,size of the,

Quoted 1 line

is 1.

Did you find this by manual inspection or did you use some tool?

Quoted 1 line

[…]

With the typo fixed above,

Thanks,

Paul

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

PATCH v2 1/1 drm/nouveau/disp: sizeof() wrong pointer

"data" is a void pointer and "args" is "data" after we have casted it to a struct. We care about the size of the struct here. Btw, sizeof(*data) is 1.

---
v2: tweaked the commit message

drivers/gpu/drm/nouveau/core/engine/disp/nv50.c +2 -2
index ca1a7d7..eb9c489 100644
@@ -335,7 +335,7 @@ nv50_disp_sync_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head > 1)
+	if (size < sizeof(*args) || args->head > 1)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
@@ -374,7 +374,7 @@ nv50_disp_ovly_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head > 1)
+	if (size < sizeof(*args) || args->head > 1)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
drivers/gpu/drm/nouveau/core/engine/disp/nvd0.c +2 -2
index 9e38ebf..f28725a 100644
@@ -230,7 +230,7 @@ nvd0_disp_sync_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head >= priv->head.nr)
+	if (size < sizeof(*args) || args->head >= priv->head.nr)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
@@ -270,7 +270,7 @@ nvd0_disp_ovly_ctor(struct nouveau_object *parent,
 	struct nv50_disp_dmac *dmac;
 	int ret;
 
-	if (size < sizeof(*data) || args->head >= priv->head.nr)
+	if (size < sizeof(*args) || args->head >= priv->head.nr)
 		return -EINVAL;
 
 	ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
#3 lore raw
In reply to Paul Menzel
Quoted 3 lines · Paul Menzel

Did you find this by manual inspection or did you use some tool?

I found this because it caused a problem in a parser I was working on but Sparse warns about "warning: expression using sizeof(void)".

It's sort of hard to run Sparse on nouveau because you can't build the individual .o files.

$ kchecker --sparse drivers/gpu/drm/nouveau/core/engine/disp/nv50.c
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
  CHK     include/generated/uapi/linux/version.h
  CHK     include/generated/utsrelease.h
  CALL    scripts/checksyscalls.sh
<stdin>:1223:2: warning: #warning syscall finit_module not implemented [-Wcpp]
scripts/Makefile.build:44: /home/dcarpenter/progs/kernel/devel/drivers/gpu/drm/nouveau/core/engine/disp/Makefile: No such file or directory
make[1]: *** No rule to make target `/home/dcarpenter/progs/kernel/devel/drivers/gpu/drm/nouveau/core/engine/disp/Makefile'.  Stop.
make: *** [drivers/gpu/drm/nouveau/core/engine/disp/nv50.o] Error 2

regards,
dan carpenter

#4 lore raw
Quoted 6 lines · Dan Carpenter
Quoted 2 lines · Paul Menzel

Did you find this by manual inspection or did you use some tool?

I found this because it caused a problem in a parser I was working on but Sparse warns about "warning: expression using sizeof(void)".

gcc's -Wpointer-arith option also reports this.
Never tried it on the kernel though .....

Bernd

Signature · 2 lines
Bernd Petrovitsch                  Email : [email protected]
                     LUGA : http://www.luga.at