2020-10-02 23:32:23

by Coiby Xu

[permalink] [raw]
Subject: [PATCH v2 1/3] staging: greybus: fix warnings about endianness detected by sparse

This patch fix the following warnings from sparse,

$ make C=2 drivers/staging/greybus/
drivers/staging/greybus/audio_module.c:222:25: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_module.c:222:25: expected restricted __le16 [usertype] data_cport
drivers/staging/greybus/audio_module.c:222:25: got unsigned short [usertype] intf_cport_id
drivers/staging/greybus/audio_topology.c:460:40: warning: restricted __le32 degrades to integer
drivers/staging/greybus/audio_topology.c:691:41: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_topology.c:691:41: expected unsigned int access
drivers/staging/greybus/audio_topology.c:691:41: got restricted __le32 [usertype] access
drivers/staging/greybus/audio_topology.c:746:44: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_topology.c:746:44: expected unsigned int
drivers/staging/greybus/audio_topology.c:746:44: got restricted __le32
drivers/staging/greybus/audio_topology.c:748:52: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_topology.c:748:52: expected unsigned int
drivers/staging/greybus/audio_topology.c:748:52: got restricted __le32
drivers/staging/greybus/audio_topology.c:802:42: warning: restricted __le32 degrades to integer
drivers/staging/greybus/audio_topology.c:805:50: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_topology.c:805:50: expected restricted __le32
drivers/staging/greybus/audio_topology.c:805:50: got unsigned int
drivers/staging/greybus/audio_topology.c:814:50: warning: restricted __le32 degrades to integer
drivers/staging/greybus/audio_topology.c:817:58: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_topology.c:817:58: expected restricted __le32
drivers/staging/greybus/audio_topology.c:817:58: got unsigned int
drivers/staging/greybus/audio_topology.c:889:25: warning: incorrect type in assignment (different base types)
drivers/staging/greybus/audio_topology.c:889:25: expected unsigned int access
drivers/staging/greybus/audio_topology.c:889:25: got restricted __le32 [usertype] access

Suggested-by: Dan Carpenter <[email protected]>
Reviewed-by: Dan Carpenter <[email protected]>
Reviewed-by: Alex Elder <[email protected]>
Signed-off-by: Coiby Xu <[email protected]>
---
drivers/staging/greybus/audio_module.c | 6 +++---
drivers/staging/greybus/audio_topology.c | 18 +++++++++---------
2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c
index 16f60256adb2..c52c4f361b90 100644
--- a/drivers/staging/greybus/audio_module.c
+++ b/drivers/staging/greybus/audio_module.c
@@ -219,7 +219,7 @@ static int gb_audio_add_data_connection(struct gbaudio_module_info *gbmodule,

greybus_set_drvdata(bundle, gbmodule);
dai->id = 0;
- dai->data_cport = connection->intf_cport_id;
+ dai->data_cport = cpu_to_le16(connection->intf_cport_id);
dai->connection = connection;
list_add(&dai->list, &gbmodule->data_list);

@@ -329,7 +329,7 @@ static int gb_audio_probe(struct gb_bundle *bundle,
if (ret) {
dev_err(dev,
"%d:Error while enabling %d:data connection\n",
- ret, dai->data_cport);
+ ret, le16_to_cpu(dai->data_cport));
goto disable_data_connection;
}
}
@@ -451,7 +451,7 @@ static int gb_audio_resume(struct device *dev)
if (ret) {
dev_err(dev,
"%d:Error while enabling %d:data connection\n",
- ret, dai->data_cport);
+ ret, le16_to_cpu(dai->data_cport));
return ret;
}
}
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 83b38ae8908c..2091031659de 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -466,7 +466,7 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
goto exit;

/* update ucontrol */
- if (gbvalue.value.integer_value[0] != val) {
+ if (le32_to_cpu(gbvalue.value.integer_value[0]) != val) {
for (wi = 0; wi < wlist->num_widgets; wi++) {
widget = wlist->widgets[wi];
snd_soc_dapm_mixer_update_power(widget->dapm, kcontrol,
@@ -689,7 +689,7 @@ static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info *gb,
return -ENOMEM;
ctldata->ctl_id = ctl->id;
ctldata->data_cport = le16_to_cpu(ctl->data_cport);
- ctldata->access = ctl->access;
+ ctldata->access = le32_to_cpu(ctl->access);
ctldata->vcount = ctl->count_values;
ctldata->info = &ctl->info;
*kctl = (struct snd_kcontrol_new)
@@ -744,10 +744,10 @@ static int gbcodec_enum_dapm_ctl_get(struct snd_kcontrol *kcontrol,
return ret;
}

- ucontrol->value.enumerated.item[0] = gbvalue.value.enumerated_item[0];
+ ucontrol->value.enumerated.item[0] = le32_to_cpu(gbvalue.value.enumerated_item[0]);
if (e->shift_l != e->shift_r)
ucontrol->value.enumerated.item[1] =
- gbvalue.value.enumerated_item[1];
+ le32_to_cpu(gbvalue.value.enumerated_item[1]);

return 0;
}
@@ -800,11 +800,11 @@ static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol *kcontrol,
val = mux << e->shift_l;
mask = e->mask << e->shift_l;

- if (gbvalue.value.enumerated_item[0] !=
+ if (le32_to_cpu(gbvalue.value.enumerated_item[0]) !=
ucontrol->value.enumerated.item[0]) {
change = 1;
gbvalue.value.enumerated_item[0] =
- ucontrol->value.enumerated.item[0];
+ cpu_to_le32(ucontrol->value.enumerated.item[0]);
}

if (e->shift_l != e->shift_r) {
@@ -812,11 +812,11 @@ static int gbcodec_enum_dapm_ctl_put(struct snd_kcontrol *kcontrol,
return -EINVAL;
val |= ucontrol->value.enumerated.item[1] << e->shift_r;
mask |= e->mask << e->shift_r;
- if (gbvalue.value.enumerated_item[1] !=
+ if (le32_to_cpu(gbvalue.value.enumerated_item[1]) !=
ucontrol->value.enumerated.item[1]) {
change = 1;
gbvalue.value.enumerated_item[1] =
- ucontrol->value.enumerated.item[1];
+ cpu_to_le32(ucontrol->value.enumerated.item[1]);
}
}

@@ -887,7 +887,7 @@ static int gbaudio_tplg_create_mixer_ctl(struct gbaudio_module_info *gb,
return -ENOMEM;
ctldata->ctl_id = ctl->id;
ctldata->data_cport = le16_to_cpu(ctl->data_cport);
- ctldata->access = ctl->access;
+ ctldata->access = le32_to_cpu(ctl->access);
ctldata->vcount = ctl->count_values;
ctldata->info = &ctl->info;
*kctl = (struct snd_kcontrol_new)
--
2.28.0


2020-10-02 23:32:35

by Coiby Xu

[permalink] [raw]
Subject: [PATCH v2 2/3] staging: greybus: codecs: use SNDRV_PCM_FMTBIT_S16_LE for format bitmask

snd_soc_pcm_stream.formats should use the bitmask SNDRV_PCM_FMTBIT_*
instead of the sequential integers SNDRV_PCM_FORMAT_* as explained by
commit e712bfca1ac1f63f622f87c2f33b57608f2a4d19
("ASoC: codecs: use SNDRV_PCM_FMTBIT_* for format bitmask").

Found by sparse,

$ make C=2 drivers/staging/greybus/
drivers/staging/greybus/audio_codec.c:691:36: warning: incorrect type in initializer (different base types)
drivers/staging/greybus/audio_codec.c:691:36: expected unsigned long long [usertype] formats
drivers/staging/greybus/audio_codec.c:691:36: got restricted snd_pcm_format_t [usertype]
drivers/staging/greybus/audio_codec.c:701:36: warning: incorrect type in initializer (different base types)
drivers/staging/greybus/audio_codec.c:701:36: expected unsigned long long [usertype] formats
drivers/staging/greybus/audio_codec.c:701:36: got restricted snd_pcm_format_t [usertype]

Reviewed-by: Alex Elder <[email protected]>
Signed-off-by: Coiby Xu <[email protected]>
---
drivers/staging/greybus/audio_codec.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index 74538f8c5fa4..494aa823e998 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -688,7 +688,7 @@ static struct snd_soc_dai_driver gbaudio_dai[] = {
.playback = {
.stream_name = "I2S 0 Playback",
.rates = SNDRV_PCM_RATE_48000,
- .formats = SNDRV_PCM_FORMAT_S16_LE,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
.rate_max = 48000,
.rate_min = 48000,
.channels_min = 1,
@@ -698,7 +698,7 @@ static struct snd_soc_dai_driver gbaudio_dai[] = {
.capture = {
.stream_name = "I2S 0 Capture",
.rates = SNDRV_PCM_RATE_48000,
- .formats = SNDRV_PCM_FORMAT_S16_LE,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE,
.rate_max = 48000,
.rate_min = 48000,
.channels_min = 1,
--
2.28.0

2020-10-02 23:32:57

by Coiby Xu

[permalink] [raw]
Subject: [PATCH v2 3/3] staging: greybus: use __force when assigning __u8 value to snd_ctl_elem_type_t

(struct gb_audio_ctl_elem_info*)->type has the type of __u8 so there is no
concern about the byte order. __force is safe to use.

Found by sparse,

$ make C=2 drivers/staging/greybus/
drivers/staging/greybus/audio_topology.c:185:24: warning: cast to restricted snd_ctl_elem_type_t

Suggested-by: Alex Elder <[email protected]>
Signed-off-by: Coiby Xu <[email protected]>
---
drivers/staging/greybus/audio_topology.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 2091031659de..662e3e8b4b63 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -182,7 +182,7 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
/* update uinfo */
uinfo->access = data->access;
uinfo->count = data->vcount;
- uinfo->type = (snd_ctl_elem_type_t)info->type;
+ uinfo->type = (__force snd_ctl_elem_type_t)info->type;

switch (info->type) {
case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN:
--
2.28.0

2020-10-05 21:13:54

by Vaibhav Agarwal

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] staging: greybus: fix warnings about endianness detected by sparse

On Sat, Oct 3, 2020 at 5:01 AM Coiby Xu <[email protected]> wrote:
>
> This patch fix the following warnings from sparse,
>
> $ make C=2 drivers/staging/greybus/
> drivers/staging/greybus/audio_module.c:222:25: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_module.c:222:25: expected restricted __le16 [usertype] data_cport
> drivers/staging/greybus/audio_module.c:222:25: got unsigned short [usertype] intf_cport_id
> drivers/staging/greybus/audio_topology.c:460:40: warning: restricted __le32 degrades to integer
> drivers/staging/greybus/audio_topology.c:691:41: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_topology.c:691:41: expected unsigned int access
> drivers/staging/greybus/audio_topology.c:691:41: got restricted __le32 [usertype] access
> drivers/staging/greybus/audio_topology.c:746:44: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_topology.c:746:44: expected unsigned int
> drivers/staging/greybus/audio_topology.c:746:44: got restricted __le32
> drivers/staging/greybus/audio_topology.c:748:52: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_topology.c:748:52: expected unsigned int
> drivers/staging/greybus/audio_topology.c:748:52: got restricted __le32
> drivers/staging/greybus/audio_topology.c:802:42: warning: restricted __le32 degrades to integer
> drivers/staging/greybus/audio_topology.c:805:50: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_topology.c:805:50: expected restricted __le32
> drivers/staging/greybus/audio_topology.c:805:50: got unsigned int
> drivers/staging/greybus/audio_topology.c:814:50: warning: restricted __le32 degrades to integer
> drivers/staging/greybus/audio_topology.c:817:58: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_topology.c:817:58: expected restricted __le32
> drivers/staging/greybus/audio_topology.c:817:58: got unsigned int
> drivers/staging/greybus/audio_topology.c:889:25: warning: incorrect type in assignment (different base types)
> drivers/staging/greybus/audio_topology.c:889:25: expected unsigned int access
> drivers/staging/greybus/audio_topology.c:889:25: got restricted __le32 [usertype] access
>
> Suggested-by: Dan Carpenter <[email protected]>
> Reviewed-by: Dan Carpenter <[email protected]>
> Reviewed-by: Alex Elder <[email protected]>
> Signed-off-by: Coiby Xu <[email protected]>
> ---
Hi Coiby,

Thanks for sharing the patch. Sorry, I could not reply to the v1 series.
Now, I have gone through the patches. Looks good (all 3 patches).

Reviewed-by: Vaibhav Agarwal <[email protected]>

--
Thanks,

2020-10-06 04:18:32

by Coiby Xu

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] staging: greybus: fix warnings about endianness detected by sparse

On Tue, Oct 06, 2020 at 12:47:37AM +0530, Vaibhav Agarwal wrote:
>On Sat, Oct 3, 2020 at 5:01 AM Coiby Xu <[email protected]> wrote:
>>
>> This patch fix the following warnings from sparse,
>>
>> $ make C=2 drivers/staging/greybus/
>> drivers/staging/greybus/audio_module.c:222:25: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_module.c:222:25: expected restricted __le16 [usertype] data_cport
>> drivers/staging/greybus/audio_module.c:222:25: got unsigned short [usertype] intf_cport_id
>> drivers/staging/greybus/audio_topology.c:460:40: warning: restricted __le32 degrades to integer
>> drivers/staging/greybus/audio_topology.c:691:41: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_topology.c:691:41: expected unsigned int access
>> drivers/staging/greybus/audio_topology.c:691:41: got restricted __le32 [usertype] access
>> drivers/staging/greybus/audio_topology.c:746:44: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_topology.c:746:44: expected unsigned int
>> drivers/staging/greybus/audio_topology.c:746:44: got restricted __le32
>> drivers/staging/greybus/audio_topology.c:748:52: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_topology.c:748:52: expected unsigned int
>> drivers/staging/greybus/audio_topology.c:748:52: got restricted __le32
>> drivers/staging/greybus/audio_topology.c:802:42: warning: restricted __le32 degrades to integer
>> drivers/staging/greybus/audio_topology.c:805:50: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_topology.c:805:50: expected restricted __le32
>> drivers/staging/greybus/audio_topology.c:805:50: got unsigned int
>> drivers/staging/greybus/audio_topology.c:814:50: warning: restricted __le32 degrades to integer
>> drivers/staging/greybus/audio_topology.c:817:58: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_topology.c:817:58: expected restricted __le32
>> drivers/staging/greybus/audio_topology.c:817:58: got unsigned int
>> drivers/staging/greybus/audio_topology.c:889:25: warning: incorrect type in assignment (different base types)
>> drivers/staging/greybus/audio_topology.c:889:25: expected unsigned int access
>> drivers/staging/greybus/audio_topology.c:889:25: got restricted __le32 [usertype] access
>>
>> Suggested-by: Dan Carpenter <[email protected]>
>> Reviewed-by: Dan Carpenter <[email protected]>
>> Reviewed-by: Alex Elder <[email protected]>
>> Signed-off-by: Coiby Xu <[email protected]>
>> ---
>Hi Coiby,
>
>Thanks for sharing the patch. Sorry, I could not reply to the v1 series.
>Now, I have gone through the patches. Looks good (all 3 patches).
>
>Reviewed-by: Vaibhav Agarwal <[email protected]>
>
>--
>Thanks,

Hi Vaibhav,

Thank you for reviewing these patches and giving the credit!

--
Best regards,
Coiby