]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ALSA: control: Annotate snd_kcontrol with __counted_by()
authorTakashi Iwai <tiwai@suse.de>
Fri, 26 Jul 2024 15:28:15 +0000 (17:28 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 30 Jul 2024 05:45:37 +0000 (07:45 +0200)
struct snd_kcontrol contains a flex array of snd_kcontrol_volatile
objects at its end, and the array size is stored in count field.
This can be annotated gracefully with __counted_by() for catching
possible array overflows.

One additional change is the order of the count field initialization;
The assignment of the count field is moved before assignment of vd[]
elements for avoiding false-positive warnings from compilers.

Link: https://patch.msgid.link/20240726152840.8629-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/control.h
sound/core/control.c

index c1659036c4a77805376717159ace29a4503bf561..13511c50825f69bb74c1bd606ea70e5d58630ac0 100644 (file)
@@ -81,7 +81,7 @@ struct snd_kcontrol {
        unsigned long private_value;
        void *private_data;
        void (*private_free)(struct snd_kcontrol *kcontrol);
-       struct snd_kcontrol_volatile vd[];      /* volatile data */
+       struct snd_kcontrol_volatile vd[] __counted_by(count);  /* volatile data */
 };
 
 #define snd_kcontrol(n) list_entry(n, struct snd_kcontrol, list)
index f64a555f404f0af1952d583a481345e6974e6d0d..c3aad64ffbf5b0ccf86bc1ee3c903c2c0984ea33 100644 (file)
@@ -237,11 +237,11 @@ static int snd_ctl_new(struct snd_kcontrol **kctl, unsigned int count,
        if (!*kctl)
                return -ENOMEM;
 
+       (*kctl)->count = count;
        for (idx = 0; idx < count; idx++) {
                (*kctl)->vd[idx].access = access;
                (*kctl)->vd[idx].owner = file;
        }
-       (*kctl)->count = count;
 
        return 0;
 }