Document kfree and vfree NULL usage
Subsystems (4)
PATCH 1/1 Document kfree and vfree NULL usage
Hi,
This patch adds comments for kfree() and vfree() stating that both accept NULL pointers. I audited vfree() callers and there seems to be lots of confusion over this in the kernel.
---
slab.c | 2 ++ vmalloc.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
mm/slab.c +2 -0
@@ -2535,6 +2535,8 @@* kfree - free previously allocated memory * @objp: pointer returned by kmalloc. * +* If @objp is NULL, no operation is performed. +* * Don't free memory not originally allocated by kmalloc() * or you will run into trouble. */
mm/vmalloc.c +2 -1
@@ -389,7 +389,8 @@* @addr: memory base address * * Free the virtually contiguous memory area starting at @addr, as -* obtained from vmalloc(), vmalloc_32() or __vmalloc(). +* obtained from vmalloc(), vmalloc_32() or __vmalloc(). If @addr is +* NULL, no operation is performed. * * May not be called in interrupt context. */
Quoted 6 lines · Pekka Enberg
Hi,
This patch adds comments for
kfree()andvfree()stating that both accept NULL pointers. I auditedvfree()callers and there seems to be lots of confusion over this in the kernel.
I've cleaned up sound/ directory from "if (x) {k/v}free(x);" and similar constructions. I'm going to to this for most of the kernel if I found some time.
This patch is against 2.6.10-rc2 but applies cleanly to bk9 too.
sound/core/info.c +1 -2
@@ -895,8 +895,7 @@ void snd_info_free_entry(snd_info_entry_ {if (entry ==NULL )return ; -if (entry->name) -kfree ((char *)entry->name); +kfree (entry->name);if (entry->private_free) entry->private_free (entry);kfree (entry);
sound/core/init.c +2 -3
@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
sound/core/ioctl32/ioctl32.c +2 -4
@@ -370,10 +370,8 @@ static inline int _snd_ioctl32_ctl_elem_if (copy_to_user ((void __user *)arg, data32,sizeof (*data32))) err = -EFAULT ; __end: -if (data32) -kfree (data32); -if (data) -kfree (data); +kfree (data32); +kfree (data);return err; }
sound/core/ioctl32/ioctl32.h +2 -4
@@ -103,10 +103,8 @@ static inline int _snd_ioctl32_##type(un err = -EFAULT ;\ }\ __end:\ -if (data)\ -kfree (data);\ -if (data32)\ -kfree (data32);\ +kfree (data);\ +kfree (data32);\return err;\ }
sound/core/ioctl32/pcm32.c +4 -8
@@ -224,10 +224,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
@@ -432,10 +430,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
sound/core/oss/mixer_oss.c +12 -24
@@ -527,10 +527,8 @@ static void snd_mixer_oss_get_volume1_vo *right =snd_mixer_oss_conv1 (uctl->value.integer.value[1 ], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1 ]); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -566,10 +564,8 @@ static void snd_mixer_oss_get_volume1_sw *right =0 ; __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer,
@@ -628,10 +624,8 @@ static void snd_mixer_oss_put_volume1_vosnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -673,10 +667,8 @@ static void snd_mixer_oss_put_volume1_swsnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer,
@@ -802,10 +794,8 @@ static int snd_mixer_oss_get_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
@@ -853,10 +843,8 @@ static int snd_mixer_oss_put_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
sound/core/oss/pcm_oss.c +5 -10
@@ -513,8 +513,7 @@ static int snd_pcm_oss_change_params(snd runtime->oss.params =0 ; runtime->oss.prepare =1 ; -if (runtime->oss.buffer !=NULL ) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer); runtime->oss.buffer =vmalloc (runtime->oss.period_bytes); runtime->oss.buffer_used =0 ;if (runtime->dma_area)
@@ -524,12 +523,9 @@ static int snd_pcm_oss_change_params(snd err =0 ; failure: -if (sw_params) -kfree (sw_params); -if (params) -kfree (params); -if (sparams) -kfree (sparams); +kfree (sw_params); +kfree (params); +kfree (sparams);return err; }
@@ -1671,8 +1667,7 @@ static void snd_pcm_oss_release_substrea {snd_pcm_runtime_t *runtime; runtime = substream->runtime; -if (runtime->oss.buffer) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer);snd_pcm_oss_plugin_clear (substream); substream->oss.file =NULL ; substream->oss.oss =0 ;
sound/core/oss/pcm_plugin.c +5 -10
@@ -86,8 +86,7 @@ static int snd_pcm_plugin_alloc(snd_pcm_snd_assert ((size %8 ) ==0 , return -ENXIO ); size /=8 ;if (plugin->buf_frames < frames) { -if (plugin->buf) -vfree (plugin->buf); +vfree (plugin->buf); plugin->buf =vmalloc (size); plugin->buf_frames = frames; }
@@ -217,14 +216,10 @@ int snd_pcm_plugin_free(snd_pcm_plugin_treturn 0 ;if (plugin->private_free) plugin->private_free (plugin); -if (plugin->buf_channels) -kfree (plugin->buf_channels); -if (plugin->buf) -vfree (plugin->buf); -if (plugin->src_vmask) -kfree (plugin->src_vmask); -if (plugin->dst_vmask) -kfree (plugin->dst_vmask); +kfree (plugin->buf_channels); +vfree (plugin->buf); +kfree (plugin->src_vmask); +kfree (plugin->dst_vmask);kfree (plugin);return 0 ; }
sound/core/oss/route.c +1 -2
@@ -407,8 +407,7 @@ static void route_free(snd_pcm_plugin_troute_t *data = (route_t *)plugin->extra_data;unsigned int dst_channel;for (dst_channel =0 ; dst_channel < plugin->dst_format.channels; ++dst_channel) { -if (data->ttable[dst_channel].srcs !=NULL ) -kfree (data->ttable[dst_channel].srcs); +kfree (data->ttable[dst_channel].srcs); } }
sound/core/pcm.c +1 -2
@@ -830,8 +830,7 @@ void snd_pcm_release_substream(snd_pcm_s runtime->private_free (runtime);snd_free_pages ((void *)runtime->status,PAGE_ALIGN (sizeof (snd_pcm_mmap_status_t)));snd_free_pages ((void *)runtime->control,PAGE_ALIGN (sizeof (snd_pcm_mmap_control_t))); -if (runtime->hw_constraints.rules) -kfree (runtime->hw_constraints.rules); +kfree (runtime->hw_constraints.rules);kfree (runtime); substream->runtime =NULL ; substream->pstr->substream_opened--;
sound/core/pcm_native.c +1 -1
@@ -1445,7 +1445,7 @@ static int snd_pcm_drain(snd_pcm_substre _end:snd_pcm_stream_unlock_irq (substream); -if (drec && drec != &drec_tmp) +if (drec != &drec_tmp)kfree (drec); _unlock:snd_power_unlock (card);
sound/core/seq/oss/seq_oss_readq.c +1 -2
@@ -74,8 +74,7 @@ void snd_seq_oss_readq_delete(seq_oss_readq_t *q) {if (q) { -if (q->q) -kfree (q->q); +kfree (q->q);kfree (q); } }
sound/core/seq/seq_instr.c +0 -2
@@ -56,8 +56,6 @@ snd_seq_kcluster_t *snd_seq_cluster_new(void snd_seq_cluster_free (snd_seq_kcluster_t *cluster,int atomic) { -if (cluster ==NULL ) -return ;kfree (cluster); }
sound/core/seq/seq_memory.c +1 -2
@@ -436,8 +436,7 @@ int snd_seq_pool_done(pool_t *pool) pool->total_elements =0 ;spin_unlock_irqrestore (&pool->lock, flags); -if (ptr) -vfree (ptr); +vfree (ptr);spin_lock_irqsave (&pool->lock, flags); pool->closing =0 ;
sound/core/seq/seq_midi_emul.c +1 -2
@@ -713,8 +713,7 @@ void snd_midi_channel_free_set(snd_midi_ {if (chset ==NULL )return ; -if (chset->channels !=NULL ) -kfree (chset->channels); +kfree (chset->channels);kfree (chset); }
sound/core/seq/seq_midi_event.c +2 -4
@@ -138,8 +138,7 @@ int snd_midi_event_new(int bufsize, snd_void snd_midi_event_free (snd_midi_event_t *dev) {if (dev !=NULL ) { -if (dev->buf) -kfree (dev->buf); +kfree (dev->buf);kfree (dev); } }
@@ -202,8 +201,7 @@ int snd_midi_event_resize_buffer(snd_mid dev->bufsize = bufsize;reset_encode (dev);spin_unlock_irqrestore (&dev->lock, flags); -if (old_buf) -kfree (old_buf); +kfree (old_buf);return 0 ; }
sound/core/sgbuf.c +2 -4
@@ -51,10 +51,8 @@ int snd_free_sgbuf_pages(struct snd_dma_vunmap (dmab->area); dmab->area =NULL ; -if (sgbuf->table) -kfree (sgbuf->table); -if (sgbuf->page_table) -kfree (sgbuf->page_table); +kfree (sgbuf->table); +kfree (sgbuf->page_table);kfree (sgbuf); dmab->private_data =NULL ;
sound/core/timer.c +4 -8
@@ -351,8 +351,7 @@ int snd_timer_close(snd_timer_instance_t }if (timeri->private_free) timeri->private_free (timeri); -if (timeri->owner) -kfree (timeri->owner); +kfree (timeri->owner);kfree (timeri);if (timer && timer->card)module_put (timer->card->module);
@@ -1004,8 +1003,7 @@ static struct _snd_timer_hardware snd_tistatic void snd_timer_free_system (snd_timer_t *timer) { -if (timer->private_data) -kfree (timer->private_data); +kfree (timer->private_data); }static int snd_timer_register_system (void )
@@ -1226,10 +1224,8 @@ static int snd_timer_user_release(structfasync_helper (-1 , file,0 , &tu->fasync);if (tu->timeri)snd_timer_close (tu->timeri); -if (tu->queue) -kfree (tu->queue); -if (tu->tqueue) -kfree (tu->tqueue); +kfree (tu->queue); +kfree (tu->tqueue);kfree (tu); }return 0 ;
sound/i2c/cs8427.c +1 -2
@@ -156,8 +156,7 @@ static int snd_cs8427_send_corudata(snd_static void snd_cs8427_free (snd_i2c_device_t *device) { -if (device->private_data) -kfree (device->private_data); +kfree (device->private_data); } int snd_cs8427_create(snd_i2c_bus_t *bus,
sound/i2c/l3/uda1341.c +1 -2
@@ -730,8 +730,7 @@ static int uda1341_attach(struct l3_cliestatic void uda1341_detach (struct l3_client *clnt) { -if (clnt->driver_data) -kfree (clnt->driver_data); +kfree (clnt->driver_data); } static int
sound/isa/gus/gus_mem.c +1 -2
@@ -100,8 +100,7 @@ int snd_gf1_mem_xfree(snd_gf1_mem_t * alif (block->prev) block->prev->next = block->next; } -if (block->name) -kfree (block->name); +kfree (block->name);kfree (block);return 0 ; }
sound/isa/sb/emu8000_pcm.c +1 -2
@@ -260,8 +260,7 @@ static int emu8k_pcm_open(snd_pcm_substrstatic int emu8k_pcm_close (snd_pcm_substream_t *subs) {emu8k_pcm_t *rec = subs->runtime->private_data; -if (rec) -kfree (rec); +kfree (rec); subs->runtime->private_data =NULL ;return 0 ; }
sound/isa/wavefront/wavefront_fx.c +1 -2
@@ -537,8 +537,7 @@ snd_wavefront_fx_ioctl (snd_hwdep_t *sde r.data[1 ],/* addr */ r.data[2 ],/* cnt */ pd); -if (page_data) -kfree (page_data); +kfree (page_data);break ;default :
sound/pci/ac97/ac97_codec.c +1 -2
@@ -1055,8 +1055,7 @@ static int snd_ac97_bus_free(ac97_bus_t {if (bus) {snd_ac97_bus_proc_done (bus); -if (bus->pcms) -kfree (bus->pcms); +kfree (bus->pcms);if (bus->private_free) bus->private_free (bus);kfree (bus);
sound/pci/ali5451/ali5451.c +1 -2
@@ -1987,8 +1987,7 @@ static int snd_ali_free(ali_t * codec)if (codec->port)pci_release_regions (codec->pci);#ifdef CONFIG_PM -if (codec->image) -kfree (codec->image); +kfree (codec->image);#endif kfree (codec);return 0 ;
sound/pci/cs46xx/dsp_spos.c +3 -9
@@ -289,15 +289,9 @@ void cs46xx_dsp_spos_destroy (cs46xx_tcs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); } -if (ins->code.data) -kfree (ins->code.data); - -if (ins->symbol_table.symbols) -vfree (ins->symbol_table.symbols); - -if (ins->modules) -kfree (ins->modules); - +kfree (ins->code.data); +vfree (ins->symbol_table.symbols); +kfree (ins->modules);kfree (ins);up (&chip->spos_mutex); }
sound/pci/emu10k1/emu10k1_main.c +2 -4
@@ -553,10 +553,8 @@ static int snd_emu10k1_free(emu10k1_t *esnd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)snd_dma_free_pages (&emu->ptb_pages); -if (emu->page_ptr_table) -vfree (emu->page_ptr_table); -if (emu->page_addr_table) -vfree (emu->page_addr_table); +vfree (emu->page_ptr_table); +vfree (emu->page_addr_table);if (emu->irq >=0 )free_irq (emu->irq, (void *)emu);if (emu->port)
sound/pci/emu10k1/emupcm.c +1 -2
@@ -777,8 +777,7 @@ static void snd_emu10k1_pcm_free_substre {emu10k1_pcm_t *epcm = runtime->private_data; -if (epcm) -kfree (epcm); +kfree (epcm); }static int snd_emu10k1_playback_open (snd_pcm_substream_t * substream)
sound/pci/ice1712/ak4xxx.c +1 -2
@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree (ak->private_value[0 ]); }kfree (ice->akm); }
sound/pci/maestro3.c +1 -2
@@ -2374,8 +2374,7 @@ static int snd_m3_free(m3_t *chip) }#ifdef CONFIG_PM -if (chip->suspend_mem) -vfree (chip->suspend_mem); +vfree (chip->suspend_mem);#endif if (chip->irq >=0 ) {
sound/pci/trident/trident_main.c +1 -2
@@ -3675,8 +3675,7 @@ int snd_trident_free(trident_t *trident)snd_util_memhdr_free (trident->tlb.memhdr);if (trident->tlb.silent_page.area)snd_dma_free_pages (&trident->tlb.silent_page); -if (trident->tlb.shadow_entries) -vfree (trident->tlb.shadow_entries); +vfree (trident->tlb.shadow_entries);snd_dma_free_pages (&trident->tlb.buffer); }if (trident->irq >=0 )
sound/pci/ymfpci/ymfpci_main.c +2 -4
@@ -831,8 +831,7 @@ static void snd_ymfpci_pcm_free_substrea {ymfpci_pcm_t *ypcm = runtime->private_data; -if (ypcm) -kfree (ypcm); +kfree (ypcm); }static int snd_ymfpci_playback_open_1 (snd_pcm_substream_t * substream)
@@ -2065,8 +2064,7 @@ static int snd_ymfpci_free(ymfpci_t *chi#endif #ifdef CONFIG_PM -if (chip->saved_regs) -vfree (chip->saved_regs); +vfree (chip->saved_regs);#endif if (chip->mpu_res) {release_resource (chip->mpu_res);
sound/ppc/pmac.c +1 -1
@@ -71,7 +71,7 @@ static int snd_pmac_dbdma_alloc(pmac_dbdstatic void snd_pmac_dbdma_free (pmac_dbdma_t *rec) { -if (rec && rec->space) +if (rec)kfree (rec->space); }
sound/synth/emux/emux.c +2 -6
@@ -137,12 +137,8 @@ int snd_emux_free(snd_emux_t *emu)if (emu->sflist)snd_sf_free (emu->sflist); -if (emu->voices) -kfree (emu->voices); - -if (emu->name) -kfree (emu->name); - +kfree (emu->voices); +kfree (emu->name);kfree (emu);return 0 ; }
sound/synth/emux/emux_seq.c +1 -2
@@ -197,8 +197,7 @@ free_port(void *private_data)#ifdef SNDRV_EMUX_USE_RAW_EFFECT snd_emux_delete_effect (p);#endif -if (p->chset.channels) -kfree (p->chset.channels); +kfree (p->chset.channels);kfree (p); } }
sound/usb/usbaudio.c +5 -10
@@ -2063,8 +2063,7 @@ static void free_substream(snd_usb_substreturn ;/* not initialized */ list_for_each_safe (p, n, &subs->fmt_list) { struct audioformat *fp = list_entry(p, struct audioformat, list); -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp); } }
@@ -2550,8 +2549,7 @@ static int parse_audio_endpoints(snd_usb/* ok, let's parse further... */ if (parse_audio_format (dev, fp, format, fmt, stream) <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);continue ; }
@@ -2559,8 +2557,7 @@ static int parse_audio_endpoints(snd_usbsnd_printdd (KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n" , dev->devnum, iface_no, i, fp->endpoint); err =add_audio_endpoint (chip, stream, fp);if (err <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);return err; }
@@ -2693,15 +2690,13 @@ static int create_fixed_stream_quirk(snd err =add_audio_endpoint (chip, stream, fp);if (err <0 ) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return err; }if (fp->iface !=get_iface_desc (&iface->altsetting[0 ])->bInterfaceNumber || fp->altset_idx >= iface->num_altsetting) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return -EINVAL ; } alts = &iface->altsetting[fp->altset_idx];
sound/usb/usbmidi.c +2 -4
@@ -504,8 +504,7 @@ static snd_rawmidi_ops_t snd_usbmidi_inpstatic void snd_usbmidi_in_endpoint_delete (snd_usb_midi_in_endpoint_t * ep) {if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
@@ -632,8 +631,7 @@ static void snd_usbmidi_out_endpoint_delif (ep->tasklet.func)tasklet_kill (&ep->tasklet);if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
sound/usb/usbmixer.c +1 -1
@@ -573,7 +573,7 @@ static struct usb_feature_control_info astatic void usb_mixer_elem_free (snd_kcontrol_t *kctl) {if (kctl->private_data) { -kfree ((void *)kctl->private_data); +kfree (kctl->private_data); kctl->private_data =NULL ; } }
sound/usb/usx2y/usbusx2y.c +2 -4
@@ -285,8 +285,7 @@ static void usX2Y_unlinkSeq(snd_usX2Y_AsS ->urb[i] =NULL ; } } -if (S ->buffer) -kfree (S ->buffer); +kfree (S ->buffer); }
@@ -389,8 +388,7 @@ static struct usb_driver snd_usX2Y_usb_dstatic void snd_usX2Y_card_private_free (snd_card_t *card) { -if (usX2Y (card)->In04Buf) -kfree (usX2Y (card)->In04Buf); +kfree (usX2Y (card)->In04Buf);usb_free_urb (usX2Y (card)->In04urb);if (usX2Y (card)->us428ctls_sharedmem)snd_free_pages (usX2Y (card)->us428ctls_sharedmem,sizeof (*usX2Y (card)->us428ctls_sharedmem));
Signature · 4 lines
Marcel Sebek jabber: [email protected] ICQ: 279852819 linux user number: 307850 GPG ID: 5F88735E GPG FP: 0F01 BAB8 3148 94DB B95D 1FCA 8B63 CA06 5F88 735E
Hi Marcel,
Quoted 3 lines · Marcel Sebek
I've cleaned up
sound/directory from "if (x) {k/v}free(x);" and similar constructions. I'm going to to this for most of the kernel if I found some time.
I have patches to clean up vfree() in the kernel which I am planning to send to the maintainers.
sound/pci/ice1712/ak4xxx.c void snd_ice1712_akm4xxx_free(ice1712_t · line 154
Quoted 11 lines · Marcel Sebek
static int
snd_emu10k1_playback_open(snd_pcm_substream_t * substream)
diff -urpNlinux-2.6.10-rc2/sound/pci/ice1712/ak4xxx.clinux-2.6.10-rc2.changed/sound/pci/ice1712/ak4xxx.csound/pci/ice1712/ak4xxx.c +1
-2@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree (ak->private_value[0 ]);
Did you compile this? The type of ak->private_value seems to be unsigned long so you need that cast here.
Please compile the kernel with allmodconfig to make sure you did not break anything and then send these to the ALSA maintainers.
Pekka
Quoted 26 lines · Pekka Enberg
Hi Marcel,
Quoted 3 lines · Marcel Sebek
I've cleaned up
sound/directory from "if (x) {k/v}free(x);" and similar constructions. I'm going to to this for most of the kernel if I found some time.I have patches to clean up
vfree()in the kernel which I am planning to send to the maintainers.sound/pci/ice1712/ak4xxx.c void snd_ice1712_akm4xxx_free(ice1712_t · line 154
Quoted 11 lines · Marcel Sebek
static int
snd_emu10k1_playback_open(snd_pcm_substream_t * substream)
diff -urpNlinux-2.6.10-rc2/sound/pci/ice1712/ak4xxx.clinux-2.6.10-rc2.changed/sound/pci/ice1712/ak4xxx.csound/pci/ice1712/ak4xxx.c +1
-2@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree (ak->private_value[0 ]);Did you compile this? The type of
ak->private_valueseems to be unsigned long so you need that cast here.
Quoted 3 lines
Please compile the kernel with allmodconfig to make sure you did not break anything and then send these to the ALSA maintainers.
You are right. Next time I'll do it. Here's corrected compile-tested version of the patch.
sound/core/info.c +1 -2
@@ -895,8 +895,7 @@ void snd_info_free_entry(snd_info_entry_ {if (entry ==NULL )return ; -if (entry->name) -kfree ((char *)entry->name); +kfree (entry->name);if (entry->private_free) entry->private_free (entry);kfree (entry);
sound/core/init.c +2 -3
@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
sound/core/ioctl32/ioctl32.c +2 -4
@@ -370,10 +370,8 @@ static inline int _snd_ioctl32_ctl_elem_if (copy_to_user ((void __user *)arg, data32,sizeof (*data32))) err = -EFAULT ; __end: -if (data32) -kfree (data32); -if (data) -kfree (data); +kfree (data32); +kfree (data);return err; }
sound/core/ioctl32/ioctl32.h +2 -4
@@ -103,10 +103,8 @@ static inline int _snd_ioctl32_##type(un err = -EFAULT ;\ }\ __end:\ -if (data)\ -kfree (data);\ -if (data32)\ -kfree (data32);\ +kfree (data);\ +kfree (data32);\return err;\ }
sound/core/ioctl32/pcm32.c +4 -8
@@ -224,10 +224,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
@@ -432,10 +430,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
sound/core/oss/mixer_oss.c +12 -24
@@ -527,10 +527,8 @@ static void snd_mixer_oss_get_volume1_vo *right =snd_mixer_oss_conv1 (uctl->value.integer.value[1 ], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1 ]); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -566,10 +564,8 @@ static void snd_mixer_oss_get_volume1_sw *right =0 ; __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer,
@@ -628,10 +624,8 @@ static void snd_mixer_oss_put_volume1_vosnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -673,10 +667,8 @@ static void snd_mixer_oss_put_volume1_swsnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer,
@@ -802,10 +794,8 @@ static int snd_mixer_oss_get_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
@@ -853,10 +843,8 @@ static int snd_mixer_oss_put_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
sound/core/oss/pcm_oss.c +5 -10
@@ -513,8 +513,7 @@ static int snd_pcm_oss_change_params(snd runtime->oss.params =0 ; runtime->oss.prepare =1 ; -if (runtime->oss.buffer !=NULL ) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer); runtime->oss.buffer =vmalloc (runtime->oss.period_bytes); runtime->oss.buffer_used =0 ;if (runtime->dma_area)
@@ -524,12 +523,9 @@ static int snd_pcm_oss_change_params(snd err =0 ; failure: -if (sw_params) -kfree (sw_params); -if (params) -kfree (params); -if (sparams) -kfree (sparams); +kfree (sw_params); +kfree (params); +kfree (sparams);return err; }
@@ -1671,8 +1667,7 @@ static void snd_pcm_oss_release_substrea {snd_pcm_runtime_t *runtime; runtime = substream->runtime; -if (runtime->oss.buffer) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer);snd_pcm_oss_plugin_clear (substream); substream->oss.file =NULL ; substream->oss.oss =0 ;
sound/core/oss/pcm_plugin.c +5 -10
@@ -86,8 +86,7 @@ static int snd_pcm_plugin_alloc(snd_pcm_snd_assert ((size %8 ) ==0 , return -ENXIO ); size /=8 ;if (plugin->buf_frames < frames) { -if (plugin->buf) -vfree (plugin->buf); +vfree (plugin->buf); plugin->buf =vmalloc (size); plugin->buf_frames = frames; }
@@ -217,14 +216,10 @@ int snd_pcm_plugin_free(snd_pcm_plugin_treturn 0 ;if (plugin->private_free) plugin->private_free (plugin); -if (plugin->buf_channels) -kfree (plugin->buf_channels); -if (plugin->buf) -vfree (plugin->buf); -if (plugin->src_vmask) -kfree (plugin->src_vmask); -if (plugin->dst_vmask) -kfree (plugin->dst_vmask); +kfree (plugin->buf_channels); +vfree (plugin->buf); +kfree (plugin->src_vmask); +kfree (plugin->dst_vmask);kfree (plugin);return 0 ; }
sound/core/oss/route.c +1 -2
@@ -407,8 +407,7 @@ static void route_free(snd_pcm_plugin_troute_t *data = (route_t *)plugin->extra_data;unsigned int dst_channel;for (dst_channel =0 ; dst_channel < plugin->dst_format.channels; ++dst_channel) { -if (data->ttable[dst_channel].srcs !=NULL ) -kfree (data->ttable[dst_channel].srcs); +kfree (data->ttable[dst_channel].srcs); } }
sound/core/pcm.c +1 -2
@@ -830,8 +830,7 @@ void snd_pcm_release_substream(snd_pcm_s runtime->private_free (runtime);snd_free_pages ((void *)runtime->status,PAGE_ALIGN (sizeof (snd_pcm_mmap_status_t)));snd_free_pages ((void *)runtime->control,PAGE_ALIGN (sizeof (snd_pcm_mmap_control_t))); -if (runtime->hw_constraints.rules) -kfree (runtime->hw_constraints.rules); +kfree (runtime->hw_constraints.rules);kfree (runtime); substream->runtime =NULL ; substream->pstr->substream_opened--;
sound/core/pcm_native.c +1 -1
@@ -1445,7 +1445,7 @@ static int snd_pcm_drain(snd_pcm_substre _end:snd_pcm_stream_unlock_irq (substream); -if (drec && drec != &drec_tmp) +if (drec != &drec_tmp)kfree (drec); _unlock:snd_power_unlock (card);
sound/core/seq/oss/seq_oss_readq.c +1 -2
@@ -74,8 +74,7 @@ void snd_seq_oss_readq_delete(seq_oss_readq_t *q) {if (q) { -if (q->q) -kfree (q->q); +kfree (q->q);kfree (q); } }
sound/core/seq/seq_instr.c +0 -2
@@ -56,8 +56,6 @@ snd_seq_kcluster_t *snd_seq_cluster_new(void snd_seq_cluster_free (snd_seq_kcluster_t *cluster,int atomic) { -if (cluster ==NULL ) -return ;kfree (cluster); }
sound/core/seq/seq_memory.c +1 -2
@@ -436,8 +436,7 @@ int snd_seq_pool_done(pool_t *pool) pool->total_elements =0 ;spin_unlock_irqrestore (&pool->lock, flags); -if (ptr) -vfree (ptr); +vfree (ptr);spin_lock_irqsave (&pool->lock, flags); pool->closing =0 ;
sound/core/seq/seq_midi_emul.c +1 -2
@@ -713,8 +713,7 @@ void snd_midi_channel_free_set(snd_midi_ {if (chset ==NULL )return ; -if (chset->channels !=NULL ) -kfree (chset->channels); +kfree (chset->channels);kfree (chset); }
sound/core/seq/seq_midi_event.c +2 -4
@@ -138,8 +138,7 @@ int snd_midi_event_new(int bufsize, snd_void snd_midi_event_free (snd_midi_event_t *dev) {if (dev !=NULL ) { -if (dev->buf) -kfree (dev->buf); +kfree (dev->buf);kfree (dev); } }
@@ -202,8 +201,7 @@ int snd_midi_event_resize_buffer(snd_mid dev->bufsize = bufsize;reset_encode (dev);spin_unlock_irqrestore (&dev->lock, flags); -if (old_buf) -kfree (old_buf); +kfree (old_buf);return 0 ; }
sound/core/sgbuf.c +2 -4
@@ -51,10 +51,8 @@ int snd_free_sgbuf_pages(struct snd_dma_vunmap (dmab->area); dmab->area =NULL ; -if (sgbuf->table) -kfree (sgbuf->table); -if (sgbuf->page_table) -kfree (sgbuf->page_table); +kfree (sgbuf->table); +kfree (sgbuf->page_table);kfree (sgbuf); dmab->private_data =NULL ;
sound/core/timer.c +4 -8
@@ -351,8 +351,7 @@ int snd_timer_close(snd_timer_instance_t }if (timeri->private_free) timeri->private_free (timeri); -if (timeri->owner) -kfree (timeri->owner); +kfree (timeri->owner);kfree (timeri);if (timer && timer->card)module_put (timer->card->module);
@@ -1004,8 +1003,7 @@ static struct _snd_timer_hardware snd_tistatic void snd_timer_free_system (snd_timer_t *timer) { -if (timer->private_data) -kfree (timer->private_data); +kfree (timer->private_data); }static int snd_timer_register_system (void )
@@ -1226,10 +1224,8 @@ static int snd_timer_user_release(structfasync_helper (-1 , file,0 , &tu->fasync);if (tu->timeri)snd_timer_close (tu->timeri); -if (tu->queue) -kfree (tu->queue); -if (tu->tqueue) -kfree (tu->tqueue); +kfree (tu->queue); +kfree (tu->tqueue);kfree (tu); }return 0 ;
sound/i2c/cs8427.c +1 -2
@@ -156,8 +156,7 @@ static int snd_cs8427_send_corudata(snd_static void snd_cs8427_free (snd_i2c_device_t *device) { -if (device->private_data) -kfree (device->private_data); +kfree (device->private_data); } int snd_cs8427_create(snd_i2c_bus_t *bus,
sound/i2c/l3/uda1341.c +1 -2
@@ -730,8 +730,7 @@ static int uda1341_attach(struct l3_cliestatic void uda1341_detach (struct l3_client *clnt) { -if (clnt->driver_data) -kfree (clnt->driver_data); +kfree (clnt->driver_data); } static int
sound/isa/gus/gus_mem.c +1 -2
@@ -100,8 +100,7 @@ int snd_gf1_mem_xfree(snd_gf1_mem_t * alif (block->prev) block->prev->next = block->next; } -if (block->name) -kfree (block->name); +kfree (block->name);kfree (block);return 0 ; }
sound/isa/sb/emu8000_pcm.c +1 -2
@@ -260,8 +260,7 @@ static int emu8k_pcm_open(snd_pcm_substrstatic int emu8k_pcm_close (snd_pcm_substream_t *subs) {emu8k_pcm_t *rec = subs->runtime->private_data; -if (rec) -kfree (rec); +kfree (rec); subs->runtime->private_data =NULL ;return 0 ; }
sound/isa/wavefront/wavefront_fx.c +1 -2
@@ -537,8 +537,7 @@ snd_wavefront_fx_ioctl (snd_hwdep_t *sde r.data[1 ],/* addr */ r.data[2 ],/* cnt */ pd); -if (page_data) -kfree (page_data); +kfree (page_data);break ;default :
sound/pci/ac97/ac97_codec.c +1 -2
@@ -1055,8 +1055,7 @@ static int snd_ac97_bus_free(ac97_bus_t {if (bus) {snd_ac97_bus_proc_done (bus); -if (bus->pcms) -kfree (bus->pcms); +kfree (bus->pcms);if (bus->private_free) bus->private_free (bus);kfree (bus);
sound/pci/ali5451/ali5451.c +1 -2
@@ -1987,8 +1987,7 @@ static int snd_ali_free(ali_t * codec)if (codec->port)pci_release_regions (codec->pci);#ifdef CONFIG_PM -if (codec->image) -kfree (codec->image); +kfree (codec->image);#endif kfree (codec);return 0 ;
sound/pci/cs46xx/dsp_spos.c +3 -9
@@ -289,15 +289,9 @@ void cs46xx_dsp_spos_destroy (cs46xx_tcs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); } -if (ins->code.data) -kfree (ins->code.data); - -if (ins->symbol_table.symbols) -vfree (ins->symbol_table.symbols); - -if (ins->modules) -kfree (ins->modules); - +kfree (ins->code.data); +vfree (ins->symbol_table.symbols); +kfree (ins->modules);kfree (ins);up (&chip->spos_mutex); }
sound/pci/emu10k1/emu10k1_main.c +2 -4
@@ -553,10 +553,8 @@ static int snd_emu10k1_free(emu10k1_t *esnd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)snd_dma_free_pages (&emu->ptb_pages); -if (emu->page_ptr_table) -vfree (emu->page_ptr_table); -if (emu->page_addr_table) -vfree (emu->page_addr_table); +vfree (emu->page_ptr_table); +vfree (emu->page_addr_table);if (emu->irq >=0 )free_irq (emu->irq, (void *)emu);if (emu->port)
sound/pci/emu10k1/emupcm.c +1 -2
@@ -777,8 +777,7 @@ static void snd_emu10k1_pcm_free_substre {emu10k1_pcm_t *epcm = runtime->private_data; -if (epcm) -kfree (epcm); +kfree (epcm); }static int snd_emu10k1_playback_open (snd_pcm_substream_t * substream)
sound/pci/ice1712/ak4xxx.c +1 -2
@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree ((void *)ak->private_value[0 ]); }kfree (ice->akm); }
sound/pci/maestro3.c +1 -2
@@ -2374,8 +2374,7 @@ static int snd_m3_free(m3_t *chip) }#ifdef CONFIG_PM -if (chip->suspend_mem) -vfree (chip->suspend_mem); +vfree (chip->suspend_mem);#endif if (chip->irq >=0 ) {
sound/pci/trident/trident_main.c +1 -2
@@ -3675,8 +3675,7 @@ int snd_trident_free(trident_t *trident)snd_util_memhdr_free (trident->tlb.memhdr);if (trident->tlb.silent_page.area)snd_dma_free_pages (&trident->tlb.silent_page); -if (trident->tlb.shadow_entries) -vfree (trident->tlb.shadow_entries); +vfree (trident->tlb.shadow_entries);snd_dma_free_pages (&trident->tlb.buffer); }if (trident->irq >=0 )
sound/pci/ymfpci/ymfpci_main.c +2 -4
@@ -831,8 +831,7 @@ static void snd_ymfpci_pcm_free_substrea {ymfpci_pcm_t *ypcm = runtime->private_data; -if (ypcm) -kfree (ypcm); +kfree (ypcm); }static int snd_ymfpci_playback_open_1 (snd_pcm_substream_t * substream)
@@ -2065,8 +2064,7 @@ static int snd_ymfpci_free(ymfpci_t *chi#endif #ifdef CONFIG_PM -if (chip->saved_regs) -vfree (chip->saved_regs); +vfree (chip->saved_regs);#endif if (chip->mpu_res) {release_resource (chip->mpu_res);
sound/ppc/pmac.c +1 -1
@@ -71,7 +71,7 @@ static int snd_pmac_dbdma_alloc(pmac_dbdstatic void snd_pmac_dbdma_free (pmac_dbdma_t *rec) { -if (rec && rec->space) +if (rec)kfree (rec->space); }
sound/synth/emux/emux.c +2 -6
@@ -137,12 +137,8 @@ int snd_emux_free(snd_emux_t *emu)if (emu->sflist)snd_sf_free (emu->sflist); -if (emu->voices) -kfree (emu->voices); - -if (emu->name) -kfree (emu->name); - +kfree (emu->voices); +kfree (emu->name);kfree (emu);return 0 ; }
sound/synth/emux/emux_seq.c +1 -2
@@ -197,8 +197,7 @@ free_port(void *private_data)#ifdef SNDRV_EMUX_USE_RAW_EFFECT snd_emux_delete_effect (p);#endif -if (p->chset.channels) -kfree (p->chset.channels); +kfree (p->chset.channels);kfree (p); } }
sound/usb/usbaudio.c +5 -10
@@ -2063,8 +2063,7 @@ static void free_substream(snd_usb_substreturn ;/* not initialized */ list_for_each_safe (p, n, &subs->fmt_list) { struct audioformat *fp = list_entry(p, struct audioformat, list); -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp); } }
@@ -2550,8 +2549,7 @@ static int parse_audio_endpoints(snd_usb/* ok, let's parse further... */ if (parse_audio_format (dev, fp, format, fmt, stream) <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);continue ; }
@@ -2559,8 +2557,7 @@ static int parse_audio_endpoints(snd_usbsnd_printdd (KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n" , dev->devnum, iface_no, i, fp->endpoint); err =add_audio_endpoint (chip, stream, fp);if (err <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);return err; }
@@ -2693,15 +2690,13 @@ static int create_fixed_stream_quirk(snd err =add_audio_endpoint (chip, stream, fp);if (err <0 ) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return err; }if (fp->iface !=get_iface_desc (&iface->altsetting[0 ])->bInterfaceNumber || fp->altset_idx >= iface->num_altsetting) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return -EINVAL ; } alts = &iface->altsetting[fp->altset_idx];
sound/usb/usbmidi.c +2 -4
@@ -504,8 +504,7 @@ static snd_rawmidi_ops_t snd_usbmidi_inpstatic void snd_usbmidi_in_endpoint_delete (snd_usb_midi_in_endpoint_t * ep) {if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
@@ -632,8 +631,7 @@ static void snd_usbmidi_out_endpoint_delif (ep->tasklet.func)tasklet_kill (&ep->tasklet);if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
sound/usb/usbmixer.c +1 -1
@@ -573,7 +573,7 @@ static struct usb_feature_control_info astatic void usb_mixer_elem_free (snd_kcontrol_t *kctl) {if (kctl->private_data) { -kfree ((void *)kctl->private_data); +kfree (kctl->private_data); kctl->private_data =NULL ; } }
sound/usb/usx2y/usbusx2y.c +2 -4
@@ -285,8 +285,7 @@ static void usX2Y_unlinkSeq(snd_usX2Y_AsS ->urb[i] =NULL ; } } -if (S ->buffer) -kfree (S ->buffer); +kfree (S ->buffer); }
@@ -389,8 +388,7 @@ static struct usb_driver snd_usX2Y_usb_dstatic void snd_usX2Y_card_private_free (snd_card_t *card) { -if (usX2Y (card)->In04Buf) -kfree (usX2Y (card)->In04Buf); +kfree (usX2Y (card)->In04Buf);usb_free_urb (usX2Y (card)->In04urb);if (usX2Y (card)->us428ctls_sharedmem)snd_free_pages (usX2Y (card)->us428ctls_sharedmem,sizeof (*usX2Y (card)->us428ctls_sharedmem));
Signature · 4 lines
Marcel Sebek jabber: [email protected] ICQ: 279852819 linux user number: 307850 GPG ID: 5F88735E GPG FP: 0F01 BAB8 3148 94DB B95D 1FCA 8B63 CA06 5F88 735E
Quoted 26 lines · Pekka Enberg
Hi Marcel,
Quoted 3 lines · Marcel Sebek
I've cleaned up
sound/directory from "if (x) {k/v}free(x);" and similar constructions. I'm going to to this for most of the kernel if I found some time.I have patches to clean up
vfree()in the kernel which I am planning to send to the maintainers.sound/pci/ice1712/ak4xxx.c void snd_ice1712_akm4xxx_free(ice1712_t · line 154
Quoted 11 lines · Marcel Sebek
static int
snd_emu10k1_playback_open(snd_pcm_substream_t * substream)
diff -urpNlinux-2.6.10-rc2/sound/pci/ice1712/ak4xxx.clinux-2.6.10-rc2.changed/sound/pci/ice1712/ak4xxx.csound/pci/ice1712/ak4xxx.c +1
-2@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree (ak->private_value[0 ]);Did you compile this? The type of
ak->private_valueseems to be unsigned long so you need that cast here.
Quoted 3 lines
Please compile the kernel with allmodconfig to make sure you did not break anything and then send these to the ALSA maintainers.
You are right. Next time I'll do it. Here's corrected compile-tested version of the patch.
sound/core/info.c +1 -2
@@ -895,8 +895,7 @@ void snd_info_free_entry(snd_info_entry_ {if (entry ==NULL )return ; -if (entry->name) -kfree ((char *)entry->name); +kfree (entry->name);if (entry->private_free) entry->private_free (entry);kfree (entry);
sound/core/init.c +2 -3
@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
sound/core/ioctl32/ioctl32.c +2 -4
@@ -370,10 +370,8 @@ static inline int _snd_ioctl32_ctl_elem_if (copy_to_user ((void __user *)arg, data32,sizeof (*data32))) err = -EFAULT ; __end: -if (data32) -kfree (data32); -if (data) -kfree (data); +kfree (data32); +kfree (data);return err; }
sound/core/ioctl32/ioctl32.h +2 -4
@@ -103,10 +103,8 @@ static inline int _snd_ioctl32_##type(un err = -EFAULT ;\ }\ __end:\ -if (data)\ -kfree (data);\ -if (data32)\ -kfree (data32);\ +kfree (data);\ +kfree (data32);\return err;\ }
sound/core/ioctl32/pcm32.c +4 -8
@@ -224,10 +224,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
@@ -432,10 +430,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
sound/core/oss/mixer_oss.c +12 -24
@@ -527,10 +527,8 @@ static void snd_mixer_oss_get_volume1_vo *right =snd_mixer_oss_conv1 (uctl->value.integer.value[1 ], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1 ]); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -566,10 +564,8 @@ static void snd_mixer_oss_get_volume1_sw *right =0 ; __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer,
@@ -628,10 +624,8 @@ static void snd_mixer_oss_put_volume1_vosnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -673,10 +667,8 @@ static void snd_mixer_oss_put_volume1_swsnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer,
@@ -802,10 +794,8 @@ static int snd_mixer_oss_get_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
@@ -853,10 +843,8 @@ static int snd_mixer_oss_put_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
sound/core/oss/pcm_oss.c +5 -10
@@ -513,8 +513,7 @@ static int snd_pcm_oss_change_params(snd runtime->oss.params =0 ; runtime->oss.prepare =1 ; -if (runtime->oss.buffer !=NULL ) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer); runtime->oss.buffer =vmalloc (runtime->oss.period_bytes); runtime->oss.buffer_used =0 ;if (runtime->dma_area)
@@ -524,12 +523,9 @@ static int snd_pcm_oss_change_params(snd err =0 ; failure: -if (sw_params) -kfree (sw_params); -if (params) -kfree (params); -if (sparams) -kfree (sparams); +kfree (sw_params); +kfree (params); +kfree (sparams);return err; }
@@ -1671,8 +1667,7 @@ static void snd_pcm_oss_release_substrea {snd_pcm_runtime_t *runtime; runtime = substream->runtime; -if (runtime->oss.buffer) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer);snd_pcm_oss_plugin_clear (substream); substream->oss.file =NULL ; substream->oss.oss =0 ;
sound/core/oss/pcm_plugin.c +5 -10
@@ -86,8 +86,7 @@ static int snd_pcm_plugin_alloc(snd_pcm_snd_assert ((size %8 ) ==0 , return -ENXIO ); size /=8 ;if (plugin->buf_frames < frames) { -if (plugin->buf) -vfree (plugin->buf); +vfree (plugin->buf); plugin->buf =vmalloc (size); plugin->buf_frames = frames; }
@@ -217,14 +216,10 @@ int snd_pcm_plugin_free(snd_pcm_plugin_treturn 0 ;if (plugin->private_free) plugin->private_free (plugin); -if (plugin->buf_channels) -kfree (plugin->buf_channels); -if (plugin->buf) -vfree (plugin->buf); -if (plugin->src_vmask) -kfree (plugin->src_vmask); -if (plugin->dst_vmask) -kfree (plugin->dst_vmask); +kfree (plugin->buf_channels); +vfree (plugin->buf); +kfree (plugin->src_vmask); +kfree (plugin->dst_vmask);kfree (plugin);return 0 ; }
sound/core/oss/route.c +1 -2
@@ -407,8 +407,7 @@ static void route_free(snd_pcm_plugin_troute_t *data = (route_t *)plugin->extra_data;unsigned int dst_channel;for (dst_channel =0 ; dst_channel < plugin->dst_format.channels; ++dst_channel) { -if (data->ttable[dst_channel].srcs !=NULL ) -kfree (data->ttable[dst_channel].srcs); +kfree (data->ttable[dst_channel].srcs); } }
sound/core/pcm.c +1 -2
@@ -830,8 +830,7 @@ void snd_pcm_release_substream(snd_pcm_s runtime->private_free (runtime);snd_free_pages ((void *)runtime->status,PAGE_ALIGN (sizeof (snd_pcm_mmap_status_t)));snd_free_pages ((void *)runtime->control,PAGE_ALIGN (sizeof (snd_pcm_mmap_control_t))); -if (runtime->hw_constraints.rules) -kfree (runtime->hw_constraints.rules); +kfree (runtime->hw_constraints.rules);kfree (runtime); substream->runtime =NULL ; substream->pstr->substream_opened--;
sound/core/pcm_native.c +1 -1
@@ -1445,7 +1445,7 @@ static int snd_pcm_drain(snd_pcm_substre _end:snd_pcm_stream_unlock_irq (substream); -if (drec && drec != &drec_tmp) +if (drec != &drec_tmp)kfree (drec); _unlock:snd_power_unlock (card);
sound/core/seq/oss/seq_oss_readq.c +1 -2
@@ -74,8 +74,7 @@ void snd_seq_oss_readq_delete(seq_oss_readq_t *q) {if (q) { -if (q->q) -kfree (q->q); +kfree (q->q);kfree (q); } }
sound/core/seq/seq_instr.c +0 -2
@@ -56,8 +56,6 @@ snd_seq_kcluster_t *snd_seq_cluster_new(void snd_seq_cluster_free (snd_seq_kcluster_t *cluster,int atomic) { -if (cluster ==NULL ) -return ;kfree (cluster); }
sound/core/seq/seq_memory.c +1 -2
@@ -436,8 +436,7 @@ int snd_seq_pool_done(pool_t *pool) pool->total_elements =0 ;spin_unlock_irqrestore (&pool->lock, flags); -if (ptr) -vfree (ptr); +vfree (ptr);spin_lock_irqsave (&pool->lock, flags); pool->closing =0 ;
sound/core/seq/seq_midi_emul.c +1 -2
@@ -713,8 +713,7 @@ void snd_midi_channel_free_set(snd_midi_ {if (chset ==NULL )return ; -if (chset->channels !=NULL ) -kfree (chset->channels); +kfree (chset->channels);kfree (chset); }
sound/core/seq/seq_midi_event.c +2 -4
@@ -138,8 +138,7 @@ int snd_midi_event_new(int bufsize, snd_void snd_midi_event_free (snd_midi_event_t *dev) {if (dev !=NULL ) { -if (dev->buf) -kfree (dev->buf); +kfree (dev->buf);kfree (dev); } }
@@ -202,8 +201,7 @@ int snd_midi_event_resize_buffer(snd_mid dev->bufsize = bufsize;reset_encode (dev);spin_unlock_irqrestore (&dev->lock, flags); -if (old_buf) -kfree (old_buf); +kfree (old_buf);return 0 ; }
sound/core/sgbuf.c +2 -4
@@ -51,10 +51,8 @@ int snd_free_sgbuf_pages(struct snd_dma_vunmap (dmab->area); dmab->area =NULL ; -if (sgbuf->table) -kfree (sgbuf->table); -if (sgbuf->page_table) -kfree (sgbuf->page_table); +kfree (sgbuf->table); +kfree (sgbuf->page_table);kfree (sgbuf); dmab->private_data =NULL ;
sound/core/timer.c +4 -8
@@ -351,8 +351,7 @@ int snd_timer_close(snd_timer_instance_t }if (timeri->private_free) timeri->private_free (timeri); -if (timeri->owner) -kfree (timeri->owner); +kfree (timeri->owner);kfree (timeri);if (timer && timer->card)module_put (timer->card->module);
@@ -1004,8 +1003,7 @@ static struct _snd_timer_hardware snd_tistatic void snd_timer_free_system (snd_timer_t *timer) { -if (timer->private_data) -kfree (timer->private_data); +kfree (timer->private_data); }static int snd_timer_register_system (void )
@@ -1226,10 +1224,8 @@ static int snd_timer_user_release(structfasync_helper (-1 , file,0 , &tu->fasync);if (tu->timeri)snd_timer_close (tu->timeri); -if (tu->queue) -kfree (tu->queue); -if (tu->tqueue) -kfree (tu->tqueue); +kfree (tu->queue); +kfree (tu->tqueue);kfree (tu); }return 0 ;
sound/i2c/cs8427.c +1 -2
@@ -156,8 +156,7 @@ static int snd_cs8427_send_corudata(snd_static void snd_cs8427_free (snd_i2c_device_t *device) { -if (device->private_data) -kfree (device->private_data); +kfree (device->private_data); } int snd_cs8427_create(snd_i2c_bus_t *bus,
sound/i2c/l3/uda1341.c +1 -2
@@ -730,8 +730,7 @@ static int uda1341_attach(struct l3_cliestatic void uda1341_detach (struct l3_client *clnt) { -if (clnt->driver_data) -kfree (clnt->driver_data); +kfree (clnt->driver_data); } static int
sound/isa/gus/gus_mem.c +1 -2
@@ -100,8 +100,7 @@ int snd_gf1_mem_xfree(snd_gf1_mem_t * alif (block->prev) block->prev->next = block->next; } -if (block->name) -kfree (block->name); +kfree (block->name);kfree (block);return 0 ; }
sound/isa/sb/emu8000_pcm.c +1 -2
@@ -260,8 +260,7 @@ static int emu8k_pcm_open(snd_pcm_substrstatic int emu8k_pcm_close (snd_pcm_substream_t *subs) {emu8k_pcm_t *rec = subs->runtime->private_data; -if (rec) -kfree (rec); +kfree (rec); subs->runtime->private_data =NULL ;return 0 ; }
sound/isa/wavefront/wavefront_fx.c +1 -2
@@ -537,8 +537,7 @@ snd_wavefront_fx_ioctl (snd_hwdep_t *sde r.data[1 ],/* addr */ r.data[2 ],/* cnt */ pd); -if (page_data) -kfree (page_data); +kfree (page_data);break ;default :
sound/pci/ac97/ac97_codec.c +1 -2
@@ -1055,8 +1055,7 @@ static int snd_ac97_bus_free(ac97_bus_t {if (bus) {snd_ac97_bus_proc_done (bus); -if (bus->pcms) -kfree (bus->pcms); +kfree (bus->pcms);if (bus->private_free) bus->private_free (bus);kfree (bus);
sound/pci/ali5451/ali5451.c +1 -2
@@ -1987,8 +1987,7 @@ static int snd_ali_free(ali_t * codec)if (codec->port)pci_release_regions (codec->pci);#ifdef CONFIG_PM -if (codec->image) -kfree (codec->image); +kfree (codec->image);#endif kfree (codec);return 0 ;
sound/pci/cs46xx/dsp_spos.c +3 -9
@@ -289,15 +289,9 @@ void cs46xx_dsp_spos_destroy (cs46xx_tcs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); } -if (ins->code.data) -kfree (ins->code.data); - -if (ins->symbol_table.symbols) -vfree (ins->symbol_table.symbols); - -if (ins->modules) -kfree (ins->modules); - +kfree (ins->code.data); +vfree (ins->symbol_table.symbols); +kfree (ins->modules);kfree (ins);up (&chip->spos_mutex); }
sound/pci/emu10k1/emu10k1_main.c +2 -4
@@ -553,10 +553,8 @@ static int snd_emu10k1_free(emu10k1_t *esnd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)snd_dma_free_pages (&emu->ptb_pages); -if (emu->page_ptr_table) -vfree (emu->page_ptr_table); -if (emu->page_addr_table) -vfree (emu->page_addr_table); +vfree (emu->page_ptr_table); +vfree (emu->page_addr_table);if (emu->irq >=0 )free_irq (emu->irq, (void *)emu);if (emu->port)
sound/pci/emu10k1/emupcm.c +1 -2
@@ -777,8 +777,7 @@ static void snd_emu10k1_pcm_free_substre {emu10k1_pcm_t *epcm = runtime->private_data; -if (epcm) -kfree (epcm); +kfree (epcm); }static int snd_emu10k1_playback_open (snd_pcm_substream_t * substream)
sound/pci/ice1712/ak4xxx.c +1 -2
@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree ((void *)ak->private_value[0 ]); }kfree (ice->akm); }
sound/pci/maestro3.c +1 -2
@@ -2374,8 +2374,7 @@ static int snd_m3_free(m3_t *chip) }#ifdef CONFIG_PM -if (chip->suspend_mem) -vfree (chip->suspend_mem); +vfree (chip->suspend_mem);#endif if (chip->irq >=0 ) {
sound/pci/trident/trident_main.c +1 -2
@@ -3675,8 +3675,7 @@ int snd_trident_free(trident_t *trident)snd_util_memhdr_free (trident->tlb.memhdr);if (trident->tlb.silent_page.area)snd_dma_free_pages (&trident->tlb.silent_page); -if (trident->tlb.shadow_entries) -vfree (trident->tlb.shadow_entries); +vfree (trident->tlb.shadow_entries);snd_dma_free_pages (&trident->tlb.buffer); }if (trident->irq >=0 )
sound/pci/ymfpci/ymfpci_main.c +2 -4
@@ -831,8 +831,7 @@ static void snd_ymfpci_pcm_free_substrea {ymfpci_pcm_t *ypcm = runtime->private_data; -if (ypcm) -kfree (ypcm); +kfree (ypcm); }static int snd_ymfpci_playback_open_1 (snd_pcm_substream_t * substream)
@@ -2065,8 +2064,7 @@ static int snd_ymfpci_free(ymfpci_t *chi#endif #ifdef CONFIG_PM -if (chip->saved_regs) -vfree (chip->saved_regs); +vfree (chip->saved_regs);#endif if (chip->mpu_res) {release_resource (chip->mpu_res);
sound/ppc/pmac.c +1 -1
@@ -71,7 +71,7 @@ static int snd_pmac_dbdma_alloc(pmac_dbdstatic void snd_pmac_dbdma_free (pmac_dbdma_t *rec) { -if (rec && rec->space) +if (rec)kfree (rec->space); }
sound/synth/emux/emux.c +2 -6
@@ -137,12 +137,8 @@ int snd_emux_free(snd_emux_t *emu)if (emu->sflist)snd_sf_free (emu->sflist); -if (emu->voices) -kfree (emu->voices); - -if (emu->name) -kfree (emu->name); - +kfree (emu->voices); +kfree (emu->name);kfree (emu);return 0 ; }
sound/synth/emux/emux_seq.c +1 -2
@@ -197,8 +197,7 @@ free_port(void *private_data)#ifdef SNDRV_EMUX_USE_RAW_EFFECT snd_emux_delete_effect (p);#endif -if (p->chset.channels) -kfree (p->chset.channels); +kfree (p->chset.channels);kfree (p); } }
sound/usb/usbaudio.c +5 -10
@@ -2063,8 +2063,7 @@ static void free_substream(snd_usb_substreturn ;/* not initialized */ list_for_each_safe (p, n, &subs->fmt_list) { struct audioformat *fp = list_entry(p, struct audioformat, list); -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp); } }
@@ -2550,8 +2549,7 @@ static int parse_audio_endpoints(snd_usb/* ok, let's parse further... */ if (parse_audio_format (dev, fp, format, fmt, stream) <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);continue ; }
@@ -2559,8 +2557,7 @@ static int parse_audio_endpoints(snd_usbsnd_printdd (KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n" , dev->devnum, iface_no, i, fp->endpoint); err =add_audio_endpoint (chip, stream, fp);if (err <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);return err; }
@@ -2693,15 +2690,13 @@ static int create_fixed_stream_quirk(snd err =add_audio_endpoint (chip, stream, fp);if (err <0 ) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return err; }if (fp->iface !=get_iface_desc (&iface->altsetting[0 ])->bInterfaceNumber || fp->altset_idx >= iface->num_altsetting) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return -EINVAL ; } alts = &iface->altsetting[fp->altset_idx];
sound/usb/usbmidi.c +2 -4
@@ -504,8 +504,7 @@ static snd_rawmidi_ops_t snd_usbmidi_inpstatic void snd_usbmidi_in_endpoint_delete (snd_usb_midi_in_endpoint_t * ep) {if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
@@ -632,8 +631,7 @@ static void snd_usbmidi_out_endpoint_delif (ep->tasklet.func)tasklet_kill (&ep->tasklet);if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
sound/usb/usbmixer.c +1 -1
@@ -573,7 +573,7 @@ static struct usb_feature_control_info astatic void usb_mixer_elem_free (snd_kcontrol_t *kctl) {if (kctl->private_data) { -kfree ((void *)kctl->private_data); +kfree (kctl->private_data); kctl->private_data =NULL ; } }
sound/usb/usx2y/usbusx2y.c +2 -4
@@ -285,8 +285,7 @@ static void usX2Y_unlinkSeq(snd_usX2Y_AsS ->urb[i] =NULL ; } } -if (S ->buffer) -kfree (S ->buffer); +kfree (S ->buffer); }
@@ -389,8 +388,7 @@ static struct usb_driver snd_usX2Y_usb_dstatic void snd_usX2Y_card_private_free (snd_card_t *card) { -if (usX2Y (card)->In04Buf) -kfree (usX2Y (card)->In04Buf); +kfree (usX2Y (card)->In04Buf);usb_free_urb (usX2Y (card)->In04urb);if (usX2Y (card)->us428ctls_sharedmem)snd_free_pages (usX2Y (card)->us428ctls_sharedmem,sizeof (*usX2Y (card)->us428ctls_sharedmem));
Signature · 4 lines
Marcel Sebek jabber: [email protected] ICQ: 279852819 linux user number: 307850 GPG ID: 5F88735E GPG FP: 0F01 BAB8 3148 94DB B95D 1FCA 8B63 CA06 5F88 735E
Quoted 5 lines · Marcel Sebek
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +0
-0@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);
sound/core/init.c int snd_card_file_remove(snd_card_t *car · line 672
Quoted 10 lines
sound/core/init.c +2
-3if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
The above change seems to always trigger the ENOENT return, no?
Phil
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
Quoted 5 lines · Marcel Sebek
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +0
-0@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);
sound/core/init.c int snd_card_file_remove(snd_card_t *car · line 672
Quoted 10 lines
sound/core/init.c +2
-3if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
The above change seems to always trigger the ENOENT return, no?
Phil
Quoted 15 lines · Marcel Sebek
Quoted 15 lines
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +2
-3@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
Quoted 1 line · Phil Oester
The above change seems to always trigger the ENOENT return, no?
No it doesn't. kfree() does not set mfile to NULL. However, I think the above would be more readable if we did the kfree() _after_ the NULL check. Marcel, what do you think?
Pekka
Quoted 18 lines · Pekka Enberg
Quoted 7 lines · Marcel Sebek
Quoted 7 lines
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +0
-0@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep);Quoted 8 lines
sound/core/init.c int snd_card_file_remove(snd_card_t *car · line 672
Quoted 8 lines
sound/core/init.c +2
-3-if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }On Sat, 2004-11-27 at 13:23 -0800, Phil Oester wrote:
Quoted 6 lines
Quoted 1 line
The above change seems to always trigger the ENOENT return, no?
No it doesn't.
kfree()does not set mfile to NULL. However, I think the above would be more readable if we did thekfree()_after_ the NULL check. Marcel, what do you think?
I think yes. The change I did only added one extra kfree call for (mfile == NULL) and didn't save the NULL check. So here's an updated version of the patch (and hopefully the final version :).
sound/core/info.c +1 -2
@@ -895,8 +895,7 @@ void snd_info_free_entry(snd_info_entry_ {if (entry ==NULL )return ; -if (entry->name) -kfree ((char *)entry->name); +kfree (entry->name);if (entry->private_free) entry->private_free (entry);kfree (entry);
sound/core/init.c +2 -3
@@ -665,12 +665,11 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +if (!mfile)snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; } +kfree (mfile);return 0 ; }
sound/core/ioctl32/ioctl32.c +2 -4
@@ -370,10 +370,8 @@ static inline int _snd_ioctl32_ctl_elem_if (copy_to_user ((void __user *)arg, data32,sizeof (*data32))) err = -EFAULT ; __end: -if (data32) -kfree (data32); -if (data) -kfree (data); +kfree (data32); +kfree (data);return err; }
sound/core/ioctl32/ioctl32.h +2 -4
@@ -103,10 +103,8 @@ static inline int _snd_ioctl32_##type(un err = -EFAULT ;\ }\ __end:\ -if (data)\ -kfree (data);\ -if (data32)\ -kfree (data32);\ +kfree (data);\ +kfree (data32);\return err;\ }
sound/core/ioctl32/pcm32.c +4 -8
@@ -224,10 +224,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
@@ -432,10 +430,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
sound/core/oss/mixer_oss.c +12 -24
@@ -527,10 +527,8 @@ static void snd_mixer_oss_get_volume1_vo *right =snd_mixer_oss_conv1 (uctl->value.integer.value[1 ], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1 ]); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -566,10 +564,8 @@ static void snd_mixer_oss_get_volume1_sw *right =0 ; __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer,
@@ -628,10 +624,8 @@ static void snd_mixer_oss_put_volume1_vosnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -673,10 +667,8 @@ static void snd_mixer_oss_put_volume1_swsnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer,
@@ -802,10 +794,8 @@ static int snd_mixer_oss_get_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
@@ -853,10 +843,8 @@ static int snd_mixer_oss_put_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
sound/core/oss/pcm_oss.c +5 -10
@@ -513,8 +513,7 @@ static int snd_pcm_oss_change_params(snd runtime->oss.params =0 ; runtime->oss.prepare =1 ; -if (runtime->oss.buffer !=NULL ) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer); runtime->oss.buffer =vmalloc (runtime->oss.period_bytes); runtime->oss.buffer_used =0 ;if (runtime->dma_area)
@@ -524,12 +523,9 @@ static int snd_pcm_oss_change_params(snd err =0 ; failure: -if (sw_params) -kfree (sw_params); -if (params) -kfree (params); -if (sparams) -kfree (sparams); +kfree (sw_params); +kfree (params); +kfree (sparams);return err; }
@@ -1671,8 +1667,7 @@ static void snd_pcm_oss_release_substrea {snd_pcm_runtime_t *runtime; runtime = substream->runtime; -if (runtime->oss.buffer) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer);snd_pcm_oss_plugin_clear (substream); substream->oss.file =NULL ; substream->oss.oss =0 ;
sound/core/oss/pcm_plugin.c +5 -10
@@ -86,8 +86,7 @@ static int snd_pcm_plugin_alloc(snd_pcm_snd_assert ((size %8 ) ==0 , return -ENXIO ); size /=8 ;if (plugin->buf_frames < frames) { -if (plugin->buf) -vfree (plugin->buf); +vfree (plugin->buf); plugin->buf =vmalloc (size); plugin->buf_frames = frames; }
@@ -217,14 +216,10 @@ int snd_pcm_plugin_free(snd_pcm_plugin_treturn 0 ;if (plugin->private_free) plugin->private_free (plugin); -if (plugin->buf_channels) -kfree (plugin->buf_channels); -if (plugin->buf) -vfree (plugin->buf); -if (plugin->src_vmask) -kfree (plugin->src_vmask); -if (plugin->dst_vmask) -kfree (plugin->dst_vmask); +kfree (plugin->buf_channels); +vfree (plugin->buf); +kfree (plugin->src_vmask); +kfree (plugin->dst_vmask);kfree (plugin);return 0 ; }
sound/core/oss/route.c +1 -2
@@ -407,8 +407,7 @@ static void route_free(snd_pcm_plugin_troute_t *data = (route_t *)plugin->extra_data;unsigned int dst_channel;for (dst_channel =0 ; dst_channel < plugin->dst_format.channels; ++dst_channel) { -if (data->ttable[dst_channel].srcs !=NULL ) -kfree (data->ttable[dst_channel].srcs); +kfree (data->ttable[dst_channel].srcs); } }
sound/core/pcm.c +1 -2
@@ -830,8 +830,7 @@ void snd_pcm_release_substream(snd_pcm_s runtime->private_free (runtime);snd_free_pages ((void *)runtime->status,PAGE_ALIGN (sizeof (snd_pcm_mmap_status_t)));snd_free_pages ((void *)runtime->control,PAGE_ALIGN (sizeof (snd_pcm_mmap_control_t))); -if (runtime->hw_constraints.rules) -kfree (runtime->hw_constraints.rules); +kfree (runtime->hw_constraints.rules);kfree (runtime); substream->runtime =NULL ; substream->pstr->substream_opened--;
sound/core/pcm_native.c +1 -1
@@ -1445,7 +1445,7 @@ static int snd_pcm_drain(snd_pcm_substre _end:snd_pcm_stream_unlock_irq (substream); -if (drec && drec != &drec_tmp) +if (drec != &drec_tmp)kfree (drec); _unlock:snd_power_unlock (card);
sound/core/seq/oss/seq_oss_readq.c +1 -2
@@ -74,8 +74,7 @@ void snd_seq_oss_readq_delete(seq_oss_readq_t *q) {if (q) { -if (q->q) -kfree (q->q); +kfree (q->q);kfree (q); } }
sound/core/seq/seq_instr.c +0 -2
@@ -56,8 +56,6 @@ snd_seq_kcluster_t *snd_seq_cluster_new(void snd_seq_cluster_free (snd_seq_kcluster_t *cluster,int atomic) { -if (cluster ==NULL ) -return ;kfree (cluster); }
sound/core/seq/seq_memory.c +1 -2
@@ -436,8 +436,7 @@ int snd_seq_pool_done(pool_t *pool) pool->total_elements =0 ;spin_unlock_irqrestore (&pool->lock, flags); -if (ptr) -vfree (ptr); +vfree (ptr);spin_lock_irqsave (&pool->lock, flags); pool->closing =0 ;
sound/core/seq/seq_midi_emul.c +1 -2
@@ -713,8 +713,7 @@ void snd_midi_channel_free_set(snd_midi_ {if (chset ==NULL )return ; -if (chset->channels !=NULL ) -kfree (chset->channels); +kfree (chset->channels);kfree (chset); }
sound/core/seq/seq_midi_event.c +2 -4
@@ -138,8 +138,7 @@ int snd_midi_event_new(int bufsize, snd_void snd_midi_event_free (snd_midi_event_t *dev) {if (dev !=NULL ) { -if (dev->buf) -kfree (dev->buf); +kfree (dev->buf);kfree (dev); } }
@@ -202,8 +201,7 @@ int snd_midi_event_resize_buffer(snd_mid dev->bufsize = bufsize;reset_encode (dev);spin_unlock_irqrestore (&dev->lock, flags); -if (old_buf) -kfree (old_buf); +kfree (old_buf);return 0 ; }
sound/core/sgbuf.c +2 -4
@@ -51,10 +51,8 @@ int snd_free_sgbuf_pages(struct snd_dma_vunmap (dmab->area); dmab->area =NULL ; -if (sgbuf->table) -kfree (sgbuf->table); -if (sgbuf->page_table) -kfree (sgbuf->page_table); +kfree (sgbuf->table); +kfree (sgbuf->page_table);kfree (sgbuf); dmab->private_data =NULL ;
sound/core/timer.c +4 -8
@@ -351,8 +351,7 @@ int snd_timer_close(snd_timer_instance_t }if (timeri->private_free) timeri->private_free (timeri); -if (timeri->owner) -kfree (timeri->owner); +kfree (timeri->owner);kfree (timeri);if (timer && timer->card)module_put (timer->card->module);
@@ -1004,8 +1003,7 @@ static struct _snd_timer_hardware snd_tistatic void snd_timer_free_system (snd_timer_t *timer) { -if (timer->private_data) -kfree (timer->private_data); +kfree (timer->private_data); }static int snd_timer_register_system (void )
@@ -1226,10 +1224,8 @@ static int snd_timer_user_release(structfasync_helper (-1 , file,0 , &tu->fasync);if (tu->timeri)snd_timer_close (tu->timeri); -if (tu->queue) -kfree (tu->queue); -if (tu->tqueue) -kfree (tu->tqueue); +kfree (tu->queue); +kfree (tu->tqueue);kfree (tu); }return 0 ;
sound/i2c/cs8427.c +1 -2
@@ -156,8 +156,7 @@ static int snd_cs8427_send_corudata(snd_static void snd_cs8427_free (snd_i2c_device_t *device) { -if (device->private_data) -kfree (device->private_data); +kfree (device->private_data); } int snd_cs8427_create(snd_i2c_bus_t *bus,
sound/i2c/l3/uda1341.c +1 -2
@@ -730,8 +730,7 @@ static int uda1341_attach(struct l3_cliestatic void uda1341_detach (struct l3_client *clnt) { -if (clnt->driver_data) -kfree (clnt->driver_data); +kfree (clnt->driver_data); } static int
sound/isa/gus/gus_mem.c +1 -2
@@ -100,8 +100,7 @@ int snd_gf1_mem_xfree(snd_gf1_mem_t * alif (block->prev) block->prev->next = block->next; } -if (block->name) -kfree (block->name); +kfree (block->name);kfree (block);return 0 ; }
sound/isa/sb/emu8000_pcm.c +1 -2
@@ -260,8 +260,7 @@ static int emu8k_pcm_open(snd_pcm_substrstatic int emu8k_pcm_close (snd_pcm_substream_t *subs) {emu8k_pcm_t *rec = subs->runtime->private_data; -if (rec) -kfree (rec); +kfree (rec); subs->runtime->private_data =NULL ;return 0 ; }
sound/isa/wavefront/wavefront_fx.c +1 -2
@@ -537,8 +537,7 @@ snd_wavefront_fx_ioctl (snd_hwdep_t *sde r.data[1 ],/* addr */ r.data[2 ],/* cnt */ pd); -if (page_data) -kfree (page_data); +kfree (page_data);break ;default :
sound/pci/ac97/ac97_codec.c +1 -2
@@ -1055,8 +1055,7 @@ static int snd_ac97_bus_free(ac97_bus_t {if (bus) {snd_ac97_bus_proc_done (bus); -if (bus->pcms) -kfree (bus->pcms); +kfree (bus->pcms);if (bus->private_free) bus->private_free (bus);kfree (bus);
sound/pci/ali5451/ali5451.c +1 -2
@@ -1987,8 +1987,7 @@ static int snd_ali_free(ali_t * codec)if (codec->port)pci_release_regions (codec->pci);#ifdef CONFIG_PM -if (codec->image) -kfree (codec->image); +kfree (codec->image);#endif kfree (codec);return 0 ;
sound/pci/cs46xx/dsp_spos.c +3 -9
@@ -289,15 +289,9 @@ void cs46xx_dsp_spos_destroy (cs46xx_tcs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); } -if (ins->code.data) -kfree (ins->code.data); - -if (ins->symbol_table.symbols) -vfree (ins->symbol_table.symbols); - -if (ins->modules) -kfree (ins->modules); - +kfree (ins->code.data); +vfree (ins->symbol_table.symbols); +kfree (ins->modules);kfree (ins);up (&chip->spos_mutex); }
sound/pci/emu10k1/emu10k1_main.c +2 -4
@@ -553,10 +553,8 @@ static int snd_emu10k1_free(emu10k1_t *esnd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)snd_dma_free_pages (&emu->ptb_pages); -if (emu->page_ptr_table) -vfree (emu->page_ptr_table); -if (emu->page_addr_table) -vfree (emu->page_addr_table); +vfree (emu->page_ptr_table); +vfree (emu->page_addr_table);if (emu->irq >=0 )free_irq (emu->irq, (void *)emu);if (emu->port)
sound/pci/emu10k1/emupcm.c +1 -2
@@ -777,8 +777,7 @@ static void snd_emu10k1_pcm_free_substre {emu10k1_pcm_t *epcm = runtime->private_data; -if (epcm) -kfree (epcm); +kfree (epcm); }static int snd_emu10k1_playback_open (snd_pcm_substream_t * substream)
sound/pci/ice1712/ak4xxx.c +1 -2
@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree ((void *)ak->private_value[0 ]); }kfree (ice->akm); }
sound/pci/maestro3.c +1 -2
@@ -2374,8 +2374,7 @@ static int snd_m3_free(m3_t *chip) }#ifdef CONFIG_PM -if (chip->suspend_mem) -vfree (chip->suspend_mem); +vfree (chip->suspend_mem);#endif if (chip->irq >=0 ) {
sound/pci/trident/trident_main.c +1 -2
@@ -3675,8 +3675,7 @@ int snd_trident_free(trident_t *trident)snd_util_memhdr_free (trident->tlb.memhdr);if (trident->tlb.silent_page.area)snd_dma_free_pages (&trident->tlb.silent_page); -if (trident->tlb.shadow_entries) -vfree (trident->tlb.shadow_entries); +vfree (trident->tlb.shadow_entries);snd_dma_free_pages (&trident->tlb.buffer); }if (trident->irq >=0 )
sound/pci/ymfpci/ymfpci_main.c +2 -4
@@ -831,8 +831,7 @@ static void snd_ymfpci_pcm_free_substrea {ymfpci_pcm_t *ypcm = runtime->private_data; -if (ypcm) -kfree (ypcm); +kfree (ypcm); }static int snd_ymfpci_playback_open_1 (snd_pcm_substream_t * substream)
@@ -2065,8 +2064,7 @@ static int snd_ymfpci_free(ymfpci_t *chi#endif #ifdef CONFIG_PM -if (chip->saved_regs) -vfree (chip->saved_regs); +vfree (chip->saved_regs);#endif if (chip->mpu_res) {release_resource (chip->mpu_res);
sound/ppc/pmac.c +1 -1
@@ -71,7 +71,7 @@ static int snd_pmac_dbdma_alloc(pmac_dbdstatic void snd_pmac_dbdma_free (pmac_dbdma_t *rec) { -if (rec && rec->space) +if (rec)kfree (rec->space); }
sound/synth/emux/emux.c +2 -6
@@ -137,12 +137,8 @@ int snd_emux_free(snd_emux_t *emu)if (emu->sflist)snd_sf_free (emu->sflist); -if (emu->voices) -kfree (emu->voices); - -if (emu->name) -kfree (emu->name); - +kfree (emu->voices); +kfree (emu->name);kfree (emu);return 0 ; }
sound/synth/emux/emux_seq.c +1 -2
@@ -197,8 +197,7 @@ free_port(void *private_data)#ifdef SNDRV_EMUX_USE_RAW_EFFECT snd_emux_delete_effect (p);#endif -if (p->chset.channels) -kfree (p->chset.channels); +kfree (p->chset.channels);kfree (p); } }
sound/usb/usbaudio.c +5 -10
@@ -2063,8 +2063,7 @@ static void free_substream(snd_usb_substreturn ;/* not initialized */ list_for_each_safe (p, n, &subs->fmt_list) { struct audioformat *fp = list_entry(p, struct audioformat, list); -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp); } }
@@ -2550,8 +2549,7 @@ static int parse_audio_endpoints(snd_usb/* ok, let's parse further... */ if (parse_audio_format (dev, fp, format, fmt, stream) <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);continue ; }
@@ -2559,8 +2557,7 @@ static int parse_audio_endpoints(snd_usbsnd_printdd (KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n" , dev->devnum, iface_no, i, fp->endpoint); err =add_audio_endpoint (chip, stream, fp);if (err <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);return err; }
@@ -2693,15 +2690,13 @@ static int create_fixed_stream_quirk(snd err =add_audio_endpoint (chip, stream, fp);if (err <0 ) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return err; }if (fp->iface !=get_iface_desc (&iface->altsetting[0 ])->bInterfaceNumber || fp->altset_idx >= iface->num_altsetting) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return -EINVAL ; } alts = &iface->altsetting[fp->altset_idx];
sound/usb/usbmidi.c +2 -4
@@ -504,8 +504,7 @@ static snd_rawmidi_ops_t snd_usbmidi_inpstatic void snd_usbmidi_in_endpoint_delete (snd_usb_midi_in_endpoint_t * ep) {if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
@@ -632,8 +631,7 @@ static void snd_usbmidi_out_endpoint_delif (ep->tasklet.func)tasklet_kill (&ep->tasklet);if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
sound/usb/usbmixer.c +1 -1
@@ -573,7 +573,7 @@ static struct usb_feature_control_info astatic void usb_mixer_elem_free (snd_kcontrol_t *kctl) {if (kctl->private_data) { -kfree ((void *)kctl->private_data); +kfree (kctl->private_data); kctl->private_data =NULL ; } }
sound/usb/usx2y/usbusx2y.c +2 -4
@@ -285,8 +285,7 @@ static void usX2Y_unlinkSeq(snd_usX2Y_AsS ->urb[i] =NULL ; } } -if (S ->buffer) -kfree (S ->buffer); +kfree (S ->buffer); }
@@ -389,8 +388,7 @@ static struct usb_driver snd_usX2Y_usb_dstatic void snd_usX2Y_card_private_free (snd_card_t *card) { -if (usX2Y (card)->In04Buf) -kfree (usX2Y (card)->In04Buf); +kfree (usX2Y (card)->In04Buf);usb_free_urb (usX2Y (card)->In04urb);if (usX2Y (card)->us428ctls_sharedmem)snd_free_pages (usX2Y (card)->us428ctls_sharedmem,sizeof (*usX2Y (card)->us428ctls_sharedmem));
Signature · 4 lines
Marcel Sebek jabber: [email protected] ICQ: 279852819 linux user number: 307850 GPG ID: 5F88735E GPG FP: 0F01 BAB8 3148 94DB B95D 1FCA 8B63 CA06 5F88 735E
Quoted 18 lines · Pekka Enberg
Quoted 7 lines · Marcel Sebek
Quoted 7 lines
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +0
-0@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep);Quoted 8 lines
sound/core/init.c int snd_card_file_remove(snd_card_t *car · line 672
Quoted 8 lines
sound/core/init.c +2
-3-if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }On Sat, 2004-11-27 at 13:23 -0800, Phil Oester wrote:
Quoted 6 lines
Quoted 1 line
The above change seems to always trigger the ENOENT return, no?
No it doesn't.
kfree()does not set mfile to NULL. However, I think the above would be more readable if we did thekfree()_after_ the NULL check. Marcel, what do you think?
I think yes. The change I did only added one extra kfree call for (mfile == NULL) and didn't save the NULL check. So here's an updated version of the patch (and hopefully the final version :).
sound/core/info.c +1 -2
@@ -895,8 +895,7 @@ void snd_info_free_entry(snd_info_entry_ {if (entry ==NULL )return ; -if (entry->name) -kfree ((char *)entry->name); +kfree (entry->name);if (entry->private_free) entry->private_free (entry);kfree (entry);
sound/core/init.c +2 -3
@@ -665,12 +665,11 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +if (!mfile)snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; } +kfree (mfile);return 0 ; }
sound/core/ioctl32/ioctl32.c +2 -4
@@ -370,10 +370,8 @@ static inline int _snd_ioctl32_ctl_elem_if (copy_to_user ((void __user *)arg, data32,sizeof (*data32))) err = -EFAULT ; __end: -if (data32) -kfree (data32); -if (data) -kfree (data); +kfree (data32); +kfree (data);return err; }
sound/core/ioctl32/ioctl32.h +2 -4
@@ -103,10 +103,8 @@ static inline int _snd_ioctl32_##type(un err = -EFAULT ;\ }\ __end:\ -if (data)\ -kfree (data);\ -if (data32)\ -kfree (data32);\ +kfree (data);\ +kfree (data32);\return err;\ }
sound/core/ioctl32/pcm32.c +4 -8
@@ -224,10 +224,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
@@ -432,10 +430,8 @@ static inline int _snd_ioctl32_pcm_hw_paelse recalculate_boundary (file); __end: -if (data) -kfree (data); -if (data32) -kfree (data32); +kfree (data); +kfree (data32);return err; }
sound/core/oss/mixer_oss.c +12 -24
@@ -527,10 +527,8 @@ static void snd_mixer_oss_get_volume1_vo *right =snd_mixer_oss_conv1 (uctl->value.integer.value[1 ], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1 ]); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_get_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -566,10 +564,8 @@ static void snd_mixer_oss_get_volume1_sw *right =0 ; __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_get_volume1(snd_mixer_oss_file_t *fmixer,
@@ -628,10 +624,8 @@ static void snd_mixer_oss_put_volume1_vosnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static void snd_mixer_oss_put_volume1_sw(snd_mixer_oss_file_t *fmixer,
@@ -673,10 +667,8 @@ static void snd_mixer_oss_put_volume1_swsnd_ctl_notify (card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); __unalloc:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo); } static int snd_mixer_oss_put_volume1(snd_mixer_oss_file_t *fmixer,
@@ -802,10 +794,8 @@ static int snd_mixer_oss_get_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
@@ -853,10 +843,8 @@ static int snd_mixer_oss_put_recsrc2(snd err =0 ; __unlock:up_read (&card->controls_rwsem); -if (uctl) -kfree (uctl); -if (uinfo) -kfree (uinfo); +kfree (uctl); +kfree (uinfo);return err; }
sound/core/oss/pcm_oss.c +5 -10
@@ -513,8 +513,7 @@ static int snd_pcm_oss_change_params(snd runtime->oss.params =0 ; runtime->oss.prepare =1 ; -if (runtime->oss.buffer !=NULL ) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer); runtime->oss.buffer =vmalloc (runtime->oss.period_bytes); runtime->oss.buffer_used =0 ;if (runtime->dma_area)
@@ -524,12 +523,9 @@ static int snd_pcm_oss_change_params(snd err =0 ; failure: -if (sw_params) -kfree (sw_params); -if (params) -kfree (params); -if (sparams) -kfree (sparams); +kfree (sw_params); +kfree (params); +kfree (sparams);return err; }
@@ -1671,8 +1667,7 @@ static void snd_pcm_oss_release_substrea {snd_pcm_runtime_t *runtime; runtime = substream->runtime; -if (runtime->oss.buffer) -vfree (runtime->oss.buffer); +vfree (runtime->oss.buffer);snd_pcm_oss_plugin_clear (substream); substream->oss.file =NULL ; substream->oss.oss =0 ;
sound/core/oss/pcm_plugin.c +5 -10
@@ -86,8 +86,7 @@ static int snd_pcm_plugin_alloc(snd_pcm_snd_assert ((size %8 ) ==0 , return -ENXIO ); size /=8 ;if (plugin->buf_frames < frames) { -if (plugin->buf) -vfree (plugin->buf); +vfree (plugin->buf); plugin->buf =vmalloc (size); plugin->buf_frames = frames; }
@@ -217,14 +216,10 @@ int snd_pcm_plugin_free(snd_pcm_plugin_treturn 0 ;if (plugin->private_free) plugin->private_free (plugin); -if (plugin->buf_channels) -kfree (plugin->buf_channels); -if (plugin->buf) -vfree (plugin->buf); -if (plugin->src_vmask) -kfree (plugin->src_vmask); -if (plugin->dst_vmask) -kfree (plugin->dst_vmask); +kfree (plugin->buf_channels); +vfree (plugin->buf); +kfree (plugin->src_vmask); +kfree (plugin->dst_vmask);kfree (plugin);return 0 ; }
sound/core/oss/route.c +1 -2
@@ -407,8 +407,7 @@ static void route_free(snd_pcm_plugin_troute_t *data = (route_t *)plugin->extra_data;unsigned int dst_channel;for (dst_channel =0 ; dst_channel < plugin->dst_format.channels; ++dst_channel) { -if (data->ttable[dst_channel].srcs !=NULL ) -kfree (data->ttable[dst_channel].srcs); +kfree (data->ttable[dst_channel].srcs); } }
sound/core/pcm.c +1 -2
@@ -830,8 +830,7 @@ void snd_pcm_release_substream(snd_pcm_s runtime->private_free (runtime);snd_free_pages ((void *)runtime->status,PAGE_ALIGN (sizeof (snd_pcm_mmap_status_t)));snd_free_pages ((void *)runtime->control,PAGE_ALIGN (sizeof (snd_pcm_mmap_control_t))); -if (runtime->hw_constraints.rules) -kfree (runtime->hw_constraints.rules); +kfree (runtime->hw_constraints.rules);kfree (runtime); substream->runtime =NULL ; substream->pstr->substream_opened--;
sound/core/pcm_native.c +1 -1
@@ -1445,7 +1445,7 @@ static int snd_pcm_drain(snd_pcm_substre _end:snd_pcm_stream_unlock_irq (substream); -if (drec && drec != &drec_tmp) +if (drec != &drec_tmp)kfree (drec); _unlock:snd_power_unlock (card);
sound/core/seq/oss/seq_oss_readq.c +1 -2
@@ -74,8 +74,7 @@ void snd_seq_oss_readq_delete(seq_oss_readq_t *q) {if (q) { -if (q->q) -kfree (q->q); +kfree (q->q);kfree (q); } }
sound/core/seq/seq_instr.c +0 -2
@@ -56,8 +56,6 @@ snd_seq_kcluster_t *snd_seq_cluster_new(void snd_seq_cluster_free (snd_seq_kcluster_t *cluster,int atomic) { -if (cluster ==NULL ) -return ;kfree (cluster); }
sound/core/seq/seq_memory.c +1 -2
@@ -436,8 +436,7 @@ int snd_seq_pool_done(pool_t *pool) pool->total_elements =0 ;spin_unlock_irqrestore (&pool->lock, flags); -if (ptr) -vfree (ptr); +vfree (ptr);spin_lock_irqsave (&pool->lock, flags); pool->closing =0 ;
sound/core/seq/seq_midi_emul.c +1 -2
@@ -713,8 +713,7 @@ void snd_midi_channel_free_set(snd_midi_ {if (chset ==NULL )return ; -if (chset->channels !=NULL ) -kfree (chset->channels); +kfree (chset->channels);kfree (chset); }
sound/core/seq/seq_midi_event.c +2 -4
@@ -138,8 +138,7 @@ int snd_midi_event_new(int bufsize, snd_void snd_midi_event_free (snd_midi_event_t *dev) {if (dev !=NULL ) { -if (dev->buf) -kfree (dev->buf); +kfree (dev->buf);kfree (dev); } }
@@ -202,8 +201,7 @@ int snd_midi_event_resize_buffer(snd_mid dev->bufsize = bufsize;reset_encode (dev);spin_unlock_irqrestore (&dev->lock, flags); -if (old_buf) -kfree (old_buf); +kfree (old_buf);return 0 ; }
sound/core/sgbuf.c +2 -4
@@ -51,10 +51,8 @@ int snd_free_sgbuf_pages(struct snd_dma_vunmap (dmab->area); dmab->area =NULL ; -if (sgbuf->table) -kfree (sgbuf->table); -if (sgbuf->page_table) -kfree (sgbuf->page_table); +kfree (sgbuf->table); +kfree (sgbuf->page_table);kfree (sgbuf); dmab->private_data =NULL ;
sound/core/timer.c +4 -8
@@ -351,8 +351,7 @@ int snd_timer_close(snd_timer_instance_t }if (timeri->private_free) timeri->private_free (timeri); -if (timeri->owner) -kfree (timeri->owner); +kfree (timeri->owner);kfree (timeri);if (timer && timer->card)module_put (timer->card->module);
@@ -1004,8 +1003,7 @@ static struct _snd_timer_hardware snd_tistatic void snd_timer_free_system (snd_timer_t *timer) { -if (timer->private_data) -kfree (timer->private_data); +kfree (timer->private_data); }static int snd_timer_register_system (void )
@@ -1226,10 +1224,8 @@ static int snd_timer_user_release(structfasync_helper (-1 , file,0 , &tu->fasync);if (tu->timeri)snd_timer_close (tu->timeri); -if (tu->queue) -kfree (tu->queue); -if (tu->tqueue) -kfree (tu->tqueue); +kfree (tu->queue); +kfree (tu->tqueue);kfree (tu); }return 0 ;
sound/i2c/cs8427.c +1 -2
@@ -156,8 +156,7 @@ static int snd_cs8427_send_corudata(snd_static void snd_cs8427_free (snd_i2c_device_t *device) { -if (device->private_data) -kfree (device->private_data); +kfree (device->private_data); } int snd_cs8427_create(snd_i2c_bus_t *bus,
sound/i2c/l3/uda1341.c +1 -2
@@ -730,8 +730,7 @@ static int uda1341_attach(struct l3_cliestatic void uda1341_detach (struct l3_client *clnt) { -if (clnt->driver_data) -kfree (clnt->driver_data); +kfree (clnt->driver_data); } static int
sound/isa/gus/gus_mem.c +1 -2
@@ -100,8 +100,7 @@ int snd_gf1_mem_xfree(snd_gf1_mem_t * alif (block->prev) block->prev->next = block->next; } -if (block->name) -kfree (block->name); +kfree (block->name);kfree (block);return 0 ; }
sound/isa/sb/emu8000_pcm.c +1 -2
@@ -260,8 +260,7 @@ static int emu8k_pcm_open(snd_pcm_substrstatic int emu8k_pcm_close (snd_pcm_substream_t *subs) {emu8k_pcm_t *rec = subs->runtime->private_data; -if (rec) -kfree (rec); +kfree (rec); subs->runtime->private_data =NULL ;return 0 ; }
sound/isa/wavefront/wavefront_fx.c +1 -2
@@ -537,8 +537,7 @@ snd_wavefront_fx_ioctl (snd_hwdep_t *sde r.data[1 ],/* addr */ r.data[2 ],/* cnt */ pd); -if (page_data) -kfree (page_data); +kfree (page_data);break ;default :
sound/pci/ac97/ac97_codec.c +1 -2
@@ -1055,8 +1055,7 @@ static int snd_ac97_bus_free(ac97_bus_t {if (bus) {snd_ac97_bus_proc_done (bus); -if (bus->pcms) -kfree (bus->pcms); +kfree (bus->pcms);if (bus->private_free) bus->private_free (bus);kfree (bus);
sound/pci/ali5451/ali5451.c +1 -2
@@ -1987,8 +1987,7 @@ static int snd_ali_free(ali_t * codec)if (codec->port)pci_release_regions (codec->pci);#ifdef CONFIG_PM -if (codec->image) -kfree (codec->image); +kfree (codec->image);#endif kfree (codec);return 0 ;
sound/pci/cs46xx/dsp_spos.c +3 -9
@@ -289,15 +289,9 @@ void cs46xx_dsp_spos_destroy (cs46xx_tcs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) ); } -if (ins->code.data) -kfree (ins->code.data); - -if (ins->symbol_table.symbols) -vfree (ins->symbol_table.symbols); - -if (ins->modules) -kfree (ins->modules); - +kfree (ins->code.data); +vfree (ins->symbol_table.symbols); +kfree (ins->modules);kfree (ins);up (&chip->spos_mutex); }
sound/pci/emu10k1/emu10k1_main.c +2 -4
@@ -553,10 +553,8 @@ static int snd_emu10k1_free(emu10k1_t *esnd_dma_free_pages (&emu->silent_page);if (emu->ptb_pages.area)snd_dma_free_pages (&emu->ptb_pages); -if (emu->page_ptr_table) -vfree (emu->page_ptr_table); -if (emu->page_addr_table) -vfree (emu->page_addr_table); +vfree (emu->page_ptr_table); +vfree (emu->page_addr_table);if (emu->irq >=0 )free_irq (emu->irq, (void *)emu);if (emu->port)
sound/pci/emu10k1/emupcm.c +1 -2
@@ -777,8 +777,7 @@ static void snd_emu10k1_pcm_free_substre {emu10k1_pcm_t *epcm = runtime->private_data; -if (epcm) -kfree (epcm); +kfree (epcm); }static int snd_emu10k1_playback_open (snd_pcm_substream_t * substream)
sound/pci/ice1712/ak4xxx.c +1 -2
@@ -151,8 +151,7 @@ void snd_ice1712_akm4xxx_free(ice1712_treturn ;for (akidx =0 ; akidx < ice->akm_codecs; akidx++) {akm4xxx_t *ak = &ice->akm[akidx]; -if (ak->private_value[0 ]) -kfree ((void *)ak->private_value[0 ]); +kfree ((void *)ak->private_value[0 ]); }kfree (ice->akm); }
sound/pci/maestro3.c +1 -2
@@ -2374,8 +2374,7 @@ static int snd_m3_free(m3_t *chip) }#ifdef CONFIG_PM -if (chip->suspend_mem) -vfree (chip->suspend_mem); +vfree (chip->suspend_mem);#endif if (chip->irq >=0 ) {
sound/pci/trident/trident_main.c +1 -2
@@ -3675,8 +3675,7 @@ int snd_trident_free(trident_t *trident)snd_util_memhdr_free (trident->tlb.memhdr);if (trident->tlb.silent_page.area)snd_dma_free_pages (&trident->tlb.silent_page); -if (trident->tlb.shadow_entries) -vfree (trident->tlb.shadow_entries); +vfree (trident->tlb.shadow_entries);snd_dma_free_pages (&trident->tlb.buffer); }if (trident->irq >=0 )
sound/pci/ymfpci/ymfpci_main.c +2 -4
@@ -831,8 +831,7 @@ static void snd_ymfpci_pcm_free_substrea {ymfpci_pcm_t *ypcm = runtime->private_data; -if (ypcm) -kfree (ypcm); +kfree (ypcm); }static int snd_ymfpci_playback_open_1 (snd_pcm_substream_t * substream)
@@ -2065,8 +2064,7 @@ static int snd_ymfpci_free(ymfpci_t *chi#endif #ifdef CONFIG_PM -if (chip->saved_regs) -vfree (chip->saved_regs); +vfree (chip->saved_regs);#endif if (chip->mpu_res) {release_resource (chip->mpu_res);
sound/ppc/pmac.c +1 -1
@@ -71,7 +71,7 @@ static int snd_pmac_dbdma_alloc(pmac_dbdstatic void snd_pmac_dbdma_free (pmac_dbdma_t *rec) { -if (rec && rec->space) +if (rec)kfree (rec->space); }
sound/synth/emux/emux.c +2 -6
@@ -137,12 +137,8 @@ int snd_emux_free(snd_emux_t *emu)if (emu->sflist)snd_sf_free (emu->sflist); -if (emu->voices) -kfree (emu->voices); - -if (emu->name) -kfree (emu->name); - +kfree (emu->voices); +kfree (emu->name);kfree (emu);return 0 ; }
sound/synth/emux/emux_seq.c +1 -2
@@ -197,8 +197,7 @@ free_port(void *private_data)#ifdef SNDRV_EMUX_USE_RAW_EFFECT snd_emux_delete_effect (p);#endif -if (p->chset.channels) -kfree (p->chset.channels); +kfree (p->chset.channels);kfree (p); } }
sound/usb/usbaudio.c +5 -10
@@ -2063,8 +2063,7 @@ static void free_substream(snd_usb_substreturn ;/* not initialized */ list_for_each_safe (p, n, &subs->fmt_list) { struct audioformat *fp = list_entry(p, struct audioformat, list); -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp); } }
@@ -2550,8 +2549,7 @@ static int parse_audio_endpoints(snd_usb/* ok, let's parse further... */ if (parse_audio_format (dev, fp, format, fmt, stream) <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);continue ; }
@@ -2559,8 +2557,7 @@ static int parse_audio_endpoints(snd_usbsnd_printdd (KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n" , dev->devnum, iface_no, i, fp->endpoint); err =add_audio_endpoint (chip, stream, fp);if (err <0 ) { -if (fp->rate_table) -kfree (fp->rate_table); +kfree (fp->rate_table);kfree (fp);return err; }
@@ -2693,15 +2690,13 @@ static int create_fixed_stream_quirk(snd err =add_audio_endpoint (chip, stream, fp);if (err <0 ) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return err; }if (fp->iface !=get_iface_desc (&iface->altsetting[0 ])->bInterfaceNumber || fp->altset_idx >= iface->num_altsetting) {kfree (fp); -if (rate_table) -kfree (rate_table); +kfree (rate_table);return -EINVAL ; } alts = &iface->altsetting[fp->altset_idx];
sound/usb/usbmidi.c +2 -4
@@ -504,8 +504,7 @@ static snd_rawmidi_ops_t snd_usbmidi_inpstatic void snd_usbmidi_in_endpoint_delete (snd_usb_midi_in_endpoint_t * ep) {if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
@@ -632,8 +631,7 @@ static void snd_usbmidi_out_endpoint_delif (ep->tasklet.func)tasklet_kill (&ep->tasklet);if (ep->urb) { -if (ep->urb->transfer_buffer) -kfree (ep->urb->transfer_buffer); +kfree (ep->urb->transfer_buffer);usb_free_urb (ep->urb); }kfree (ep);
sound/usb/usbmixer.c +1 -1
@@ -573,7 +573,7 @@ static struct usb_feature_control_info astatic void usb_mixer_elem_free (snd_kcontrol_t *kctl) {if (kctl->private_data) { -kfree ((void *)kctl->private_data); +kfree (kctl->private_data); kctl->private_data =NULL ; } }
sound/usb/usx2y/usbusx2y.c +2 -4
@@ -285,8 +285,7 @@ static void usX2Y_unlinkSeq(snd_usX2Y_AsS ->urb[i] =NULL ; } } -if (S ->buffer) -kfree (S ->buffer); +kfree (S ->buffer); }
@@ -389,8 +388,7 @@ static struct usb_driver snd_usX2Y_usb_dstatic void snd_usX2Y_card_private_free (snd_card_t *card) { -if (usX2Y (card)->In04Buf) -kfree (usX2Y (card)->In04Buf); +kfree (usX2Y (card)->In04Buf);usb_free_urb (usX2Y (card)->In04urb);if (usX2Y (card)->us428ctls_sharedmem)snd_free_pages (usX2Y (card)->us428ctls_sharedmem,sizeof (*usX2Y (card)->us428ctls_sharedmem));
Signature · 4 lines
Marcel Sebek jabber: [email protected] ICQ: 279852819 linux user number: 307850 GPG ID: 5F88735E GPG FP: 0F01 BAB8 3148 94DB B95D 1FCA 8B63 CA06 5F88 735E
At Sun, 28 Nov 2004 10:04:07 +0100,
Quoted 28 lines · Marcel Sebek
[1 <text/plain; us-ascii (quoted-printable)>]
Quoted 18 lines · Pekka Enberg
Quoted 7 lines · Marcel Sebek
Quoted 7 lines
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +0
-0@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep);Quoted 8 lines
sound/core/init.c int snd_card_file_remove(snd_card_t *car · line 674
Quoted 8 lines
sound/core/init.c +2
-3-if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }On Sat, 2004-11-27 at 13:23 -0800, Phil Oester wrote:
Quoted 6 lines
Quoted 1 line
The above change seems to always trigger the ENOENT return, no?
No it doesn't.
kfree()does not set mfile to NULL. However, I think the above would be more readable if we did thekfree()_after_ the NULL check. Marcel, what do you think?
Quoted 5 lines
I think yes. The change I did only added one extra kfree call for (mfile == NULL) and didn't save the NULL check. So here's an updated version of the patch (and hopefully the final version :).
Signed-off-by Marcel Sebek <[email protected]>
The new patch is missing the open brace :)
Anyway, I applied your patch to ALSA tree. Thanks.
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
Quoted 15 lines · Marcel Sebek
Quoted 15 lines
diff -urpN
linux-2.6.10/sound/core/init.clinux-2.6.10-new/sound/core/init.csound/core/init.c +2
-3@@ -665,9 +665,8 @@ int snd_card_file_remove(snd_card_t *carspin_unlock (&card->files_lock);if (card->files ==NULL )wake_up (&card->shutdown_sleep); -if (mfile) { -kfree (mfile); - }else { +kfree (mfile); +if (!mfile) {snd_printk (KERN_ERR "ALSA card file remove problem (%p)\n" , file);return -ENOENT ; }
Quoted 1 line · Phil Oester
The above change seems to always trigger the ENOENT return, no?
No it doesn't. kfree() does not set mfile to NULL. However, I think the above would be more readable if we did the kfree() _after_ the NULL check. Marcel, what do you think?
Pekka
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
Quoted 11 lines · Marcel Sebek
Quoted 6 lines · Pekka Enberg
Hi,
This patch adds comments for
kfree()andvfree()stating that both accept NULL pointers. I auditedvfree()callers and there seems to be lots of confusion over this in the kernel.I've cleaned up
sound/directory from "if (x) {k/v}free(x);" and similar constructions. I'm going to to this for most of the kernel if I found some time.
Isn't 'if (x) { free(x); }' faster than the call to free() with a NULL pointer?
What about a macro ?
#define fast_free(x) if (x) { free(x); }
Or even
#define kfree(x) if (x) { _kfree(x); }
Or maybe a inline function so it doesn't break existing code. inline void kfree(x) { if (x) { _kfree(x); } }
tom
Quoted 15 lines · Tomas Carnecky
Quoted 11 lines · Marcel Sebek
Quoted 6 lines · Pekka Enberg
Hi,
This patch adds comments for
kfree()andvfree()stating that both accept NULL pointers. I auditedvfree()callers and there seems to be lots of confusion over this in the kernel.I've cleaned up
sound/directory from "if (x) {k/v}free(x);" and similar constructions. I'm going to to this for most of the kernel if I found some time.
Quoted 9 lines
Isn't 'if (x) { free(x); }' faster than the call to
free()with a NULL pointer?
What about a macro ?
#definefast_free(x)if (x) { free(x); }
Or even
#define kfree(x) if (x) {_kfree(x); }
Or maybe a inline function so it doesn't break existing code. inline void kfree(x) { if (x) {_kfree(x); } }
Well if a NULL parameter is the exceptional case, then you don't want to litter the L1 cache with the extra code that will only save a function call in rare cases.
And I think it should be the exceptional case, because it shouldn't really be used for much other than streamline error handling or cleanup functions to cope with failed allocations without adding checks everywhere. If you're doing lots of kfree(NULL) as part of normal operation, then that may suggest you aren't tracking your memory very well.
Quoted 8 lines · Tomas Carnecky
Quoted 8 lines
Isn't 'if (x) { free(x); }' faster than the call to
free()with a NULL pointer?
What about a macro ?
#definefast_free(x)if (x) { free(x); }
Or even
#define kfree(x) if (x) {_kfree(x); }
Or maybe a inline function so it doesn't break existing code. inline void kfree(x) { if (x) {_kfree(x); } }
Quoted 9 lines · Nick Piggin
Well if a NULL parameter is the exceptional case, then you don't want to litter the L1 cache with the extra code that will only save a function call in rare cases.
And I think it should be the exceptional case, because it shouldn't really be used for much other than streamline error handling or cleanup functions to cope with failed allocations without adding checks everywhere. If you're doing lots of kfree(NULL) as part of normal operation, then that may suggest you aren't tracking your memory very well.
Agreed. The drivers also use NULL for optional fields btw. Removing the redundant checks reduce the size of source and object code so we get more readable code and smaller memory footprint at the same time (yay!). Furthermore, we get rid of the _confusion_ over the use of kfree() and vfree().
Pekka
Quoted 3 lines · Pekka Enberg
This patch adds comments for
kfree()andvfree()stating that both accept NULL pointers. I auditedvfree()callers and there seems to be lots of confusion over this in the kernel.
Erm, are you sure about this? Somebody had to patch OProfile because vfree() didn't like NULL value being passed in. When did this change?
john
Quoted 3 lines · Pekka Enberg
Quoted 3 lines
This patch adds comments for
kfree()andvfree()stating that both accept NULL pointers. I auditedvfree()callers and there seems to be lots of confusion over this in the kernel.
Quoted 2 lines · John Levon
Erm, are you sure about this? Somebody had to patch OProfile because
vfree()didn't like NULL value being passed in. When did this change?
Yes, I am sure. vfree() calls __vunmap() which returns immediately if the passed pointer is NULL. I don't know when this changed.
Pekka