ALSA: seq: ump: 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-9-tiwai@suse.de
This commit is contained in:
parent
5d04ad53e5
commit
316e38ef77
@ -217,15 +217,12 @@ static void fill_port_info(struct snd_seq_port_info *port,
|
|||||||
static int seq_ump_group_init(struct seq_ump_client *client, int group_index)
|
static int seq_ump_group_init(struct seq_ump_client *client, int group_index)
|
||||||
{
|
{
|
||||||
struct seq_ump_group *group = &client->groups[group_index];
|
struct seq_ump_group *group = &client->groups[group_index];
|
||||||
struct snd_seq_port_info *port;
|
struct snd_seq_port_info *port __free(kfree) = NULL;
|
||||||
struct snd_seq_port_callback pcallbacks;
|
struct snd_seq_port_callback pcallbacks;
|
||||||
int err;
|
|
||||||
|
|
||||||
port = kzalloc(sizeof(*port), GFP_KERNEL);
|
port = kzalloc(sizeof(*port), GFP_KERNEL);
|
||||||
if (!port) {
|
if (!port)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
fill_port_info(port, client, group);
|
fill_port_info(port, client, group);
|
||||||
port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
|
port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
|
||||||
@ -238,24 +235,22 @@ static int seq_ump_group_init(struct seq_ump_client *client, int group_index)
|
|||||||
pcallbacks.unuse = seq_ump_unuse;
|
pcallbacks.unuse = seq_ump_unuse;
|
||||||
pcallbacks.event_input = seq_ump_process_event;
|
pcallbacks.event_input = seq_ump_process_event;
|
||||||
port->kernel = &pcallbacks;
|
port->kernel = &pcallbacks;
|
||||||
err = snd_seq_kernel_client_ctl(client->seq_client,
|
return snd_seq_kernel_client_ctl(client->seq_client,
|
||||||
SNDRV_SEQ_IOCTL_CREATE_PORT,
|
SNDRV_SEQ_IOCTL_CREATE_PORT,
|
||||||
port);
|
port);
|
||||||
error:
|
|
||||||
kfree(port);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update the sequencer ports; called from notify_fb_change callback */
|
/* update the sequencer ports; called from notify_fb_change callback */
|
||||||
static void update_port_infos(struct seq_ump_client *client)
|
static void update_port_infos(struct seq_ump_client *client)
|
||||||
{
|
{
|
||||||
struct snd_seq_port_info *old, *new;
|
struct snd_seq_port_info *old __free(kfree) = NULL;
|
||||||
|
struct snd_seq_port_info *new __free(kfree) = NULL;
|
||||||
int i, err;
|
int i, err;
|
||||||
|
|
||||||
old = kzalloc(sizeof(*old), GFP_KERNEL);
|
old = kzalloc(sizeof(*old), GFP_KERNEL);
|
||||||
new = kzalloc(sizeof(*new), GFP_KERNEL);
|
new = kzalloc(sizeof(*new), GFP_KERNEL);
|
||||||
if (!old || !new)
|
if (!old || !new)
|
||||||
goto error;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < SNDRV_UMP_MAX_GROUPS; i++) {
|
for (i = 0; i < SNDRV_UMP_MAX_GROUPS; i++) {
|
||||||
old->addr.client = client->seq_client;
|
old->addr.client = client->seq_client;
|
||||||
@ -264,7 +259,7 @@ static void update_port_infos(struct seq_ump_client *client)
|
|||||||
SNDRV_SEQ_IOCTL_GET_PORT_INFO,
|
SNDRV_SEQ_IOCTL_GET_PORT_INFO,
|
||||||
old);
|
old);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
return;
|
||||||
fill_port_info(new, client, &client->groups[i]);
|
fill_port_info(new, client, &client->groups[i]);
|
||||||
if (old->capability == new->capability &&
|
if (old->capability == new->capability &&
|
||||||
!strcmp(old->name, new->name))
|
!strcmp(old->name, new->name))
|
||||||
@ -273,13 +268,10 @@ static void update_port_infos(struct seq_ump_client *client)
|
|||||||
SNDRV_SEQ_IOCTL_SET_PORT_INFO,
|
SNDRV_SEQ_IOCTL_SET_PORT_INFO,
|
||||||
new);
|
new);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto error;
|
return;
|
||||||
/* notify to system port */
|
/* notify to system port */
|
||||||
snd_seq_system_client_ev_port_change(client->seq_client, i);
|
snd_seq_system_client_ev_port_change(client->seq_client, i);
|
||||||
}
|
}
|
||||||
error:
|
|
||||||
kfree(new);
|
|
||||||
kfree(old);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update dir_bits and active flag for all groups in the client */
|
/* update dir_bits and active flag for all groups in the client */
|
||||||
@ -334,7 +326,7 @@ static void update_group_attrs(struct seq_ump_client *client)
|
|||||||
/* create a UMP Endpoint port */
|
/* create a UMP Endpoint port */
|
||||||
static int create_ump_endpoint_port(struct seq_ump_client *client)
|
static int create_ump_endpoint_port(struct seq_ump_client *client)
|
||||||
{
|
{
|
||||||
struct snd_seq_port_info *port;
|
struct snd_seq_port_info *port __free(kfree) = NULL;
|
||||||
struct snd_seq_port_callback pcallbacks;
|
struct snd_seq_port_callback pcallbacks;
|
||||||
unsigned int rawmidi_info = client->ump->core.info_flags;
|
unsigned int rawmidi_info = client->ump->core.info_flags;
|
||||||
int err;
|
int err;
|
||||||
@ -383,7 +375,6 @@ static int create_ump_endpoint_port(struct seq_ump_client *client)
|
|||||||
err = snd_seq_kernel_client_ctl(client->seq_client,
|
err = snd_seq_kernel_client_ctl(client->seq_client,
|
||||||
SNDRV_SEQ_IOCTL_CREATE_PORT,
|
SNDRV_SEQ_IOCTL_CREATE_PORT,
|
||||||
port);
|
port);
|
||||||
kfree(port);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user