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: oss: 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-7-tiwai@suse.de

+8 -18
+5 -10
sound/core/seq/oss/seq_oss_init.c
··· 63 63 snd_seq_oss_create_client(void) 64 64 { 65 65 int rc; 66 - struct snd_seq_port_info *port; 66 + struct snd_seq_port_info *port __free(kfree) = NULL; 67 67 struct snd_seq_port_callback port_callback; 68 68 69 69 port = kzalloc(sizeof(*port), GFP_KERNEL); 70 - if (!port) { 71 - rc = -ENOMEM; 72 - goto __error; 73 - } 70 + if (!port) 71 + return -ENOMEM; 74 72 75 73 /* create ALSA client */ 76 74 rc = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_OSS, 77 75 "OSS sequencer"); 78 76 if (rc < 0) 79 - goto __error; 77 + return rc; 80 78 81 79 system_client = rc; 82 80 ··· 102 104 subs.dest.port = system_port; 103 105 call_ctl(SNDRV_SEQ_IOCTL_SUBSCRIBE_PORT, &subs); 104 106 } 105 - rc = 0; 106 107 107 108 /* look up midi devices */ 108 109 schedule_work(&async_lookup_work); 109 110 110 - __error: 111 - kfree(port); 112 - return rc; 111 + return 0; 113 112 } 114 113 115 114
+3 -8
sound/core/seq/oss/seq_oss_midi.c
··· 64 64 int 65 65 snd_seq_oss_midi_lookup_ports(int client) 66 66 { 67 - struct snd_seq_client_info *clinfo; 68 - struct snd_seq_port_info *pinfo; 67 + struct snd_seq_client_info *clinfo __free(kfree) = NULL; 68 + struct snd_seq_port_info *pinfo __free(kfree) = NULL; 69 69 70 70 clinfo = kzalloc(sizeof(*clinfo), GFP_KERNEL); 71 71 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); 72 - if (! clinfo || ! pinfo) { 73 - kfree(clinfo); 74 - kfree(pinfo); 72 + if (!clinfo || !pinfo) 75 73 return -ENOMEM; 76 - } 77 74 clinfo->client = -1; 78 75 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT, clinfo) == 0) { 79 76 if (clinfo->client == client) ··· 80 83 while (snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_QUERY_NEXT_PORT, pinfo) == 0) 81 84 snd_seq_oss_midi_check_new_port(pinfo); 82 85 } 83 - kfree(clinfo); 84 - kfree(pinfo); 85 86 return 0; 86 87 } 87 88