Skip to contentSkip to conversation

ALSA: emu10k1: casting (void *) value returned by kcalloc is useless

PATCH In review Duan Jiong 2 participants 4 messages Sep 5, 2013 Sound

lore
Share & tools
lore

Duan Jiong

author
#0 lore raw

PATCH 1/1 ALSA: emu10k1: casting (void *) value returned by kcalloc is useless

From: Duan Jiong <[email protected]>

Casting (void *) value returned by kcalloc is useless as mentioned in Documentation/CodingStyle, Chap 14.

---
 sound/pci/emu10k1/emufx.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/pci/emu10k1/emufx.c +4 -6
index 0275209..68edb2d 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;
@@ -1815,9 +1814,8 @@ static int _snd_emu10k1_init_efx(struct snd_emu10k1 *emu)
 
 	if ((icode = kzalloc(sizeof(*icode), GFP_KERNEL)) == NULL)
 		return -ENOMEM;
-	if ((icode->gpr_map = (u_int32_t __user *)
-	     kcalloc(256 + 160 + 160 + 2 * 512, sizeof(u_int32_t),
-		     GFP_KERNEL)) == NULL ||
+	if ((icode->gpr_map = kcalloc(256 + 160 + 160 + 2 * 512,
+				sizeof(u_int32_t), GFP_KERNEL)) == NULL ||
             (controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
 				sizeof(struct snd_emu10k1_fx8010_control_gpr),
 				GFP_KERNEL)) == NULL ||
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 4 lines · Duan Jiong

From: Duan Jiong <[email protected]>

Casting (void *) value returned by kcalloc is useless as mentioned in Documentation/CodingStyle, Chap 14.

__user is an important marker that is lost here.

sound/pci/emu10k1/emufx.c

Quoted 1 line
sound/pci/emu10k1/emufx.c +0 -0

[]

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

Quoted 12 lines
sound/pci/emu10k1/emufx.c +2 -3
@@ -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;

I think this would be clearer as

	err = -ENOMEM;
	icode = kzalloc(sizeof(*icode), GFP_KERNEL)
	if (!icode)
		goto err;
	icode->gpr_map = (__user)kcalloc(512 + 256 + 256 + 2 * 1024,
					 sizeof(u_int32_t), GFP_KERNEL);
	if (!icode->gpr_map)
		goto err;
	controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
			    sizeof(*controls), GFP_KERNEL);
	if (!controls)
		goto err;
author
#2 lore raw
Quoted 25 lines · Joe Perches
Quoted 4 lines · Duan Jiong

From: Duan Jiong <[email protected]>

Casting (void *) value returned by kcalloc is useless as mentioned in Documentation/CodingStyle, Chap 14.

__user is an important marker that is lost here.

sound/pci/emu10k1/emufx.c

Quoted 1 line
sound/pci/emu10k1/emufx.c +0 -0

[]

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

Quoted 12 lines
sound/pci/emu10k1/emufx.c +2 -3
@@ -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;

I think this would be clearer as

Quoted 13 lines
	err = -ENOMEM;
	icode = kzalloc(sizeof(*icode), GFP_KERNEL)
	if (!icode)
		goto err;
	icode->gpr_map = (__user)kcalloc(512 + 256 + 256 + 2 * 1024,
					 sizeof(u_int32_t), GFP_KERNEL);
	if (!icode->gpr_map)
		goto err;
	controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
			    sizeof(*controls), GFP_KERNEL);
	if (!controls)
		goto err;

Maybe it should keep the original style, because i do as you said, and error messages appear during compiling the kernel.

Thanks,
Duan

#3 lore raw
Quoted 40 lines · Duan Jiong
Quoted 25 lines · Joe Perches
Quoted 4 lines · Duan Jiong

From: Duan Jiong <[email protected]>

Casting (void *) value returned by kcalloc is useless as mentioned in Documentation/CodingStyle, Chap 14.

__user is an important marker that is lost here.

sound/pci/emu10k1/emufx.c

Quoted 1 line
sound/pci/emu10k1/emufx.c +0 -0

[]

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

Quoted 12 lines
sound/pci/emu10k1/emufx.c +2 -3
@@ -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;

I think this would be clearer as

Quoted 13 lines
	err = -ENOMEM;
	icode = kzalloc(sizeof(*icode), GFP_KERNEL)
	if (!icode)
		goto err;
	icode->gpr_map = (__user)kcalloc(512 + 256 + 256 + 2 * 1024,
					 sizeof(u_int32_t), GFP_KERNEL);
	if (!icode->gpr_map)
		goto err;
	controls = kcalloc(SND_EMU10K1_GPR_CONTROLS,
			    sizeof(*controls), GFP_KERNEL);
	if (!controls)
		goto err;
Quoted 2 lines

Maybe it should keep the original style, because i do as you said, and error messages appear during compiling the kernel.

I think your suggested patch causes sparse errors when compiled with "$ make C=2 sound/pci/emu10k1/emufx.o"

And sorry, I just typed my reply in the email client and I didn't compiled it or anything.

Most likely my suggestion needs a semicolon after the kzalloc and (__user void *) on the kcalloc cast.

cheers, Joe