ALSA: Use automatic cleanup of kfree()
Subsystems (2)
cover ALSA: Use automatic cleanup of kfree()
Hi,
this is a series of patches for ALSA core code to use the new cleanup mechanism for temporary buffers.
Merely a cleanup using cleanup, no functional changes.
I confirmed that there is no significant resultant size grow by this, too.
Takashi
===
Takashi Iwai (9):
ALSA: pcm: Use automatic cleanup of kfree()
ALSA: control: Use automatic cleanup of kfree()
ALSA: compress_offload: Use automatic cleanup of kfree()
ALSA: timer: Use automatic cleanup of kfree()
ALSA: vmaster: Use automatic cleanup of kfree()
ALSA: seq: oss: Use automatic cleanup of kfree()
ALSA: seq: virmidi: Use automatic cleanup of kfree()
ALSA: seq: ump: Use automatic cleanup of kfree()
ALSA: seq: core: Use automatic cleanup of kfree()
sound/core/compress_offload.c | 36 ++++------- sound/core/control.c | 23 +++---- sound/core/control_compat.c | 69 ++++++++------------- sound/core/pcm.c | 4 +- sound/core/pcm_compat.c | 29 ++++----- sound/core/pcm_native.c | 99 ++++++++++++------------------- sound/core/seq/oss/seq_oss_init.c | 15 ++--- sound/core/seq/oss/seq_oss_midi.c | 11 +--- sound/core/seq/seq_compat.c | 12 ++-- sound/core/seq/seq_midi.c | 14 +---- sound/core/seq/seq_ump_client.c | 33 ++++------- sound/core/seq/seq_virmidi.c | 22 +++---- sound/core/timer.c | 13 ++-- sound/core/vmaster.c | 19 ++---- 14 files changed, 142 insertions(+), 257 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/9 ALSA: pcm: Use automatic cleanup of kfree()
There are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
A caveat is that some allocations are memdup_user() and they return an error pointer instead of NULL. Those need special cares and the value has to be cleared with no_free_ptr() at the allocation error path.
Other than that, the conversions are straightforward.
No functional changes, only code refactoring.
--- sound/core/pcm.c | 4 +- sound/core/pcm_compat.c | 29 +++++------- sound/core/pcm_native.c | 99 ++++++++++++++++------------------------- 3 files changed, 49 insertions(+), 83 deletions(-)
sound/core/pcm.c +1 -3
@@ -342,7 +342,7 @@ static const char *snd_pcm_oss_format_name(int format)static void snd_pcm_proc_info_read (struct snd_pcm_substream *substream,struct snd_info_buffer *buffer) { -struct snd_pcm_info *info; + struct snd_pcm_info *info __free(kfree) = NULL;int err;if (! substream)
@@ -355,7 +355,6 @@ static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream, err =snd_pcm_info (substream, info);if (err <0 ) {snd_iprintf (buffer,"error %d\n" , err); -kfree (info);return ; }snd_iprintf (buffer,"card: %d\n" , info->card);
@@ -369,7 +368,6 @@ static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,snd_iprintf (buffer,"subclass: %d\n" , info->dev_subclass);snd_iprintf (buffer,"subdevices_count: %d\n" , info->subdevices_count);snd_iprintf (buffer,"subdevices_avail: %d\n" , info->subdevices_avail); -kfree (info); } static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry,
sound/core/pcm_compat.c +10 -19
@@ -235,7 +235,7 @@ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream,int refine, struct snd_pcm_hw_params32 __user *data32) { - struct snd_pcm_hw_params *data; + struct snd_pcm_hw_params *data __free(kfree) = NULL;struct snd_pcm_runtime *runtime;int err;
@@ -248,34 +248,28 @@ static int snd_pcm_ioctl_hw_params_compat(struct snd_pcm_substream *substream,return -ENOMEM ;/* only fifo_size (RO from userspace) is different, so just copy all */ -if (copy_from_user (data, data32,sizeof (*data32))) { - err = -EFAULT ; - goto error; - } +if (copy_from_user (data, data32,sizeof (*data32))) +return -EFAULT ;if (refine) { err =snd_pcm_hw_refine (substream, data);if (err <0 ) - goto error; +return err; err =fixup_unreferenced_params (substream, data); }else { err =snd_pcm_hw_params (substream, data); }if (err <0 ) - goto error; +return err;if (copy_to_user (data32, data,sizeof (*data32)) || -put_user (data->fifo_size, &data32->fifo_size)) { - err = -EFAULT ; - goto error; - } +put_user (data->fifo_size, &data32->fifo_size)) +return -EFAULT ;if (! refine) {unsigned int new_boundary =recalculate_boundary (runtime);if (new_boundary) runtime->boundary = new_boundary; } - error: -kfree (data);return err; }
@@ -338,7 +332,7 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,compat_caddr_t buf;compat_caddr_t __user *bufptr;u32 frames; -void __user **bufs; + void __user **bufs __free(kfree) = NULL;int err, ch, i;if (! substream->runtime)
@@ -360,10 +354,8 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream,return -ENOMEM ;for (i =0 ; i < ch; i++) {u32 ptr; -if (get_user (ptr, bufptr)) { -kfree (bufs); +if (get_user (ptr, bufptr))return -EFAULT ; - } bufs[i] =compat_ptr (ptr); bufptr++; }
@@ -373,9 +365,8 @@ static int snd_pcm_ioctl_xfern_compat(struct snd_pcm_substream *substream, err =snd_pcm_lib_readv (substream, bufs, frames);if (err >=0 ) {if (put_user (err, &data32->result)) - err = -EFAULT ; +return -EFAULT ; } -kfree (bufs);return err; }
sound/core/pcm_native.c +38 -61
266 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH 2/9 ALSA: control: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
A caveat is that some allocations are memdup_user() and they return an error pointer instead of NULL. Those need special cares and the value has to be cleared with no_free_ptr() at the allocation error path.
Other than that, the conversions are straightforward.
No functional changes, only code refactoring.
--- sound/core/control.c | 23 +++++-------- sound/core/control_compat.c | 69 ++++++++++++++----------------------- 2 files changed, 34 insertions(+), 58 deletions(-)
sound/core/control.c +8 -15
@@ -932,7 +932,7 @@ EXPORT_SYMBOL(snd_ctl_find_id);static int snd_ctl_card_info (struct snd_card *card,struct snd_ctl_file * ctl,unsigned int cmd,void __user *arg) { -struct snd_ctl_card_info *info; + struct snd_ctl_card_info *info __free(kfree) = NULL; info =kzalloc (sizeof (*info),GFP_KERNEL );if (! info)
@@ -946,11 +946,8 @@ static int snd_ctl_card_info(struct snd_card *card, struct snd_ctl_file * ctl,strscpy (info->mixername, card->mixername,sizeof (info->mixername));strscpy (info->components, card->components,sizeof (info->components));up_read (&snd_ioctl_rwsem); -if (copy_to_user (arg, info,sizeof (struct snd_ctl_card_info ))) { -kfree (info); +if (copy_to_user (arg, info,sizeof (struct snd_ctl_card_info )))return -EFAULT ; - } -kfree (info);return 0 ; }
@@ -1339,12 +1336,10 @@ static int snd_ctl_elem_read_user(struct snd_card *card, result =snd_ctl_elem_read (card, control);if (result <0 ) - goto error; +return result;if (copy_to_user (_control, control,sizeof (*control))) - result = -EFAULT ; - error: -kfree (control); +return -EFAULT ;return result; }
@@ -1406,23 +1401,21 @@ static int snd_ctl_elem_write(struct snd_card *card, struct snd_ctl_file *file,static int snd_ctl_elem_write_user (struct snd_ctl_file *file,struct snd_ctl_elem_value __user *_control) { -struct snd_ctl_elem_value *control; + struct snd_ctl_elem_value *control __free(kfree) = NULL;struct snd_card *card;int result; control =memdup_user (_control,sizeof (*control));if (IS_ERR (control)) -return PTR_ERR (control); +return PTR_ERR (no_free_ptr (control)); card = file->card; result =snd_ctl_elem_write (card, file, control);if (result <0 ) - goto error; +return result;if (copy_to_user (_control, control,sizeof (*control))) - result = -EFAULT ; - error: -kfree (control); +return -EFAULT ;return result; }
sound/core/control_compat.c +26 -43
193 lines not on this page · raw message
Signature · 1 line
2.35.3
PATCH 3/9 ALSA: compress_offload: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
A caveat is that some allocations are memdup_user() and they return an error pointer instead of NULL. Those need special cares and the value has to be cleared with no_free_ptr() at the allocation error path.
Other than that, the conversions are straightforward.
No functional changes, only code refactoring.
--- sound/core/compress_offload.c | 36 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 23 deletions(-)
sound/core/compress_offload.c +13 -23
@@ -465,7 +465,7 @@ static int snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) { int retval; -struct snd_compr_codec_caps *caps; + struct snd_compr_codec_caps *caps __free(kfree) = NULL;if (!stream->ops->get_codec_caps)return -ENXIO ;
@@ -476,12 +476,9 @@ snd_compr_get_codec_caps(struct snd_compr_stream *stream, unsigned long arg) retval = stream->ops->get_codec_caps (stream, caps);if (retval) - goto out; +return retval;if (copy_to_user ((void __user *)arg, caps,sizeof (*caps))) - retval = -EFAULT ; - -out: -kfree (caps); +return -EFAULT ; return retval; }#endif /* !COMPR_CODEC_CAPS_OVERFLOW */
@@ -586,7 +583,7 @@ static int snd_compress_check_input(struct snd_compr_params *params)static int snd_compr_set_params (struct snd_compr_stream *stream,unsigned long arg) { -struct snd_compr_params *params; + struct snd_compr_params *params __free(kfree) = NULL;int retval;if (stream->runtime->state ==SNDRV_PCM_STATE_OPEN || stream->next_track) {
@@ -596,24 +593,22 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)*/ params =memdup_user ((void __user *)arg,sizeof (*params));if (IS_ERR (params)) -return PTR_ERR (params); +return PTR_ERR (no_free_ptr (params)); retval =snd_compress_check_input (params);if (retval) - goto out; +return retval; retval =snd_compr_allocate_buffer (stream, params); -if (retval) { - retval = -ENOMEM ; - goto out; - } +if (retval) +return -ENOMEM ; retval = stream->ops->set_params (stream, params);if (retval) - goto out; +return retval;if (stream->next_track) - goto out; +return retval; stream->metadata_set = false; stream->next_track = false;
@@ -622,15 +617,13 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg) }else {return -EPERM ; } -out: -kfree (params);return retval; }static int snd_compr_get_params (struct snd_compr_stream *stream,unsigned long arg) { -struct snd_codec *params; + struct snd_codec *params __free(kfree) = NULL;int retval;if (!stream->ops->get_params)
@@ -641,12 +634,9 @@ snd_compr_get_params(struct snd_compr_stream *stream, unsigned long arg)return -ENOMEM ; retval = stream->ops->get_params (stream, params);if (retval) - goto out; +return retval;if (copy_to_user ((char __user *)arg, params,sizeof (*params))) - retval = -EFAULT ; - -out: -kfree (params); +return -EFAULT ;return retval; }
Signature · 1 line
2.35.3
PATCH 4/9 ALSA: timer: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
No functional changes, only code refactoring.
--- sound/core/timer.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
sound/core/timer.c +5 -8
@@ -1645,7 +1645,7 @@ static int snd_timer_user_next_device(struct snd_timer_id __user *_tid)static int snd_timer_user_ginfo (struct file *file,struct snd_timer_ginfo __user *_ginfo) { -struct snd_timer_ginfo *ginfo; + struct snd_timer_ginfo *ginfo __free(kfree) = NULL;struct snd_timer_id tid;struct snd_timer *t;struct list_head *p;
@@ -1653,7 +1653,7 @@ static int snd_timer_user_ginfo(struct file *file, ginfo =memdup_user (_ginfo,sizeof (*ginfo));if (IS_ERR (ginfo)) -return PTR_ERR (ginfo); +return PTR_ERR (no_free_ptr (ginfo)); tid = ginfo->tid;memset (ginfo,0 ,sizeof (*ginfo));
@@ -1682,7 +1682,6 @@ static int snd_timer_user_ginfo(struct file *file,mutex_unlock (®ister_mutex);if (err >=0 &©_to_user (_ginfo, ginfo,sizeof (*ginfo))) err = -EFAULT ; -kfree (ginfo);return err; }
@@ -1804,9 +1803,8 @@ static int snd_timer_user_info(struct file *file, struct snd_timer_info __user *_info) {struct snd_timer_user *tu; -struct snd_timer_info *info; + struct snd_timer_info *info __free(kfree) = NULL;struct snd_timer *t; -int err =0 ; tu = file->private_data;if (!tu->timeri)
@@ -1827,9 +1825,8 @@ static int snd_timer_user_info(struct file *file, info->resolution =snd_timer_hw_resolution (t);spin_unlock_irq (&t->lock);if (copy_to_user (_info, info,sizeof (*_info))) - err = -EFAULT ; -kfree (info); -return err; +return -EFAULT ; +return 0 ; } static int snd_timer_user_params(struct file *file,
Signature · 1 line
2.35.3
PATCH 5/9 ALSA: vmaster: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
No functional changes, only code refactoring.
--- sound/core/vmaster.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
sound/core/vmaster.c +6 -13
@@ -56,7 +56,7 @@ struct link_follower {static int follower_update (struct link_follower *follower) { -struct snd_ctl_elem_value *uctl; + struct snd_ctl_elem_value *uctl __free(kfree) = NULL;int err, ch; uctl =kzalloc (sizeof (*uctl),GFP_KERNEL );
@@ -65,18 +65,16 @@ static int follower_update(struct link_follower *follower) uctl->id = follower->follower.id; err = follower->follower.get (&follower->follower, uctl);if (err <0 ) - goto error; +return err;for (ch =0 ; ch < follower->info.count; ch++) follower->vals[ch] = uctl->value.integer.value[ch]; - error: -kfree (uctl); -return err <0 ? err :0 ; +return 0 ; }/* get the follower ctl info and save the initial values */ static int follower_init (struct link_follower *follower) { -struct snd_ctl_elem_info *uinfo; + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL;int err;if (follower->info.count) {
@@ -91,22 +89,18 @@ static int follower_init(struct link_follower *follower)return -ENOMEM ; uinfo->id = follower->follower.id; err = follower->follower.info (&follower->follower, uinfo); -if (err <0 ) { -kfree (uinfo); +if (err <0 )return err; - } follower->info.type = uinfo->type; follower->info.count = uinfo->count;if (follower->info.count >2 || (follower->info.type !=SNDRV_CTL_ELEM_TYPE_INTEGER && follower->info.type !=SNDRV_CTL_ELEM_TYPE_BOOLEAN )) {pr_err ("ALSA: vmaster: invalid follower element\n" ); -kfree (uinfo);return -EINVAL ; } follower->info.min_val = uinfo->value.integer.min; follower->info.max_val = uinfo->value.integer.max; -kfree (uinfo);return follower_update (follower); }
@@ -341,7 +335,7 @@ static int master_get(struct snd_kcontrol *kcontrol,static int sync_followers (struct link_master *master,int old_val,int new_val) {struct link_follower *follower; -struct snd_ctl_elem_value *uval; + struct snd_ctl_elem_value *uval __free(kfree) = NULL; uval =kmalloc (sizeof (*uval),GFP_KERNEL );if (!uval)
@@ -353,7 +347,6 @@ static int sync_followers(struct link_master *master, int old_val, int new_val) master->val = new_val;follower_put_val (follower, uval); } -kfree (uval);return 0 ; }
Signature · 1 line
2.35.3
PATCH 6/9 ALSA: seq: oss: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
No functional changes, only code refactoring.
--- sound/core/seq/oss/seq_oss_init.c | 15 +++++---------- sound/core/seq/oss/seq_oss_midi.c | 11 +++-------- 2 files changed, 8 insertions(+), 18 deletions(-)
sound/core/seq/oss/seq_oss_init.c +5 -10
@@ -63,20 +63,18 @@ int __initsnd_seq_oss_create_client (void) {int rc; -struct snd_seq_port_info *port; + struct snd_seq_port_info *port __free(kfree) = NULL;struct snd_seq_port_callback port_callback; port =kzalloc (sizeof (*port),GFP_KERNEL ); -if (!port) { - rc = -ENOMEM ; - goto __error; - } +if (!port) +return -ENOMEM ;/* create ALSA client */ rc =snd_seq_create_kernel_client (NULL ,SNDRV_SEQ_CLIENT_OSS ,"OSS sequencer" );if (rc <0 ) - goto __error; +return rc; system_client = rc;
@@ -104,14 +102,11 @@ snd_seq_oss_create_client(void) subs.dest.port = system_port;call_ctl (SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT , &subs); } - rc =0 ;/* look up midi devices */ schedule_work (&async_lookup_work); - __error: -kfree (port); -return rc; +return 0 ; }
sound/core/seq/oss/seq_oss_midi.c +3 -8
@@ -64,16 +64,13 @@ static int send_midi_event(struct seq_oss_devinfo *dp, struct snd_seq_event *ev,int snd_seq_oss_midi_lookup_ports (int client) { -struct snd_seq_client_info *clinfo; -struct snd_seq_port_info *pinfo; + struct snd_seq_client_info *clinfo __free(kfree) = NULL; + struct snd_seq_port_info *pinfo __free(kfree) = NULL; clinfo =kzalloc (sizeof (*clinfo),GFP_KERNEL ); pinfo =kzalloc (sizeof (*pinfo),GFP_KERNEL ); -if (! clinfo || ! pinfo) { -kfree (clinfo); -kfree (pinfo); +if (!clinfo || !pinfo)return -ENOMEM ; - } clinfo->client =-1 ;while (snd_seq_kernel_client_ctl (client,SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT , clinfo) ==0 ) {if (clinfo->client == client)
@@ -83,8 +80,6 @@ snd_seq_oss_midi_lookup_ports(int client)while (snd_seq_kernel_client_ctl (client,SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT , pinfo) ==0 )snd_seq_oss_midi_check_new_port (pinfo); } -kfree (clinfo); -kfree (pinfo);return 0 ; }
Signature · 1 line
2.35.3
PATCH 7/9 ALSA: seq: virmidi: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
No functional changes, only code refactoring.
--- sound/core/seq/seq_virmidi.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
sound/core/seq/seq_virmidi.c +7 -15
@@ -363,26 +363,22 @@ static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev) {int client;struct snd_seq_port_callback pcallbacks; -struct snd_seq_port_info *pinfo; + struct snd_seq_port_info *pinfo __free(kfree) = NULL;int err;if (rdev->client >=0 )return 0 ; pinfo =kzalloc (sizeof (*pinfo),GFP_KERNEL ); -if (!pinfo) { - err = -ENOMEM ; - goto __error; - } +if (!pinfo) +return -ENOMEM ; client =snd_seq_create_kernel_client (rdev->card, rdev->device,"%s %d-%d" , rdev->rmidi->name, rdev->card->number, rdev->device); -if (client <0 ) { - err = client; - goto __error; - } +if (client <0 ) +return client; rdev->client = client;/* create a port */
@@ -410,15 +406,11 @@ static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev)if (err <0 ) {snd_seq_delete_kernel_client (client); rdev->client =-1 ; - goto __error; +return err; } rdev->port = pinfo->addr.port; - err =0 ;/* success */ - - __error: -kfree (pinfo); -return err; +return 0 ;/* success */ }
Signature · 1 line
2.35.3
PATCH 8/9 ALSA: seq: ump: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
No functional changes, only code refactoring.
--- sound/core/seq/seq_ump_client.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-)
sound/core/seq/seq_ump_client.c +12 -21
@@ -217,15 +217,12 @@ static void fill_port_info(struct snd_seq_port_info *port,static int seq_ump_group_init (struct seq_ump_client *client,int group_index) {struct seq_ump_group *group = &client->groups[group_index]; -struct snd_seq_port_info *port; + struct snd_seq_port_info *port __free(kfree) = NULL;struct snd_seq_port_callback pcallbacks; -int err; port =kzalloc (sizeof (*port),GFP_KERNEL ); -if (!port) { - err = -ENOMEM ; - goto error; - } +if (!port) +return -ENOMEM ;fill_port_info (port, client, group); port->flags =SNDRV_SEQ_PORT_FLG_GIVEN_PORT ;
@@ -238,24 +235,22 @@ static int seq_ump_group_init(struct seq_ump_client *client, int group_index) pcallbacks.unuse = seq_ump_unuse; pcallbacks.event_input = seq_ump_process_event; port->kernel = &pcallbacks; - err =snd_seq_kernel_client_ctl (client->seq_client, -SNDRV_SEQ_IOCTL_CREATE_PORT , - port); - error: -kfree (port); -return err; +return snd_seq_kernel_client_ctl (client->seq_client, +SNDRV_SEQ_IOCTL_CREATE_PORT , + port); }/* update the sequencer ports; called from notify_fb_change callback */ static void update_port_infos (struct seq_ump_client *client) { -struct snd_seq_port_info *old, *new; + struct snd_seq_port_info *old __free(kfree) = NULL; + struct snd_seq_port_info *new __free(kfree) = NULL;int i, err; old =kzalloc (sizeof (*old),GFP_KERNEL ); new =kzalloc (sizeof (*new),GFP_KERNEL );if (!old || !new) - goto error; +return ;for (i =0 ; i <SNDRV_UMP_MAX_GROUPS ; i++) { old->addr.client = client->seq_client;
@@ -264,7 +259,7 @@ static void update_port_infos(struct seq_ump_client *client)SNDRV_SEQ_IOCTL_GET_PORT_INFO , old);if (err <0 ) - goto error; +return ;fill_port_info (new, client, &client->groups[i]);if (old->capability == new->capability && !strcmp (old->name, new->name))
@@ -273,13 +268,10 @@ static void update_port_infos(struct seq_ump_client *client)SNDRV_SEQ_IOCTL_SET_PORT_INFO , new);if (err <0 ) - goto error; +return ;/* notify to system port */ snd_seq_system_client_ev_port_change (client->seq_client, i); } - error: -kfree (new); -kfree (old); }/* update dir_bits and active flag for all groups in the client */
@@ -334,7 +326,7 @@ static void update_group_attrs(struct seq_ump_client *client)/* create a UMP Endpoint port */ static int create_ump_endpoint_port (struct seq_ump_client *client) { -struct snd_seq_port_info *port; + struct snd_seq_port_info *port __free(kfree) = NULL;struct snd_seq_port_callback pcallbacks;unsigned int rawmidi_info = client->ump->core.info_flags;int err;
@@ -383,7 +375,6 @@ static int create_ump_endpoint_port(struct seq_ump_client *client) err =snd_seq_kernel_client_ctl (client->seq_client,SNDRV_SEQ_IOCTL_CREATE_PORT , port); -kfree (port);return err; }
Signature · 1 line
2.35.3
PATCH 9/9 ALSA: seq: core: Use automatic cleanup of kfree()
In reply to Takashi IwaiThere are common patterns where a temporary buffer is allocated and freed at the exit, and those can be simplified with the recent cleanup mechanism via __free(kfree).
No functional changes, only code refactoring.
--- sound/core/seq/seq_compat.c | 12 +++++------- sound/core/seq/seq_midi.c | 14 +++----------- 2 files changed, 8 insertions(+), 18 deletions(-)
sound/core/seq/seq_compat.c +5 -7
@@ -31,8 +31,8 @@ struct snd_seq_port_info32 {static int snd_seq_call_port_info_ioctl (struct snd_seq_client *client,unsigned int cmd,struct snd_seq_port_info32 __user *data32) { -int err = -EFAULT ; -struct snd_seq_port_info *data; + struct snd_seq_port_info *data __free(kfree) = NULL; +int err; data =kmalloc (sizeof (*data),GFP_KERNEL );if (!data)
@@ -41,20 +41,18 @@ static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsignedif (copy_from_user (data, data32,sizeof (*data32)) ||get_user (data->flags, &data32->flags) ||get_user (data->time_queue, &data32->time_queue)) - goto error; +return -EFAULT ; data->kernel =NULL ; err =snd_seq_kernel_client_ctl (client->number, cmd, data);if (err <0 ) - goto error; +return err;if (copy_to_user (data32, data,sizeof (*data32)) ||put_user (data->flags, &data32->flags) ||put_user (data->time_queue, &data32->time_queue)) - err = -EFAULT ; +return -EFAULT ; - error: -kfree (data);return err; }
sound/core/seq/seq_midi.c +3 -11
@@ -270,8 +270,8 @@ snd_seq_midisynth_probe(struct device *_dev)struct snd_seq_device *dev =to_seq_dev (_dev);struct seq_midisynth_client *client;struct seq_midisynth *msynth, *ms; -struct snd_seq_port_info *port; -struct snd_rawmidi_info *info; + struct snd_seq_port_info *port __free(kfree) = NULL; + struct snd_rawmidi_info *info __free(kfree) = NULL;struct snd_rawmidi *rmidi = dev->private_data;int newclient =0 ;unsigned int p, ports;
@@ -297,10 +297,8 @@ snd_seq_midisynth_probe(struct device *_dev) ports = output_count;if (ports < input_count) ports = input_count; -if (ports ==0 ) { -kfree (info); +if (ports ==0 )return -ENODEV ; - }if (ports > (256 /SNDRV_RAWMIDI_DEVICES )) ports =256 /SNDRV_RAWMIDI_DEVICES ;
@@ -311,7 +309,6 @@ snd_seq_midisynth_probe(struct device *_dev) client =kzalloc (sizeof (*client),GFP_KERNEL );if (client ==NULL ) {mutex_unlock (®ister_mutex); -kfree (info);return -ENOMEM ; } client->seq_client =
@@ -321,7 +318,6 @@ snd_seq_midisynth_probe(struct device *_dev)if (client->seq_client <0 ) {kfree (client);mutex_unlock (®ister_mutex); -kfree (info);return -ENOMEM ; } }
@@ -403,8 +399,6 @@ snd_seq_midisynth_probe(struct device *_dev)if (newclient) synths[card->number] = client;mutex_unlock (®ister_mutex); -kfree (info); -kfree (port);return 0 ;/* success */ __nomem:
@@ -417,8 +411,6 @@ snd_seq_midisynth_probe(struct device *_dev)snd_seq_delete_kernel_client (client->seq_client);kfree (client); } -kfree (info); -kfree (port);mutex_unlock (®ister_mutex);return -ENOMEM ; }
Signature · 1 line
2.35.3