* [PATCH] greybus: audio: Fix sparse warning.
@ 2021-05-19 4:16 Rajat Asthana
2021-05-19 10:29 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Rajat Asthana @ 2021-05-19 4:16 UTC (permalink / raw)
To: vaibhav.sr, mgreer, johan, elder, gregkh
Cc: greybus-dev, linux-staging, linux-kernel, Rajat Asthana
Enforce int type on SNDRV_CTL_ELEM_IFACE_MIXER to fix sparse warning:
> 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.
Signed-off-by: Rajat Asthana <thisisrast7@gmail.com>
---
drivers/staging/greybus/audio_topology.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 1fc7727ab7be..1e613d42d823 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -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);
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] greybus: audio: Fix sparse warning.
2021-05-19 4:16 [PATCH] greybus: audio: Fix sparse warning Rajat Asthana
@ 2021-05-19 10:29 ` Dan Carpenter
2021-05-19 13:41 ` [PATCH v2] " Rajat Asthana
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-05-19 10:29 UTC (permalink / raw)
To: Rajat Asthana
Cc: vaibhav.sr, mgreer, johan, elder, gregkh, greybus-dev,
linux-staging, linux-kernel
On Wed, May 19, 2021 at 09:46:24AM +0530, Rajat Asthana wrote:
> Enforce int type on SNDRV_CTL_ELEM_IFACE_MIXER to fix sparse warning:
> > 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] greybus: audio: Fix sparse warning.
2021-05-19 10:29 ` Dan Carpenter
@ 2021-05-19 13:41 ` Rajat Asthana
2021-05-19 13:47 ` Dan Carpenter
0 siblings, 1 reply; 4+ messages in thread
From: Rajat Asthana @ 2021-05-19 13:41 UTC (permalink / raw)
To: dan.carpenter
Cc: vaibhav.sr, mgreer, johan, elder, gregkh, greybus-dev,
linux-staging, linux-kernel, 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.
So just add a (__force int) to make the warning go away.
Signed-off-by: Rajat Asthana <thisisrast7@gmail.com>
---
Changes in v2:
- Update the commit message.
drivers/staging/greybus/audio_topology.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 1fc7727ab7be..1e613d42d823 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -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);
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] greybus: audio: Fix sparse warning.
2021-05-19 13:41 ` [PATCH v2] " Rajat Asthana
@ 2021-05-19 13:47 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-05-19 13:47 UTC (permalink / raw)
To: Rajat Asthana
Cc: vaibhav.sr, mgreer, johan, elder, gregkh, greybus-dev,
linux-staging, linux-kernel
On Wed, May 19, 2021 at 07:11:19PM +0530, Rajat Asthana wrote:
> 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.
>
> Signed-off-by: Rajat Asthana <thisisrast7@gmail.com>
> ---
> Changes in v2:
> - Update the commit message.
Thanks!
Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-05-19 13:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 4:16 [PATCH] greybus: audio: Fix sparse warning Rajat Asthana
2021-05-19 10:29 ` Dan Carpenter
2021-05-19 13:41 ` [PATCH v2] " Rajat Asthana
2021-05-19 13:47 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).