From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Subject: [PATCH 4/9] ALSA: timer: Use automatic cleanup of kfree()
Date: Thu, 22 Feb 2024 12:15:04 +0100 [thread overview]
Message-ID: <20240222111509.28390-5-tiwai@suse.de> (raw)
In-Reply-To: <20240222111509.28390-1-tiwai@suse.de>
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>
---
sound/core/timer.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/sound/core/timer.c b/sound/core/timer.c
index e6e551d4a29e..a595c4fb4b2a 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -1645,7 +1645,7 @@ static int snd_timer_user_next_device(struct snd_timer_id __user *_tid)
static int snd_timer_user_ginfo(struct file *file,
struct snd_timer_ginfo __user *_ginfo)
{
- struct snd_timer_ginfo *ginfo;
+ struct snd_timer_ginfo *ginfo __free(kfree) = NULL;
struct snd_timer_id tid;
struct snd_timer *t;
struct list_head *p;
@@ -1653,7 +1653,7 @@ static int snd_timer_user_ginfo(struct file *file,
ginfo = memdup_user(_ginfo, sizeof(*ginfo));
if (IS_ERR(ginfo))
- return PTR_ERR(ginfo);
+ return PTR_ERR(no_free_ptr(ginfo));
tid = ginfo->tid;
memset(ginfo, 0, sizeof(*ginfo));
@@ -1682,7 +1682,6 @@ static int snd_timer_user_ginfo(struct file *file,
mutex_unlock(®ister_mutex);
if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo)))
err = -EFAULT;
- kfree(ginfo);
return err;
}
@@ -1804,9 +1803,8 @@ static int snd_timer_user_info(struct file *file,
struct snd_timer_info __user *_info)
{
struct snd_timer_user *tu;
- struct snd_timer_info *info;
+ struct snd_timer_info *info __free(kfree) = NULL;
struct snd_timer *t;
- int err = 0;
tu = file->private_data;
if (!tu->timeri)
@@ -1827,9 +1825,8 @@ static int snd_timer_user_info(struct file *file,
info->resolution = snd_timer_hw_resolution(t);
spin_unlock_irq(&t->lock);
if (copy_to_user(_info, info, sizeof(*_info)))
- err = -EFAULT;
- kfree(info);
- return err;
+ return -EFAULT;
+ return 0;
}
static int snd_timer_user_params(struct file *file,
--
2.35.3
next prev parent reply other threads:[~2024-02-22 11:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 11:15 [PATCH 0/9] ALSA: Use automatic cleanup of kfree() Takashi Iwai
2024-02-22 11:15 ` [PATCH 1/9] ALSA: pcm: " Takashi Iwai
2024-02-22 11:15 ` [PATCH 2/9] ALSA: control: " Takashi Iwai
2024-02-22 11:15 ` [PATCH 3/9] ALSA: compress_offload: " Takashi Iwai
2024-02-22 11:15 ` Takashi Iwai [this message]
2024-02-22 11:15 ` [PATCH 5/9] ALSA: vmaster: " Takashi Iwai
2024-02-22 11:15 ` [PATCH 6/9] ALSA: seq: oss: " Takashi Iwai
2024-02-22 11:15 ` [PATCH 7/9] ALSA: seq: virmidi: " Takashi Iwai
2024-02-22 11:15 ` [PATCH 8/9] ALSA: seq: ump: " Takashi Iwai
2024-02-22 11:15 ` [PATCH 9/9] ALSA: seq: core: " Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240222111509.28390-5-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-sound@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox