[PATCH] remove redundant NULL checks before kfree() in sound/ and avoid casting pointers about to be kfree()'ed

Checking a pointer for NULL before calling kfree() on it is redundant,
kfree() deals with NULL pointers just fine.
This patch removes such checks from sound/

This patch also makes another, but closely related, change.
It avoids casting pointers about to be kfree()'ed.

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Jesper Juhl and committed by Linus Torvalds 09417379 4ae6673e

+16 -28
+1 -2
sound/oss/ad1848.c
··· 2178 2178 2179 2179 if (devc != NULL) 2180 2180 { 2181 - if(audio_devs[dev]->portc!=NULL) 2182 - kfree(audio_devs[dev]->portc); 2181 + kfree(audio_devs[dev]->portc); 2183 2182 release_region(devc->base, 4); 2184 2183 2185 2184 if (!share_dma)
+1 -2
sound/oss/ad1889.c
··· 277 277 278 278 for (j = 0; j < AD_MAX_STATES; j++) { 279 279 dmabuf = &dev->state[j].dmabuf; 280 - if (dmabuf->rawbuf != NULL) 281 - kfree(dmabuf->rawbuf); 280 + kfree(dmabuf->rawbuf); 282 281 } 283 282 284 283 kfree(dev);
+7 -13
sound/oss/dmasound/dmasound_awacs.c
··· 671 671 release_OF_resource(awacs_node, 1); 672 672 release_OF_resource(awacs_node, 2); 673 673 674 - if (awacs_tx_cmd_space) 675 - kfree(awacs_tx_cmd_space); 676 - if (awacs_rx_cmd_space) 677 - kfree(awacs_rx_cmd_space); 678 - if (beep_dbdma_cmd_space) 679 - kfree(beep_dbdma_cmd_space); 680 - if (beep_buf) 681 - kfree(beep_buf); 674 + kfree(awacs_tx_cmd_space); 675 + kfree(awacs_rx_cmd_space); 676 + kfree(beep_dbdma_cmd_space); 677 + kfree(beep_buf); 682 678 #ifdef CONFIG_PMAC_PBOOK 683 679 pmu_unregister_sleep_notifier(&awacs_sleep_notifier); 684 680 #endif ··· 2297 2301 #endif 2298 2302 2299 2303 if ((write_sq.max_count + 1) > number_of_tx_cmd_buffers) { 2300 - if (awacs_tx_cmd_space) 2301 - kfree(awacs_tx_cmd_space); 2304 + kfree(awacs_tx_cmd_space); 2302 2305 number_of_tx_cmd_buffers = 0; 2303 2306 2304 2307 /* we need nbufs + 1 (for the loop) and we should request + 1 ··· 2355 2360 #endif 2356 2361 2357 2362 if ((read_sq.max_count+1) > number_of_rx_cmd_buffers ) { 2358 - if (awacs_rx_cmd_space) 2359 - kfree(awacs_rx_cmd_space); 2363 + kfree(awacs_rx_cmd_space); 2360 2364 number_of_rx_cmd_buffers = 0; 2361 2365 2362 2366 /* we need nbufs + 1 (for the loop) and we should request + 1 again ··· 2799 2805 beep_buf = (short *) kmalloc(BEEP_BUFLEN * 4, GFP_KERNEL); 2800 2806 if (beep_buf == NULL) { 2801 2807 printk(KERN_ERR "dmasound_pmac: no memory for beep buffer\n"); 2802 - if( beep_dbdma_cmd_space ) kfree(beep_dbdma_cmd_space) ; 2808 + kfree(beep_dbdma_cmd_space) ; 2803 2809 return -ENOMEM ; 2804 2810 } 2805 2811 return 0 ;
+2 -4
sound/oss/emu10k1/midi.c
··· 523 523 card = midi_devs[dev]->devc; 524 524 emu10k1_mpuout_close(card); 525 525 526 - if (card->seq_mididev) { 527 - kfree(card->seq_mididev); 528 - card->seq_mididev = NULL; 529 - } 526 + kfree(card->seq_mididev); 527 + card->seq_mididev = NULL; 530 528 } 531 529 532 530 int emu10k1_seq_midi_out(int dev, unsigned char midi_byte)
+1 -2
sound/oss/emu10k1/passthrough.c
··· 213 213 sblive_writeptr(card, SPCS0 + i, 0, pt->old_spcs[i]); 214 214 } 215 215 pt->state = PT_STATE_INACTIVE; 216 - if(pt->buf) 217 - kfree(pt->buf); 216 + kfree(pt->buf); 218 217 } 219 218 } 220 219
+1 -1
sound/oss/maestro.c
··· 2356 2356 } 2357 2357 2358 2358 rec_return_free: 2359 - if(combbuf) kfree(combbuf); 2359 + kfree(combbuf); 2360 2360 return ret; 2361 2361 } 2362 2362
+1 -2
sound/oss/mpu401.c
··· 1240 1240 p=mpu401_synth_operations[n]; 1241 1241 sound_unload_mididev(n); 1242 1242 sound_unload_timerdev(hw_config->slots[2]); 1243 - if(p) 1244 - kfree(p); 1243 + kfree(p); 1245 1244 } 1246 1245 } 1247 1246
+2 -2
sound/oss/sb_common.c
··· 915 915 } 916 916 else 917 917 release_region(hw_config->io_base, 16); 918 - if(detected_devc) 919 - kfree(detected_devc); 918 + 919 + kfree(detected_devc); 920 920 } 921 921 922 922 /*