Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: seq: core: 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).

No functional changes, only code refactoring.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20240222111509.28390-10-tiwai@suse.de

+8 -18
+5 -7
sound/core/seq/seq_compat.c
··· 31 31 static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned int cmd, 32 32 struct snd_seq_port_info32 __user *data32) 33 33 { 34 - int err = -EFAULT; 35 - struct snd_seq_port_info *data; 34 + struct snd_seq_port_info *data __free(kfree) = NULL; 35 + int err; 36 36 37 37 data = kmalloc(sizeof(*data), GFP_KERNEL); 38 38 if (!data) ··· 41 41 if (copy_from_user(data, data32, sizeof(*data32)) || 42 42 get_user(data->flags, &data32->flags) || 43 43 get_user(data->time_queue, &data32->time_queue)) 44 - goto error; 44 + return -EFAULT; 45 45 data->kernel = NULL; 46 46 47 47 err = snd_seq_kernel_client_ctl(client->number, cmd, data); 48 48 if (err < 0) 49 - goto error; 49 + return err; 50 50 51 51 if (copy_to_user(data32, data, sizeof(*data32)) || 52 52 put_user(data->flags, &data32->flags) || 53 53 put_user(data->time_queue, &data32->time_queue)) 54 - err = -EFAULT; 54 + return -EFAULT; 55 55 56 - error: 57 - kfree(data); 58 56 return err; 59 57 } 60 58
+3 -11
sound/core/seq/seq_midi.c
··· 270 270 struct snd_seq_device *dev = to_seq_dev(_dev); 271 271 struct seq_midisynth_client *client; 272 272 struct seq_midisynth *msynth, *ms; 273 - struct snd_seq_port_info *port; 274 - struct snd_rawmidi_info *info; 273 + struct snd_seq_port_info *port __free(kfree) = NULL; 274 + struct snd_rawmidi_info *info __free(kfree) = NULL; 275 275 struct snd_rawmidi *rmidi = dev->private_data; 276 276 int newclient = 0; 277 277 unsigned int p, ports; ··· 297 297 ports = output_count; 298 298 if (ports < input_count) 299 299 ports = input_count; 300 - if (ports == 0) { 301 - kfree(info); 300 + if (ports == 0) 302 301 return -ENODEV; 303 - } 304 302 if (ports > (256 / SNDRV_RAWMIDI_DEVICES)) 305 303 ports = 256 / SNDRV_RAWMIDI_DEVICES; 306 304 ··· 309 311 client = kzalloc(sizeof(*client), GFP_KERNEL); 310 312 if (client == NULL) { 311 313 mutex_unlock(&register_mutex); 312 - kfree(info); 313 314 return -ENOMEM; 314 315 } 315 316 client->seq_client = ··· 318 321 if (client->seq_client < 0) { 319 322 kfree(client); 320 323 mutex_unlock(&register_mutex); 321 - kfree(info); 322 324 return -ENOMEM; 323 325 } 324 326 } ··· 399 403 if (newclient) 400 404 synths[card->number] = client; 401 405 mutex_unlock(&register_mutex); 402 - kfree(info); 403 - kfree(port); 404 406 return 0; /* success */ 405 407 406 408 __nomem: ··· 411 417 snd_seq_delete_kernel_client(client->seq_client); 412 418 kfree(client); 413 419 } 414 - kfree(info); 415 - kfree(port); 416 420 mutex_unlock(&register_mutex); 417 421 return -ENOMEM; 418 422 }