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

+6 -13
+6 -13
sound/core/vmaster.c
··· 56 56 57 57 static int follower_update(struct link_follower *follower) 58 58 { 59 - struct snd_ctl_elem_value *uctl; 59 + struct snd_ctl_elem_value *uctl __free(kfree) = NULL; 60 60 int err, ch; 61 61 62 62 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL); ··· 65 65 uctl->id = follower->follower.id; 66 66 err = follower->follower.get(&follower->follower, uctl); 67 67 if (err < 0) 68 - goto error; 68 + return err; 69 69 for (ch = 0; ch < follower->info.count; ch++) 70 70 follower->vals[ch] = uctl->value.integer.value[ch]; 71 - error: 72 - kfree(uctl); 73 - return err < 0 ? err : 0; 71 + return 0; 74 72 } 75 73 76 74 /* get the follower ctl info and save the initial values */ 77 75 static int follower_init(struct link_follower *follower) 78 76 { 79 - struct snd_ctl_elem_info *uinfo; 77 + struct snd_ctl_elem_info *uinfo __free(kfree) = NULL; 80 78 int err; 81 79 82 80 if (follower->info.count) { ··· 89 91 return -ENOMEM; 90 92 uinfo->id = follower->follower.id; 91 93 err = follower->follower.info(&follower->follower, uinfo); 92 - if (err < 0) { 93 - kfree(uinfo); 94 + if (err < 0) 94 95 return err; 95 - } 96 96 follower->info.type = uinfo->type; 97 97 follower->info.count = uinfo->count; 98 98 if (follower->info.count > 2 || 99 99 (follower->info.type != SNDRV_CTL_ELEM_TYPE_INTEGER && 100 100 follower->info.type != SNDRV_CTL_ELEM_TYPE_BOOLEAN)) { 101 101 pr_err("ALSA: vmaster: invalid follower element\n"); 102 - kfree(uinfo); 103 102 return -EINVAL; 104 103 } 105 104 follower->info.min_val = uinfo->value.integer.min; 106 105 follower->info.max_val = uinfo->value.integer.max; 107 - kfree(uinfo); 108 106 109 107 return follower_update(follower); 110 108 } ··· 335 341 static int sync_followers(struct link_master *master, int old_val, int new_val) 336 342 { 337 343 struct link_follower *follower; 338 - struct snd_ctl_elem_value *uval; 344 + struct snd_ctl_elem_value *uval __free(kfree) = NULL; 339 345 340 346 uval = kmalloc(sizeof(*uval), GFP_KERNEL); 341 347 if (!uval) ··· 347 353 master->val = new_val; 348 354 follower_put_val(follower, uval); 349 355 } 350 - kfree(uval); 351 356 return 0; 352 357 } 353 358