]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: hda: Relax __free() variable declarations
authorTakashi Iwai <tiwai@suse.de>
Tue, 16 Dec 2025 14:06:31 +0000 (15:06 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 17 Dec 2025 09:08:30 +0000 (10:08 +0100)
We used to have a variable declaration with __free() initialized with
NULL.  This was to keep the old coding style rule, but recently it's
relaxed and rather recommends to follow the new rule to declare in
place of use for __free() -- which avoids potential deadlocks or UAFs
with nested cleanups.

Although the current code has no bug, per se, let's follow the new
standard and move the declaration to the place of assignment (or
directly assign the allocated result) instead of NULL initializations.

Fixes: ee0b0f5d32fe ("ALSA: hda/generic: Use auto cleanup for temporary buffers")
Fixes: 03c5c350e38d ("ALSA: hda/realtek: Add support for new HP G12 laptops")
Fixes: b0550d4c2dd8 ("ALSA: hda/common: Use auto cleanup for temporary buffers")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20251216140634.171890-10-tiwai@suse.de
sound/hda/codecs/generic.c
sound/hda/codecs/realtek/alc269.c
sound/hda/codecs/realtek/realtek.c
sound/hda/common/codec.c
sound/hda/common/sysfs.c

index 7bcf9aef8275f9c8232bd9620006fd0bdbbcfb24..443500a3518f413fb89f5c11318edfe085b1d7e4 100644 (file)
@@ -1984,15 +1984,15 @@ static int parse_output_paths(struct hda_codec *codec)
 {
        struct hda_gen_spec *spec = codec->spec;
        struct auto_pin_cfg *cfg = &spec->autocfg;
-       struct auto_pin_cfg *best_cfg __free(kfree) = NULL;
        unsigned int val;
        int best_badness = INT_MAX;
        int badness;
        bool fill_hardwired = true, fill_mio_first = true;
        bool best_wired = true, best_mio = true;
        bool hp_spk_swapped = false;
+       struct auto_pin_cfg *best_cfg __free(kfree) =
+               kmalloc(sizeof(*best_cfg), GFP_KERNEL);
 
-       best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
        if (!best_cfg)
                return -ENOMEM;
        *best_cfg = *cfg;
index c8a9b9b15cb49fee3531fd634bbab3393954b85d..85e7b5d4c496ea59401a75716de0c019eb6beca2 100644 (file)
@@ -2904,7 +2904,6 @@ static void find_cirrus_companion_amps(struct hda_codec *cdc)
 {
        struct device *dev = hda_codec_dev(cdc);
        struct acpi_device *adev;
-       struct fwnode_handle *fwnode __free(fwnode_handle) = NULL;
        const char *bus = NULL;
        static const struct {
                const char *hid;
@@ -2934,7 +2933,8 @@ static void find_cirrus_companion_amps(struct hda_codec *cdc)
                        bus = "spi";
        }
 
-       fwnode = fwnode_handle_get(acpi_fwnode_handle(adev));
+       struct fwnode_handle *fwnode __free(fwnode_handle) =
+               fwnode_handle_get(acpi_fwnode_handle(adev));
        acpi_dev_put(adev);
 
        if (!bus) {
index ca377a5adadb5b44cc44fede43b96d5704a5436b..efe20b450529005a6d9bed48ec50a5c7bf6dd33f 100644 (file)
@@ -215,12 +215,13 @@ void alc_update_knob_master(struct hda_codec *codec,
 {
        unsigned int val;
        struct snd_kcontrol *kctl;
-       struct snd_ctl_elem_value *uctl __free(kfree) = NULL;
 
        kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
        if (!kctl)
                return;
-       uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
+
+       struct snd_ctl_elem_value *uctl __free(kfree) =
+               kzalloc(sizeof(*uctl), GFP_KERNEL);
        if (!uctl)
                return;
        val = snd_hda_codec_read(codec, jack->nid, 0,
index c6d44168c7f9dec23e2d07d2d6d3387f8d6ba94d..ffe7c69d5a32c92329df995f12364f7182f274db 100644 (file)
@@ -1854,9 +1854,9 @@ static int check_follower_present(struct hda_codec *codec,
 /* call kctl->put with the given value(s) */
 static int put_kctl_with_value(struct snd_kcontrol *kctl, int val)
 {
-       struct snd_ctl_elem_value *ucontrol __free(kfree) = NULL;
+       struct snd_ctl_elem_value *ucontrol __free(kfree) =
+               kzalloc(sizeof(*ucontrol), GFP_KERNEL);
 
-       ucontrol = kzalloc(sizeof(*ucontrol), GFP_KERNEL);
        if (!ucontrol)
                return -ENOMEM;
        ucontrol->value.integer.value[0] = val;
index f8c8483fd5e5f3f1b04743d742dbc37a1dd2f06e..bedf10b308850b008a1f701f2baf347b5b1c41c5 100644 (file)
@@ -299,7 +299,6 @@ static void remove_trail_spaces(char *str)
 
 static int parse_hints(struct hda_codec *codec, const char *buf)
 {
-       char *key __free(kfree) = NULL;
        char *val;
        struct hda_hint *hint;
 
@@ -308,7 +307,9 @@ static int parse_hints(struct hda_codec *codec, const char *buf)
                return 0;
        if (*buf == '=')
                return -EINVAL;
-       key = kstrndup_noeol(buf, 1024);
+
+       char *key __free(kfree) =
+               kstrndup_noeol(buf, 1024);
        if (!key)
                return -ENOMEM;
        /* extract key and val */