Skip to contentSkip to conversation

greybus: audio: Fix sparse warning.

PATCH Superseded Rajat Asthana 2 participants 4 messages May 19, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 greybus: audio: Fix sparse warning.

Enforce int type on SNDRV_CTL_ELEM_IFACE_MIXER to fix sparse warning:

Quoted 1 line

warning: restricted snd_ctl_elem_iface_t degrades to integer

The iface field in the gb_audio_control struct is of type __u8, but the values stored in it are of type int. So on conversion they are degraded. Adding (__force int) will enforce them not to be degraded.

---
 drivers/staging/greybus/audio_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/greybus/audio_topology.c +2 -2
index 1fc7727ab7be..1e613d42d823 100644
@@ -676,7 +676,7 @@ static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info *gb,
 	struct gbaudio_ctl_pvt *ctldata;
 
 	switch (ctl->iface) {
-	case SNDRV_CTL_ELEM_IFACE_MIXER:
+	case (__force int)SNDRV_CTL_ELEM_IFACE_MIXER:
 		switch (ctl->info.type) {
 		case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
 			ret = gbaudio_tplg_create_enum_kctl(gb, kctl, ctl);
@@ -903,7 +903,7 @@ static int gbaudio_tplg_create_wcontrol(struct gbaudio_module_info *gb,
 	int ret;
 
 	switch (ctl->iface) {
-	case SNDRV_CTL_ELEM_IFACE_MIXER:
+	case (__force int)SNDRV_CTL_ELEM_IFACE_MIXER:
 		switch (ctl->info.type) {
 		case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
 			ret = gbaudio_tplg_create_enum_ctl(gb, kctl, ctl);
Signature · 1 line
2.31.1
#1 lore raw
Quoted 7 lines · Rajat Asthana

Enforce int type on SNDRV_CTL_ELEM_IFACE_MIXER to fix sparse warning:

Quoted 1 line

warning: restricted snd_ctl_elem_iface_t degrades to integer

The iface field in the gb_audio_control struct is of type __u8, but the values stored in it are of type int. So on conversion they are degraded. Adding (__force int) will enforce them not to be degraded.

The patch is fine, but the commit message is not very great. This patch doesn't "enforce" anything or affect the compiled code at all, it just silences a Sparse warning. Here is a better commit message.

Sparse complains that:

warning: restricted snd_ctl_elem_iface_t degrades to integer

I have looked at this code, and the code is fine as-is. Normally we would frown on using the __force directive to silence Sparse warnings but in this case it's fine. Case statements can't be made into __bitwise types. We also can't change the type of "ctl->iface" either because that is part of the user space API.

So just add a (__force int) to make the warning go away.

regards,
dan carpenter

#2 lore raw

PATCH v2 1/1 greybus: audio: Fix sparse warning.

Sparse complains that:
warning: restricted send_ctl_elem_iface_t degrades to integer.

I have looked at this code, and the code is fine as-is. Normally we would frown on using the __force directive to silence Sparse warnings but in this case it's fine. Case statements can't be made into __bitwise types. We also can't change the type of "ctl->iface" either because that is part of the user space API.

So just add a (__force int) to make the warning go away.

---
Changes in v2:
- Update the commit message.

 drivers/staging/greybus/audio_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/greybus/audio_topology.c +2 -2
index 1fc7727ab7be..1e613d42d823 100644
@@ -676,7 +676,7 @@ static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info *gb,
 	struct gbaudio_ctl_pvt *ctldata;
 
 	switch (ctl->iface) {
-	case SNDRV_CTL_ELEM_IFACE_MIXER:
+	case (__force int)SNDRV_CTL_ELEM_IFACE_MIXER:
 		switch (ctl->info.type) {
 		case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
 			ret = gbaudio_tplg_create_enum_kctl(gb, kctl, ctl);
@@ -903,7 +903,7 @@ static int gbaudio_tplg_create_wcontrol(struct gbaudio_module_info *gb,
 	int ret;
 
 	switch (ctl->iface) {
-	case SNDRV_CTL_ELEM_IFACE_MIXER:
+	case (__force int)SNDRV_CTL_ELEM_IFACE_MIXER:
 		switch (ctl->info.type) {
 		case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
 			ret = gbaudio_tplg_create_enum_ctl(gb, kctl, ctl);
Signature · 1 line
2.31.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 9 lines · Rajat Asthana

Sparse complains that:
warning: restricted send_ctl_elem_iface_t degrades to integer.

I have looked at this code, and the code is fine as-is. Normally we would frown on using the __force directive to silence Sparse warnings but in this case it's fine. Case statements can't be made into __bitwise types. We also can't change the type of "ctl->iface" either because that is part of the user space API.

Quoted 6 lines

So just add a (__force int) to make the warning go away.

---
Changes in v2:
- Update the commit message.

Thanks!

regards,
dan carpenter