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

+7 -15
+7 -15
sound/core/seq/seq_virmidi.c
··· 363 363 { 364 364 int client; 365 365 struct snd_seq_port_callback pcallbacks; 366 - struct snd_seq_port_info *pinfo; 366 + struct snd_seq_port_info *pinfo __free(kfree) = NULL; 367 367 int err; 368 368 369 369 if (rdev->client >= 0) 370 370 return 0; 371 371 372 372 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); 373 - if (!pinfo) { 374 - err = -ENOMEM; 375 - goto __error; 376 - } 373 + if (!pinfo) 374 + return -ENOMEM; 377 375 378 376 client = snd_seq_create_kernel_client(rdev->card, rdev->device, 379 377 "%s %d-%d", rdev->rmidi->name, 380 378 rdev->card->number, 381 379 rdev->device); 382 - if (client < 0) { 383 - err = client; 384 - goto __error; 385 - } 380 + if (client < 0) 381 + return client; 386 382 rdev->client = client; 387 383 388 384 /* create a port */ ··· 406 410 if (err < 0) { 407 411 snd_seq_delete_kernel_client(client); 408 412 rdev->client = -1; 409 - goto __error; 413 + return err; 410 414 } 411 415 412 416 rdev->port = pinfo->addr.port; 413 - err = 0; /* success */ 414 - 415 - __error: 416 - kfree(pinfo); 417 - return err; 417 + return 0; /* success */ 418 418 } 419 419 420 420