ALSA: compat_ioctl: use correct snd_ctl_elem_type_t type
authorMin-Hua Chen <minhuadotchen@gmail.com>
Tue, 16 May 2023 22:38:05 +0000 (06:38 +0800)
committerTakashi Iwai <tiwai@suse.de>
Wed, 17 May 2023 15:01:51 +0000 (17:01 +0200)
SNDRV_CTL_ELEM_TYPE_* are type of snd_ctl_elem_type_t, we
have to __force cast them to int when comparing them with int
to fix the following sparse warnings.

sound/core/control_compat.c:203:14: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:205:14: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:207:14: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:209:14: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:237:21: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:238:21: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:270:21: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer
sound/core/control_compat.c:271:21: sparse: warning: restricted snd_ctl_elem_type_t degrades to integer

Signed-off-by: Min-Hua Chen <minhuadotchen@gmail.com>
Link: https://lore.kernel.org/r/20230516223806.185683-1-minhuadotchen@gmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/control_compat.c

index d8a86d1a99d6ec7860af032244b7c0501c1f35f1..9cae5d74335cab235de9caf08f28082cad410af7 100644 (file)
@@ -197,7 +197,7 @@ static int get_ctl_type(struct snd_card *card, struct snd_ctl_elem_id *id,
        return err;
 }
 
-static int get_elem_size(int type, int count)
+static int get_elem_size(snd_ctl_elem_type_t type, int count)
 {
        switch (type) {
        case SNDRV_CTL_ELEM_TYPE_INTEGER64:
@@ -234,8 +234,8 @@ static int copy_ctl_value_from_user(struct snd_card *card,
        if (type < 0)
                return type;
 
-       if (type == SNDRV_CTL_ELEM_TYPE_BOOLEAN ||
-           type == SNDRV_CTL_ELEM_TYPE_INTEGER) {
+       if (type == (__force int)SNDRV_CTL_ELEM_TYPE_BOOLEAN ||
+           type == (__force int)SNDRV_CTL_ELEM_TYPE_INTEGER) {
                for (i = 0; i < count; i++) {
                        s32 __user *intp = valuep;
                        int val;
@@ -244,7 +244,7 @@ static int copy_ctl_value_from_user(struct snd_card *card,
                        data->value.integer.value[i] = val;
                }
        } else {
-               size = get_elem_size(type, count);
+               size = get_elem_size((__force snd_ctl_elem_type_t)type, count);
                if (size < 0) {
                        dev_err(card->dev, "snd_ioctl32_ctl_elem_value: unknown type %d\n", type);
                        return -EINVAL;
@@ -267,8 +267,8 @@ static int copy_ctl_value_to_user(void __user *userdata,
        struct snd_ctl_elem_value32 __user *data32 = userdata;
        int i, size;
 
-       if (type == SNDRV_CTL_ELEM_TYPE_BOOLEAN ||
-           type == SNDRV_CTL_ELEM_TYPE_INTEGER) {
+       if (type == (__force int)SNDRV_CTL_ELEM_TYPE_BOOLEAN ||
+           type == (__force int)SNDRV_CTL_ELEM_TYPE_INTEGER) {
                for (i = 0; i < count; i++) {
                        s32 __user *intp = valuep;
                        int val;
@@ -277,7 +277,7 @@ static int copy_ctl_value_to_user(void __user *userdata,
                                return -EFAULT;
                }
        } else {
-               size = get_elem_size(type, count);
+               size = get_elem_size((__force snd_ctl_elem_type_t)type, count);
                if (copy_to_user(valuep, data->value.bytes.data, size))
                        return -EFAULT;
        }