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

+12 -21
+12 -21
sound/core/seq/seq_ump_client.c
··· 217 217 static int seq_ump_group_init(struct seq_ump_client *client, int group_index) 218 218 { 219 219 struct seq_ump_group *group = &client->groups[group_index]; 220 - struct snd_seq_port_info *port; 220 + struct snd_seq_port_info *port __free(kfree) = NULL; 221 221 struct snd_seq_port_callback pcallbacks; 222 - int err; 223 222 224 223 port = kzalloc(sizeof(*port), GFP_KERNEL); 225 - if (!port) { 226 - err = -ENOMEM; 227 - goto error; 228 - } 224 + if (!port) 225 + return -ENOMEM; 229 226 230 227 fill_port_info(port, client, group); 231 228 port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT; ··· 235 238 pcallbacks.unuse = seq_ump_unuse; 236 239 pcallbacks.event_input = seq_ump_process_event; 237 240 port->kernel = &pcallbacks; 238 - err = snd_seq_kernel_client_ctl(client->seq_client, 239 - SNDRV_SEQ_IOCTL_CREATE_PORT, 240 - port); 241 - error: 242 - kfree(port); 243 - return err; 241 + return snd_seq_kernel_client_ctl(client->seq_client, 242 + SNDRV_SEQ_IOCTL_CREATE_PORT, 243 + port); 244 244 } 245 245 246 246 /* update the sequencer ports; called from notify_fb_change callback */ 247 247 static void update_port_infos(struct seq_ump_client *client) 248 248 { 249 - struct snd_seq_port_info *old, *new; 249 + struct snd_seq_port_info *old __free(kfree) = NULL; 250 + struct snd_seq_port_info *new __free(kfree) = NULL; 250 251 int i, err; 251 252 252 253 old = kzalloc(sizeof(*old), GFP_KERNEL); 253 254 new = kzalloc(sizeof(*new), GFP_KERNEL); 254 255 if (!old || !new) 255 - goto error; 256 + return; 256 257 257 258 for (i = 0; i < SNDRV_UMP_MAX_GROUPS; i++) { 258 259 old->addr.client = client->seq_client; ··· 259 264 SNDRV_SEQ_IOCTL_GET_PORT_INFO, 260 265 old); 261 266 if (err < 0) 262 - goto error; 267 + return; 263 268 fill_port_info(new, client, &client->groups[i]); 264 269 if (old->capability == new->capability && 265 270 !strcmp(old->name, new->name)) ··· 268 273 SNDRV_SEQ_IOCTL_SET_PORT_INFO, 269 274 new); 270 275 if (err < 0) 271 - goto error; 276 + return; 272 277 /* notify to system port */ 273 278 snd_seq_system_client_ev_port_change(client->seq_client, i); 274 279 } 275 - error: 276 - kfree(new); 277 - kfree(old); 278 280 } 279 281 280 282 /* update dir_bits and active flag for all groups in the client */ ··· 326 334 /* create a UMP Endpoint port */ 327 335 static int create_ump_endpoint_port(struct seq_ump_client *client) 328 336 { 329 - struct snd_seq_port_info *port; 337 + struct snd_seq_port_info *port __free(kfree) = NULL; 330 338 struct snd_seq_port_callback pcallbacks; 331 339 unsigned int rawmidi_info = client->ump->core.info_flags; 332 340 int err; ··· 375 383 err = snd_seq_kernel_client_ctl(client->seq_client, 376 384 SNDRV_SEQ_IOCTL_CREATE_PORT, 377 385 port); 378 - kfree(port); 379 386 return err; 380 387 } 381 388