Skip to contentSkip to conversation

emu10k1: Fix coccicheck warning

PATCH In review Vicentiu Ciorbaru 2 participants 4 messages Mar 10, 2013 1 message not in the archive Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 emu10k1: Fix coccicheck warning

Removed redundant cast of kmalloc return pointer.

---
 sound/pci/emu10k1/emufx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/pci/emu10k1/emufx.c +2 -3
index 0275209..a0f7502 100644
@@ -1183,9 +1183,8 @@ static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu)
 	mm_segment_t seg;
 
 	if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL ||
-	    (icode->gpr_map = (u_int32_t __user *)
-	     kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
-		     GFP_KERNEL)) == NULL ||
+	    (icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
+				sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
 	    (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
 				sizeof(*controls), GFP_KERNEL)) == NULL) {
 		err = -ENOMEM;
Signature · 1 line
1.7.10.4
#1 lore raw

sound/pci/emu10k1/emufx.c static int _snd_emu10k1_audigy_init_efx(struct snd_emu10k1 *emu) · line 1187

Quoted 7 lines · Vicentiu Ciorbaru

Removed redundant cast of kmalloc return pointer.

sound/pci/emu10k1/emufx.c +2 -3
-	    (icode->gpr_map = (u_int32_t __user *)
-	     kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
-		     GFP_KERNEL)) == NULL ||
+	    (icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
+				sizeof(u_int32_t), GFP_KERNEL)) == NULL ||

Why would casting to __user be redundant?

Regards,
Clemens

A message that is not in the archive (sent off-list or not yet received): CACzaYTOE=tVst3=TvUCtxpMuUOtJiHQ3o2wbgWeMvxwZy41DMw@mail.gmail.com

#3 lore raw
Quoted 10 lines · Vicentiu Ciorbaru
Quoted 9 lines · Clemens Ladisch
Quoted 7 lines · Vicentiu Ciorbaru

Removed redundant cast of kmalloc return pointer.

sound/pci/emu10k1/emufx.c +2 -3
-         (icode->gpr_map = (u_int32_t __user *)
-          kcalloc(512 + 256 + 256 + 2 * 1024, sizeof(u_int32_t),
-                  GFP_KERNEL)) == NULL ||
+         (icode->gpr_map = kcalloc(512 + 256 + 256 + 2 * 1024,
+                             sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
Quoted 6 lines
Quoted 1 line

Why would casting to __user be redundant?

My reasoning behind the patch is that the C standard does not require a specific cast of a void pointer in order to set it to the type of the member gpr_map of the struct snd_emu10k1_fx8010_code. I named it redundant because the compiler would cast to it anyway.

That's correct as far as the C standard is concerned. However, __user is a non-standard extension.

Quoted 1 line

The line also appears as a warning when running make coccicheck.

And when you remove the __user, you get a warning when running make C=x.

Both coccinelle and sparse are merely tools for finding likely bugs. When it isn't possible to make them both happy with or without the cast, that just shows that the code itself is badly designed.

The driver should be redesigned to not access user and kernel space memory through the same pointer.

Regards,
Clemens

#4 lore raw
Quoted 10 lines
Quoted 4 lines

My reasoning behind the patch is that the C standard does not require a specific cast of a void pointer in order to set it to the type of the member gpr_map of the struct snd_emu10k1_fx8010_code. I named it redundant because the compiler would cast to it anyway.

That's correct as far as the C standard is concerned. However, __user is a non-standard extension.

Quoted 1 line

The line also appears as a warning when running make coccicheck.

Quoted 8 lines

And when you remove the __user, you get a warning when running make C=x.

Both coccinelle and sparse are merely tools for finding likely bugs. When it isn't possible to make them both happy with or without the cast, that just shows that the code itself is badly designed.

The driver should be redesigned to not access user and kernel space memory through the same pointer.

In that case I thank you for the quick feedback and I will try looking more deeply into the issue.

Vicentiu