mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 18:13:41 +02:00
ALSA: hda/common: Use auto cleanup for temporary buffers
The release of temporary kmalloced buffers can be nicely handled via the standard __free(kfree). Only code refactoring, and no behavior change. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250827072916.31933-20-tiwai@suse.de
This commit is contained in:
parent
59195f13ee
commit
b0550d4c2d
|
|
@ -1858,14 +1858,14 @@ static int check_follower_present(struct hda_codec *codec,
|
||||||
/* call kctl->put with the given value(s) */
|
/* call kctl->put with the given value(s) */
|
||||||
static int put_kctl_with_value(struct snd_kcontrol *kctl, int val)
|
static int put_kctl_with_value(struct snd_kcontrol *kctl, int val)
|
||||||
{
|
{
|
||||||
struct snd_ctl_elem_value *ucontrol;
|
struct snd_ctl_elem_value *ucontrol __free(kfree) = NULL;
|
||||||
|
|
||||||
ucontrol = kzalloc(sizeof(*ucontrol), GFP_KERNEL);
|
ucontrol = kzalloc(sizeof(*ucontrol), GFP_KERNEL);
|
||||||
if (!ucontrol)
|
if (!ucontrol)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
ucontrol->value.integer.value[0] = val;
|
ucontrol->value.integer.value[0] = val;
|
||||||
ucontrol->value.integer.value[1] = val;
|
ucontrol->value.integer.value[1] = val;
|
||||||
kctl->put(kctl, ucontrol);
|
kctl->put(kctl, ucontrol);
|
||||||
kfree(ucontrol);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -299,9 +299,9 @@ static void remove_trail_spaces(char *str)
|
||||||
|
|
||||||
static int parse_hints(struct hda_codec *codec, const char *buf)
|
static int parse_hints(struct hda_codec *codec, const char *buf)
|
||||||
{
|
{
|
||||||
char *key, *val;
|
char *key __free(kfree) = NULL;
|
||||||
|
char *val;
|
||||||
struct hda_hint *hint;
|
struct hda_hint *hint;
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
buf = skip_spaces(buf);
|
buf = skip_spaces(buf);
|
||||||
if (!*buf || *buf == '#' || *buf == '\n')
|
if (!*buf || *buf == '#' || *buf == '\n')
|
||||||
|
|
@ -313,10 +313,8 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
/* extract key and val */
|
/* extract key and val */
|
||||||
val = strchr(key, '=');
|
val = strchr(key, '=');
|
||||||
if (!val) {
|
if (!val)
|
||||||
kfree(key);
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
*val++ = 0;
|
*val++ = 0;
|
||||||
val = skip_spaces(val);
|
val = skip_spaces(val);
|
||||||
remove_trail_spaces(key);
|
remove_trail_spaces(key);
|
||||||
|
|
@ -326,25 +324,18 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
|
||||||
if (hint) {
|
if (hint) {
|
||||||
/* replace */
|
/* replace */
|
||||||
kfree(hint->key);
|
kfree(hint->key);
|
||||||
hint->key = key;
|
goto replace;
|
||||||
hint->val = val;
|
|
||||||
goto unlock;
|
|
||||||
}
|
}
|
||||||
/* allocate a new hint entry */
|
/* allocate a new hint entry */
|
||||||
if (codec->hints.used >= MAX_HINTS)
|
if (codec->hints.used >= MAX_HINTS)
|
||||||
hint = NULL;
|
return -ENOMEM;
|
||||||
else
|
|
||||||
hint = snd_array_new(&codec->hints);
|
hint = snd_array_new(&codec->hints);
|
||||||
if (hint) {
|
if (!hint)
|
||||||
hint->key = key;
|
return -ENOMEM;
|
||||||
|
replace:
|
||||||
|
hint->key = no_free_ptr(key);
|
||||||
hint->val = val;
|
hint->val = val;
|
||||||
} else {
|
return 0;
|
||||||
err = -ENOMEM;
|
|
||||||
}
|
|
||||||
unlock:
|
|
||||||
if (err)
|
|
||||||
kfree(key);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t hints_store(struct device *dev,
|
static ssize_t hints_store(struct device *dev,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user