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

+5 -8
+5 -8
sound/core/timer.c
··· 1645 1645 static int snd_timer_user_ginfo(struct file *file, 1646 1646 struct snd_timer_ginfo __user *_ginfo) 1647 1647 { 1648 - struct snd_timer_ginfo *ginfo; 1648 + struct snd_timer_ginfo *ginfo __free(kfree) = NULL; 1649 1649 struct snd_timer_id tid; 1650 1650 struct snd_timer *t; 1651 1651 struct list_head *p; ··· 1653 1653 1654 1654 ginfo = memdup_user(_ginfo, sizeof(*ginfo)); 1655 1655 if (IS_ERR(ginfo)) 1656 - return PTR_ERR(ginfo); 1656 + return PTR_ERR(no_free_ptr(ginfo)); 1657 1657 1658 1658 tid = ginfo->tid; 1659 1659 memset(ginfo, 0, sizeof(*ginfo)); ··· 1682 1682 mutex_unlock(&register_mutex); 1683 1683 if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo))) 1684 1684 err = -EFAULT; 1685 - kfree(ginfo); 1686 1685 return err; 1687 1686 } 1688 1687 ··· 1803 1804 struct snd_timer_info __user *_info) 1804 1805 { 1805 1806 struct snd_timer_user *tu; 1806 - struct snd_timer_info *info; 1807 + struct snd_timer_info *info __free(kfree) = NULL; 1807 1808 struct snd_timer *t; 1808 - int err = 0; 1809 1809 1810 1810 tu = file->private_data; 1811 1811 if (!tu->timeri) ··· 1825 1827 info->resolution = snd_timer_hw_resolution(t); 1826 1828 spin_unlock_irq(&t->lock); 1827 1829 if (copy_to_user(_info, info, sizeof(*_info))) 1828 - err = -EFAULT; 1829 - kfree(info); 1830 - return err; 1830 + return -EFAULT; 1831 + return 0; 1831 1832 } 1832 1833 1833 1834 static int snd_timer_user_params(struct file *file,