From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Subject: [PATCH 9/9] ALSA: seq: core: Use automatic cleanup of kfree()
Date: Thu, 22 Feb 2024 12:15:09 +0100 [thread overview]
Message-ID: <20240222111509.28390-10-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/seq/seq_compat.c | 12 +++++-------
sound/core/seq/seq_midi.c | 14 +++-----------
2 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/sound/core/seq/seq_compat.c b/sound/core/seq/seq_compat.c
index 1e35bf086a51..643af4c1e838 100644
--- a/sound/core/seq/seq_compat.c
+++ b/sound/core/seq/seq_compat.c
@@ -31,8 +31,8 @@ struct snd_seq_port_info32 {
static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned int cmd,
struct snd_seq_port_info32 __user *data32)
{
- int err = -EFAULT;
- struct snd_seq_port_info *data;
+ struct snd_seq_port_info *data __free(kfree) = NULL;
+ int err;
data = kmalloc(sizeof(*data), GFP_KERNEL);
if (!data)
@@ -41,20 +41,18 @@ static int snd_seq_call_port_info_ioctl(struct snd_seq_client *client, unsigned
if (copy_from_user(data, data32, sizeof(*data32)) ||
get_user(data->flags, &data32->flags) ||
get_user(data->time_queue, &data32->time_queue))
- goto error;
+ return -EFAULT;
data->kernel = NULL;
err = snd_seq_kernel_client_ctl(client->number, cmd, data);
if (err < 0)
- goto error;
+ return err;
if (copy_to_user(data32, data, sizeof(*data32)) ||
put_user(data->flags, &data32->flags) ||
put_user(data->time_queue, &data32->time_queue))
- err = -EFAULT;
+ return -EFAULT;
- error:
- kfree(data);
return err;
}
diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
index 78dcb0ea1558..0594269d92ab 100644
--- a/sound/core/seq/seq_midi.c
+++ b/sound/core/seq/seq_midi.c
@@ -270,8 +270,8 @@ snd_seq_midisynth_probe(struct device *_dev)
struct snd_seq_device *dev = to_seq_dev(_dev);
struct seq_midisynth_client *client;
struct seq_midisynth *msynth, *ms;
- struct snd_seq_port_info *port;
- struct snd_rawmidi_info *info;
+ struct snd_seq_port_info *port __free(kfree) = NULL;
+ struct snd_rawmidi_info *info __free(kfree) = NULL;
struct snd_rawmidi *rmidi = dev->private_data;
int newclient = 0;
unsigned int p, ports;
@@ -297,10 +297,8 @@ snd_seq_midisynth_probe(struct device *_dev)
ports = output_count;
if (ports < input_count)
ports = input_count;
- if (ports == 0) {
- kfree(info);
+ if (ports == 0)
return -ENODEV;
- }
if (ports > (256 / SNDRV_RAWMIDI_DEVICES))
ports = 256 / SNDRV_RAWMIDI_DEVICES;
@@ -311,7 +309,6 @@ snd_seq_midisynth_probe(struct device *_dev)
client = kzalloc(sizeof(*client), GFP_KERNEL);
if (client == NULL) {
mutex_unlock(®ister_mutex);
- kfree(info);
return -ENOMEM;
}
client->seq_client =
@@ -321,7 +318,6 @@ snd_seq_midisynth_probe(struct device *_dev)
if (client->seq_client < 0) {
kfree(client);
mutex_unlock(®ister_mutex);
- kfree(info);
return -ENOMEM;
}
}
@@ -403,8 +399,6 @@ snd_seq_midisynth_probe(struct device *_dev)
if (newclient)
synths[card->number] = client;
mutex_unlock(®ister_mutex);
- kfree(info);
- kfree(port);
return 0; /* success */
__nomem:
@@ -417,8 +411,6 @@ snd_seq_midisynth_probe(struct device *_dev)
snd_seq_delete_kernel_client(client->seq_client);
kfree(client);
}
- kfree(info);
- kfree(port);
mutex_unlock(®ister_mutex);
return -ENOMEM;
}
--
2.35.3
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 ` [PATCH 4/9] ALSA: timer: " Takashi Iwai
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 ` Takashi Iwai [this message]
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-10-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