Skip to content

Commit

Permalink
[ALSA] Remove redundant NULL checks before kfree
Browse files Browse the repository at this point in the history
Timer Midlevel,ALSA sequencer,ALSA<-OSS sequencer,Digigram VX core
I2C tea6330t,GUS Library,VIA82xx driver,VIA82xx-modem driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,YMFPCI driver
Digigram VX Pocket driver,Common EMU synth,USB generic driver,USB USX2Y
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: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Jesper Juhl authored and Jaroslav Kysela committed Jun 22, 2005
1 parent 6fd8b87 commit 4d57277
Show file tree
Hide file tree
Showing 18 changed files with 39 additions and 87 deletions.
24 changes: 8 additions & 16 deletions sound/core/seq/oss/seq_oss_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@ snd_seq_oss_synth_cleanup(seq_oss_devinfo_t *dp)
}
snd_use_lock_free(&rec->use_lock);
}
if (info->sysex) {
kfree(info->sysex);
info->sysex = NULL;
}
if (info->ch) {
kfree(info->ch);
info->ch = NULL;
}
kfree(info->sysex);
info->sysex = NULL;
kfree(info->ch);
info->ch = NULL;
}
dp->synth_opened = 0;
dp->max_synthdev = 0;
Expand Down Expand Up @@ -418,14 +414,10 @@ snd_seq_oss_synth_reset(seq_oss_devinfo_t *dp, int dev)
dp->file_mode) < 0) {
midi_synth_dev.opened--;
info->opened = 0;
if (info->sysex) {
kfree(info->sysex);
info->sysex = NULL;
}
if (info->ch) {
kfree(info->ch);
info->ch = NULL;
}
kfree(info->sysex);
info->sysex = NULL;
kfree(info->ch);
info->ch = NULL;
}
return;
}
Expand Down
5 changes: 1 addition & 4 deletions sound/core/seq/seq_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ dummy_input(snd_seq_event_t *ev, int direct, void *private_data, int atomic, int
static void
dummy_free(void *private_data)
{
snd_seq_dummy_port_t *p;

p = private_data;
kfree(p);
kfree(private_data);
}

/*
Expand Down
12 changes: 4 additions & 8 deletions sound/core/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,14 +1469,10 @@ static int snd_timer_user_tselect(struct file *file, snd_timer_select_t __user *
if ((err = snd_timer_open(&tu->timeri, str, &tselect.id, current->pid)) < 0)
goto __err;

if (tu->queue) {
kfree(tu->queue);
tu->queue = NULL;
}
if (tu->tqueue) {
kfree(tu->tqueue);
tu->tqueue = NULL;
}
kfree(tu->queue);
tu->queue = NULL;
kfree(tu->tqueue);
tu->tqueue = NULL;
if (tu->tread) {
tu->tqueue = (snd_timer_tread_t *)kmalloc(tu->queue_size * sizeof(snd_timer_tread_t), GFP_KERNEL);
if (tu->tqueue == NULL)
Expand Down
12 changes: 4 additions & 8 deletions sound/drivers/vx/vx_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1264,14 +1264,10 @@ static void snd_vx_pcm_free(snd_pcm_t *pcm)
{
vx_core_t *chip = pcm->private_data;
chip->pcm[pcm->device] = NULL;
if (chip->playback_pipes) {
kfree(chip->playback_pipes);
chip->playback_pipes = NULL;
}
if (chip->capture_pipes) {
kfree(chip->capture_pipes);
chip->capture_pipes = NULL;
}
kfree(chip->playback_pipes);
chip->playback_pipes = NULL;
kfree(chip->capture_pipes);
chip->capture_pipes = NULL;
}

/*
Expand Down
3 changes: 1 addition & 2 deletions sound/i2c/tea6330t.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ TEA6330T_TREBLE("Tone Control - Treble", 0)

static void snd_tea6330_free(snd_i2c_device_t *device)
{
tea6330t_t *tea = device->private_data;
kfree(tea);
kfree(device->private_data);
}

int snd_tea6330t_update_mixer(snd_card_t * card,
Expand Down
3 changes: 1 addition & 2 deletions sound/isa/gus/gus_pcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ static snd_pcm_hardware_t snd_gf1_pcm_capture =

static void snd_gf1_pcm_playback_free(snd_pcm_runtime_t *runtime)
{
gus_pcm_private_t * pcmp = runtime->private_data;
kfree(pcmp);
kfree(runtime->private_data);
}

static int snd_gf1_pcm_playback_open(snd_pcm_substream_t *substream)
Expand Down
6 changes: 1 addition & 5 deletions sound/pci/ca0106/ca0106_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,7 @@ static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb)

static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime)
{
ca0106_pcm_t *epcm = runtime->private_data;

if (epcm) {
kfree(epcm);
}
kfree(runtime->private_data);
}

/* open_playback callback */
Expand Down
3 changes: 1 addition & 2 deletions sound/pci/cs46xx/cs46xx_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,7 @@ static snd_pcm_hw_constraint_list_t hw_constraints_period_sizes = {

static void snd_cs46xx_pcm_free_substream(snd_pcm_runtime_t *runtime)
{
cs46xx_pcm_t * cpcm = runtime->private_data;
kfree(cpcm);
kfree(runtime->private_data);
}

static int _cs46xx_playback_open_channel (snd_pcm_substream_t * substream,int pcm_channel_id)
Expand Down
5 changes: 1 addition & 4 deletions sound/pci/emu10k1/emu10k1x.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,7 @@ static void snd_emu10k1x_gpio_write(emu10k1x_t *emu, unsigned int value)

static void snd_emu10k1x_pcm_free_substream(snd_pcm_runtime_t *runtime)
{
emu10k1x_pcm_t *epcm = runtime->private_data;

if (epcm)
kfree(epcm);
kfree(runtime->private_data);
}

static void snd_emu10k1x_pcm_interrupt(emu10k1x_t *emu, emu10k1x_voice_t *voice)
Expand Down
4 changes: 1 addition & 3 deletions sound/pci/emu10k1/emupcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,7 @@ static void snd_emu10k1_pcm_efx_mixer_notify(emu10k1_t *emu, int idx, int activa

static void snd_emu10k1_pcm_free_substream(snd_pcm_runtime_t *runtime)
{
emu10k1_pcm_t *epcm = runtime->private_data;

kfree(epcm);
kfree(runtime->private_data);
}

static int snd_emu10k1_efx_playback_close(snd_pcm_substream_t * substream)
Expand Down
6 changes: 2 additions & 4 deletions sound/pci/via82xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,8 @@ static int clean_via_table(viadev_t *dev, snd_pcm_substream_t *substream,
snd_dma_free_pages(&dev->table);
dev->table.area = NULL;
}
if (dev->idx_table) {
kfree(dev->idx_table);
dev->idx_table = NULL;
}
kfree(dev->idx_table);
dev->idx_table = NULL;
return 0;
}

Expand Down
6 changes: 2 additions & 4 deletions sound/pci/via82xx_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ static int clean_via_table(viadev_t *dev, snd_pcm_substream_t *substream,
snd_dma_free_pages(&dev->table);
dev->table.area = NULL;
}
if (dev->idx_table) {
kfree(dev->idx_table);
dev->idx_table = NULL;
}
kfree(dev->idx_table);
dev->idx_table = NULL;
return 0;
}

Expand Down
4 changes: 1 addition & 3 deletions sound/pci/ymfpci/ymfpci_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,7 @@ static snd_pcm_hardware_t snd_ymfpci_capture =

static void snd_ymfpci_pcm_free_substream(snd_pcm_runtime_t *runtime)
{
ymfpci_pcm_t *ypcm = runtime->private_data;

kfree(ypcm);
kfree(runtime->private_data);
}

static int snd_ymfpci_playback_open_1(snd_pcm_substream_t * substream)
Expand Down
3 changes: 1 addition & 2 deletions sound/pcmcia/vx/vx_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ static int snd_vxpocket_free(vx_core_t *chip)
if (hw)
hw->card_list[vxp->index] = NULL;
chip->card = NULL;
if (chip->dev)
kfree(chip->dev);
kfree(chip->dev);

snd_vx_free_firmware(chip);
kfree(chip);
Expand Down
6 changes: 2 additions & 4 deletions sound/synth/emux/emux_effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,8 @@ snd_emux_create_effect(snd_emux_port_t *p)
void
snd_emux_delete_effect(snd_emux_port_t *p)
{
if (p->effect) {
kfree(p->effect);
p->effect = NULL;
}
kfree(p->effect);
p->effect = NULL;
}

void
Expand Down
12 changes: 4 additions & 8 deletions sound/usb/usbaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,8 @@ static void release_urb_ctx(snd_urb_ctx_t *u)
usb_free_urb(u->urb);
u->urb = NULL;
}
if (u->buf) {
kfree(u->buf);
u->buf = NULL;
}
kfree(u->buf);
u->buf = NULL;
}

/*
Expand All @@ -880,10 +878,8 @@ static void release_substream_urbs(snd_usb_substream_t *subs, int force)
release_urb_ctx(&subs->dataurb[i]);
for (i = 0; i < SYNC_URBS; i++)
release_urb_ctx(&subs->syncurb[i]);
if (subs->tmpbuf) {
kfree(subs->tmpbuf);
subs->tmpbuf = NULL;
}
kfree(subs->tmpbuf);
subs->tmpbuf = NULL;
subs->nurbs = 0;
}

Expand Down
6 changes: 2 additions & 4 deletions sound/usb/usbmixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,8 @@ static struct usb_feature_control_info audio_feature_info[] = {
/* private_free callback */
static void usb_mixer_elem_free(snd_kcontrol_t *kctl)
{
if (kctl->private_data) {
kfree(kctl->private_data);
kctl->private_data = NULL;
}
kfree(kctl->private_data);
kctl->private_data = NULL;
}


Expand Down
6 changes: 2 additions & 4 deletions sound/usb/usx2y/usbusx2yaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,8 @@ static void usX2Y_urbs_release(snd_usX2Y_substream_t *subs)
for (i = 0; i < NRURBS; i++)
usX2Y_urb_release(subs->urb + i, subs != subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK]);

if (subs->tmpbuf) {
kfree(subs->tmpbuf);
subs->tmpbuf = NULL;
}
kfree(subs->tmpbuf);
subs->tmpbuf = NULL;
}
/*
* initialize a substream's urbs
Expand Down

0 comments on commit 4d57277

Please sign in to comment.