topology: fix some gcc warnings
cover topology: fix some gcc warnings
From: Mengdong Lin <[email protected]>
This series can fix the following gcc warnings:
-Wunused-function -Wsign-compare -Wunused-variable -Wtype-limits
Mengdong Lin (4):
topology: Remove unused function write_data_block()
topology: Change variable type to fix gcc warning
topology: Remove unused variables
topology: Fix comparison of unsigned expression < 0
src/topology/builder.c | 24 ------------------------ src/topology/channel.c | 6 ++++-- src/topology/ctl.c | 6 ++++-- src/topology/pcm.c | 9 +++------ 4 files changed, 11 insertions(+), 34 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/4 topology: Remove unused function write_data_block()
From: Mengdong Lin <[email protected]>
Fix gcc warning: 'write_data_block' defined but not used [-Wunused-function].
src/topology/builder.c +0 -24
@@ -82,30 +82,6 @@ static int write_block_header(snd_tplg_t *tplg, unsigned int type,return bytes; } -static int write_data_block (snd_tplg_t *tplg,int size,int tplg_type, -const char *obj_name,void *data) -{ -int ret; - -/* write the header for this block */ - ret =write_block_header (tplg, tplg_type,0 , - tplg->version,0 , size,1 ); -if (ret <0 ) { -SNDERR ("error: failed to write %s block %d\n" , obj_name, ret); -return ret; - } - -verbose (tplg," %s : write %d bytes\n" , obj_name, size); - - ret =write (tplg->out_fd, data, size); -if (ret <0 ) { -SNDERR ("error: failed to write %s %d\n" , obj_name, ret); -return ret; - } - -return 0 ; -} -static int write_elem_block (snd_tplg_t *tplg,struct list_head *base,int size,int tplg_type,const char *obj_name) {
Signature · 1 line
2.5.0
PATCH 2/4 topology: Change variable type to fix gcc warning
In reply to [email protected]From: Mengdong Lin <[email protected]>
Fix warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
ABI objects use type _le32, which is converted to host unsigned integer. So the iterator 'i' in a loop as below should also be unsigned. for (i = 0; i < pcm->num_streams; i++)
^
src/topology/ctl.c +4 -2
@@ -676,7 +676,8 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer,struct snd_soc_tplg_private *priv = mixer->priv;struct snd_soc_tplg_mixer_control *mc;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Mixer: %s\n" , mixer->hdr.name);
@@ -743,7 +744,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, {struct snd_soc_tplg_enum_control *ec;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Enum: %s\n" , enum_ctl->hdr.name);
src/topology/pcm.c +2 -2
@@ -522,7 +522,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)struct snd_tplg_pcm_template *pcm_tpl = t->pcm;struct snd_soc_tplg_pcm *pcm;struct tplg_elem *elem; -int i; +unsigned int i;tplg_dbg ("PCM: %s, DAI %s\n" , pcm_tpl->pcm_name, pcm_tpl->dai_name);
@@ -564,7 +564,7 @@ int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)struct snd_tplg_link_template *link = t->link;struct snd_soc_tplg_link_config *lk;struct tplg_elem *elem; -int i; +unsigned int i;if (t->type !=SND_TPLG_TYPE_BE && t->type !=SND_TPLG_TYPE_CC )return -EINVAL ;
Signature · 1 line
2.5.0
PATCH 3/4 topology: Remove unused variables
In reply to [email protected]From: Mengdong Lin <[email protected]>
Fix gcc warning when -Wunused-variable is set.
src/topology/pcm.c +1 -4
@@ -58,7 +58,6 @@ static int tplg_build_pcm_caps(snd_tplg_t *tplg, struct tplg_elem *elem)struct tplg_elem *ref_elem =NULL ;struct snd_soc_tplg_pcm *pcm;struct snd_soc_tplg_stream_caps *caps; -struct snd_soc_tplg_stream *stream;unsigned int i; pcm = elem->pcm;
@@ -273,7 +272,7 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg,struct tplg_elem *elem = private;struct snd_soc_tplg_pcm *pcm;const char *id, *value; -int err, stream; +int stream; pcm = elem->pcm;
@@ -384,7 +383,6 @@ int tplg_parse_be(snd_tplg_t *tplg,snd_config_iterator_t i, next;snd_config_t *n;const char *id, *val =NULL ; -int err; elem =tplg_elem_new_common (tplg, cfg,NULL ,SND_TPLG_TYPE_BE );if (!elem)
@@ -438,7 +436,6 @@ int tplg_parse_cc(snd_tplg_t *tplg,snd_config_iterator_t i, next;snd_config_t *n;const char *id, *val =NULL ; -int err; elem =tplg_elem_new_common (tplg, cfg,NULL ,SND_TPLG_TYPE_CC );if (!elem)
Signature · 1 line
2.5.0
PATCH 4/4 topology: Fix comparison of unsigned expression < 0
In reply to [email protected]From: Mengdong Lin <[email protected]>
Fix gcc warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
The ABI object channel->id is _le32 and is converted to host unsigned integer. It cannot be < 0.
src/topology/channel.c +4 -2
@@ -80,6 +80,7 @@ int tplg_parse_channel(snd_tplg_t *tplg,snd_config_t *n;struct snd_soc_tplg_channel *channel = private;const char *id, *value; +int channel_id;if (tplg->channel_idx >=SND_SOC_TPLG_MAX_CHAN )return -EINVAL ;
@@ -88,12 +89,13 @@ int tplg_parse_channel(snd_tplg_t *tplg,snd_config_get_id (cfg, &id);tplg_dbg ("\tChannel %s at index %d\n" , id, tplg->channel_idx); - channel->id =lookup_channel (id); -if (channel->id <0 ) { + channel_id =lookup_channel (id); +if (channel_id <0 ) {SNDERR ("error: invalid channel %s\n" , id);return -EINVAL ; } + channel->id = channel_id; channel->size =sizeof (*channel);tplg_dbg ("\tChan %s = %d\n" , id, channel->id);
Signature · 1 line
2.5.0
Re: [PATCH 2/4] topology: Change variable type to fix gcc warning
In reply to [email protected]Quoted 10 lines · On Wed, 18 Nov 2015 08:23:07 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
ABI objects use type
_le32, which is converted to host unsigned integer. So the iterator 'i' in a loop as below should also be unsigned. for (i = 0; i <pcm->num_streams; i++)^
Using an unsigned int for the generic loop count like i is strange.
Rather compare with the original value in the template, which is actually int.
Takashi
Quoted 51 lines
Signed-off-by Mengdong Lin <[email protected]>src/topology/ctl.c +4
-2@@ -676,7 +676,8 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer,struct snd_soc_tplg_private *priv = mixer->priv;struct snd_soc_tplg_mixer_control *mc;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Mixer: %s\n" , mixer->hdr.name);@@ -743,7 +744,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, {struct snd_soc_tplg_enum_control *ec;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Enum: %s\n" , enum_ctl->hdr.name);src/topology/pcm.c +2
-2@@ -522,7 +522,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)struct snd_tplg_pcm_template *pcm_tpl = t->pcm;struct snd_soc_tplg_pcm *pcm;struct tplg_elem *elem; -int i; +unsigned int i;tplg_dbg ("PCM: %s, DAI %s\n" , pcm_tpl->pcm_name, pcm_tpl->dai_name);@@ -564,7 +564,7 @@ int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)struct snd_tplg_link_template *link = t->link;struct snd_soc_tplg_link_config *lk;struct tplg_elem *elem; -int i; +unsigned int i;if (t->type !=SND_TPLG_TYPE_BE && t->type !=SND_TPLG_TYPE_CC )return -EINVAL ;Signature · 1 line
2.5.0
Re: [PATCH 2/4] topology: Change variable type to fix gcc warning
Quoted 13 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, November 18, 2015 3:16 PM
To: [email protected]Quoted 6 lines · On Wed, 18 Nov 2015 08:23:07 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
Quoted 6 lines
Quoted 4 lines
ABI objects use type
_le32, which is converted to host unsigned integer. So the iterator 'i' in a loop as below should also be unsigned. for (i = 0; i <pcm->num_streams; i++)^Using an unsigned int for the generic loop count like i is strange.
Yes.
Quoted 1 line
Rather compare with the original value in the template, which is actually int.
Are you suggesting not change the code?
The "pcm->num_streams" here is __le32 defined in ABI:
struct snd_soc_tplg_pcm {
...
__le32 num_streams; /* number of streams */
...
} __attribute__((packed));It seems gcc takes it as unsigned integer and so I get the warning.
Thanks
Mengdong
Quoted 59 lines
Takashi
src/topology/ctl.c int tplg_add_mixer(snd_tplg_t *tplg, struct
Quoted 7 lines
Signed-off-by Mengdong Lin <[email protected]>src/topology/ctl.c index renamed from src/topology/ctl.c +0
-07d8787f..6dc3b3d 100644
src/topology/ctl.c +0
-0@@ -676,7 +676,8 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct
snd_tplg_mixer_template*mixer,src/topology/pcm.c int tplg_add_pcm_object(snd_tplg_t *tplg,
Quoted 24 lines
src/topology/ctl.c +4
-2struct snd_soc_tplg_private *priv = mixer->priv;struct snd_soc_tplg_mixer_control *mc;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Mixer: %s\n" , mixer->hdr.name);@@ -743,7 +744,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, {struct snd_soc_tplg_enum_control *ec;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Enum: %s\n" , enum_ctl->hdr.name);src/topology/pcm.c index renamed from src/topology/pcm.c +0
-09b7e402..4b7c058 100644
src/topology/pcm.c +0
-0@@ -522,7 +522,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg,
snd_tplg_obj_template_t*t)src/topology/pcm.c int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
Quoted 7 lines
src/topology/pcm.c +1
-1struct snd_tplg_pcm_template *pcm_tpl = t->pcm;struct snd_soc_tplg_pcm *pcm;struct tplg_elem *elem; -int i; +unsigned int i; tplg_dbg("PCM: %s, DAI %s\n", pcm_tpl->pcm_name,
pcm_tpl->dai_name);src/topology/pcm.c int tplg_add_link_object(snd_tplg_t *tplg,
Quoted 2 lines
src/topology/pcm.c +0
-0@@ -564,7 +564,7 @@ int tplg_add_link_object(snd_tplg_t *tplg,
snd_tplg_obj_template_t*t)Quoted 11 lines
src/topology/pcm.c +1
-2struct snd_tplg_link_template *link = t->link;struct snd_soc_tplg_link_config *lk;struct tplg_elem *elem; -int i; +unsigned int i;if (t->type !=SND_TPLG_TYPE_BE && t->type !=SND_TPLG_TYPE_CC )return -EINVAL ; --2.5.0
Re: [PATCH 2/4] topology: Change variable type to fix gcc warning
Quoted 19 lines · Mengdong
Quoted 19 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, November 18, 2015 3:16 PM
To: [email protected]Quoted 10 lines · On Wed, 18 Nov 2015 08:23:07 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
ABI objects use type
_le32, which is converted to host unsigned integer. So the iterator 'i' in a loop as below should also be unsigned. for (i = 0; i <pcm->num_streams; i++)^
Quoted 7 lines
Quoted 1 line
Using an unsigned int for the generic loop count like i is strange.
Yes.
Quoted 1 line
Rather compare with the original value in the template, which is actually int.
Are you suggesting not change the code?
No.
Quoted 8 lines
The "
pcm->num_streams" here is__le32defined in ABI:struct snd_soc_tplg_pcm { ... __le32 num_streams; /* number of streams */ ... } __attribute__((packed));It seems gcc takes it as unsigned integer and so I get the warning.
The problem isn't only about the endianess.
Conceptually, it's wrong to refer directly to le32 data, as it's not being CPU endian. It should have always an endian conversion. Of course, we support only LE32, so it's no big issue, so far.
What you need to refer to is the value in the template instead. It's guaranteed to be CPU endianess, and it's even int.
So, the code would look like:
for (i = 0; i < pcm_tpl->num_streams; i++)
BTW, I haven't checked whether topology API would "work" on big-endian architecture; does it return an error properly?
Takashi
Quoted 64 lines
Thanks
MengdongQuoted 59 lines
Takashi
src/topology/ctl.c int tplg_add_mixer(snd_tplg_t *tplg, struct
Quoted 7 lines
Signed-off-by Mengdong Lin <[email protected]>src/topology/ctl.c index renamed from src/topology/ctl.c +0
-07d8787f..6dc3b3d 100644
src/topology/ctl.c +0
-0@@ -676,7 +676,8 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct
snd_tplg_mixer_template*mixer,src/topology/pcm.c int tplg_add_pcm_object(snd_tplg_t *tplg,
Quoted 24 lines
src/topology/ctl.c +4
-2struct snd_soc_tplg_private *priv = mixer->priv;struct snd_soc_tplg_mixer_control *mc;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Mixer: %s\n" , mixer->hdr.name);@@ -743,7 +744,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, {struct snd_soc_tplg_enum_control *ec;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Enum: %s\n" , enum_ctl->hdr.name);src/topology/pcm.c index renamed from src/topology/pcm.c +0
-09b7e402..4b7c058 100644
src/topology/pcm.c +0
-0@@ -522,7 +522,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg,
snd_tplg_obj_template_t*t)src/topology/pcm.c int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
Quoted 7 lines
src/topology/pcm.c +1
-1struct snd_tplg_pcm_template *pcm_tpl = t->pcm;struct snd_soc_tplg_pcm *pcm;struct tplg_elem *elem; -int i; +unsigned int i; tplg_dbg("PCM: %s, DAI %s\n", pcm_tpl->pcm_name,
pcm_tpl->dai_name);src/topology/pcm.c int tplg_add_link_object(snd_tplg_t *tplg,
Quoted 2 lines
src/topology/pcm.c +0
-0@@ -564,7 +564,7 @@ int tplg_add_link_object(snd_tplg_t *tplg,
snd_tplg_obj_template_t*t)Quoted 11 lines
src/topology/pcm.c +1
-2struct snd_tplg_link_template *link = t->link;struct snd_soc_tplg_link_config *lk;struct tplg_elem *elem; -int i; +unsigned int i;if (t->type !=SND_TPLG_TYPE_BE && t->type !=SND_TPLG_TYPE_CC )return -EINVAL ; --2.5.0
Re: [PATCH 1/4] topology: Remove unused function write_data_block()
In reply to [email protected]Quoted 7 lines · On Wed, 18 Nov 2015 08:22:59 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix gcc warning: '
write_data_block' defined but not used [-Wunused-function].Signed-off-by Mengdong Lin <[email protected]>
I thought this was kept intentionally for the future use. But it's fine to remove if you are OK, of course.
Applied now. Thanks.
Takashi
Quoted 39 lines
src/topology/builder.c +0
-24@@ -82,30 +82,6 @@ static int write_block_header(snd_tplg_t *tplg, unsigned int type,return bytes; } -static int write_data_block (snd_tplg_t *tplg,int size,int tplg_type, -const char *obj_name,void *data) -{ -int ret; - -/* write the header for this block */ - ret =write_block_header (tplg, tplg_type,0 , - tplg->version,0 , size,1 ); -if (ret <0 ) { -SNDERR ("error: failed to write %s block %d\n" , obj_name, ret); -return ret; - } - -verbose (tplg," %s : write %d bytes\n" , obj_name, size); - - ret =write (tplg->out_fd, data, size); -if (ret <0 ) { -SNDERR ("error: failed to write %s %d\n" , obj_name, ret); -return ret; - } - -return 0 ; -} -static int write_elem_block (snd_tplg_t *tplg,struct list_head *base,int size,int tplg_type,const char *obj_name) {Signature · 1 line
2.5.0
Takashi Iwai
AppliedRe: [PATCH 3/4] topology: Remove unused variables
In reply to [email protected]Quoted 6 lines · On Wed, 18 Nov 2015 08:23:19 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix gcc warning when -Wunused-variable is set.
Signed-off-by Mengdong Lin <[email protected]>
Thanks, applied.
Takashi
Quoted 41 lines
src/topology/pcm.c +1
-4@@ -58,7 +58,6 @@ static int tplg_build_pcm_caps(snd_tplg_t *tplg, struct tplg_elem *elem)struct tplg_elem *ref_elem =NULL ;struct snd_soc_tplg_pcm *pcm;struct snd_soc_tplg_stream_caps *caps; -struct snd_soc_tplg_stream *stream;unsigned int i; pcm = elem->pcm;@@ -273,7 +272,7 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg,struct tplg_elem *elem = private;struct snd_soc_tplg_pcm *pcm;const char *id, *value; -int err, stream; +int stream; pcm = elem->pcm;@@ -384,7 +383,6 @@ int tplg_parse_be(snd_tplg_t *tplg,snd_config_iterator_t i, next;snd_config_t *n;const char *id, *val =NULL ; -int err; elem =tplg_elem_new_common (tplg, cfg,NULL ,SND_TPLG_TYPE_BE );if (!elem)@@ -438,7 +436,6 @@ int tplg_parse_cc(snd_tplg_t *tplg,snd_config_iterator_t i, next;snd_config_t *n;const char *id, *val =NULL ; -int err; elem =tplg_elem_new_common (tplg, cfg,NULL ,SND_TPLG_TYPE_CC );if (!elem)Signature · 1 line
2.5.0
Takashi Iwai
AppliedRe: [PATCH 4/4] topology: Fix comparison of unsigned expression < 0
In reply to [email protected]Quoted 10 lines · On Wed, 18 Nov 2015 08:23:59 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix gcc warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
The ABI object
channel->idis_le32and is converted to host unsigned integer. It cannot be < 0.Signed-off-by Mengdong Lin <[email protected]>
Applied, thanks.
Takashi
Quoted 32 lines
src/topology/channel.c +4
-2@@ -80,6 +80,7 @@ int tplg_parse_channel(snd_tplg_t *tplg,snd_config_t *n;struct snd_soc_tplg_channel *channel = private;const char *id, *value; +int channel_id;if (tplg->channel_idx >=SND_SOC_TPLG_MAX_CHAN )return -EINVAL ;@@ -88,12 +89,13 @@ int tplg_parse_channel(snd_tplg_t *tplg,snd_config_get_id (cfg, &id);tplg_dbg ("\tChannel %s at index %d\n" , id, tplg->channel_idx); - channel->id =lookup_channel (id); -if (channel->id <0 ) { + channel_id =lookup_channel (id); +if (channel_id <0 ) {SNDERR ("error: invalid channel %s\n" , id);return -EINVAL ; } + channel->id = channel_id; channel->size =sizeof (*channel);tplg_dbg ("\tChan %s = %d\n" , id, channel->id);Signature · 1 line
2.5.0
Re: [PATCH 2/4] topology: Change variable type to fix gcc warning
In reply to Takashi IwaiQuoted 49 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, November 18, 2015 4:19 PMQuoted 19 lines · Mengdong
Quoted 19 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, November 18, 2015 3:16 PM
To: [email protected]Quoted 10 lines · On Wed, 18 Nov 2015 08:23:07 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
ABI objects use type
_le32, which is converted to host unsigned integer. So the iterator 'i' in a loop as below should also be unsigned. for (i = 0; i <pcm->num_streams; i++)^Quoted 7 lines
Quoted 1 line
Using an unsigned int for the generic loop count like i is strange.
Yes.
Quoted 1 line
Rather compare with the original value in the template, which is actually int.
Are you suggesting not change the code?
No.
Quoted 8 lines
The "
pcm->num_streams" here is__le32defined in ABI:struct snd_soc_tplg_pcm { ... __le32 num_streams; /* number of streams */ ... } __attribute__((packed));It seems gcc takes it as unsigned integer and so I get the warning.
The problem isn't only about the endianess.
Conceptually, it's wrong to refer directly to le32 data, as it's not being CPU endian. It should have always an endian conversion. Of course, we support only LE32, so it's no big issue, so far.
Quoted 6 lines
What you need to refer to is the value in the template instead. It's guaranteed to be CPU endianess, and it's even int.
So, the code would look like:for (i = 0; i < pcm_tpl->num_streams; i++)
Okay, I'll revise the patch. Thanks for your suggestion.
Quoted 2 lines
BTW, I haven't checked whether topology API would "work" on big-endian architecture; does it return an error properly?
Sorry, no. I'll check if an API can tell us the host endianness and let topology return an error for big-endian machines.
I had thought to use this API when generating the ABI objects from host type to _le32:uint32_t htole32(uint32_t host_32bits);
But since I have no big-endian machines to test this, maybe it's better to return an error for them.
Thanks
Mengdong
Quoted 68 lines
Takashi
Quoted 64 lines
Thanks
MengdongQuoted 59 lines
Takashi
src/topology/ctl.c int tplg_add_mixer(snd_tplg_t *tplg, struct
Quoted 7 lines
Signed-off-by Mengdong Lin <[email protected]>src/topology/ctl.c index renamed from src/topology/ctl.c +0
-07d8787f..6dc3b3d 100644
src/topology/ctl.c +0
-0@@ -676,7 +676,8 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct
snd_tplg_mixer_template*mixer,src/topology/pcm.c int tplg_add_pcm_object(snd_tplg_t *tplg,
Quoted 24 lines
src/topology/ctl.c +4
-2struct snd_soc_tplg_private *priv = mixer->priv;struct snd_soc_tplg_mixer_control *mc;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Mixer: %s\n" , mixer->hdr.name);@@ -743,7 +744,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl, {struct snd_soc_tplg_enum_control *ec;struct tplg_elem *elem; -int ret, i; +int ret; +unsigned int i;tplg_dbg (" Control Enum: %s\n" , enum_ctl->hdr.name);src/topology/pcm.c index renamed from src/topology/pcm.c +0
-09b7e402..4b7c058 100644
src/topology/pcm.c +0
-0@@ -522,7 +522,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg,
snd_tplg_obj_template_t*t)src/topology/pcm.c int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
Quoted 7 lines
src/topology/pcm.c +1
-1struct snd_tplg_pcm_template *pcm_tpl = t->pcm;struct snd_soc_tplg_pcm *pcm;struct tplg_elem *elem; -int i; +unsigned int i; tplg_dbg("PCM: %s, DAI %s\n", pcm_tpl->pcm_name,
pcm_tpl->dai_name);src/topology/pcm.c int tplg_add_link_object(snd_tplg_t *tplg,
Quoted 2 lines
src/topology/pcm.c +0
-0@@ -564,7 +564,7 @@ int tplg_add_link_object(snd_tplg_t *tplg,
snd_tplg_obj_template_t*t)Quoted 11 lines
src/topology/pcm.c +1
-2struct snd_tplg_link_template *link = t->link;struct snd_soc_tplg_link_config *lk;struct tplg_elem *elem; -int i; +unsigned int i;if (t->type !=SND_TPLG_TYPE_BE && t->type !=SND_TPLG_TYPE_CC )return -EINVAL ; --2.5.0
Re: [PATCH 2/4] topology: Change variable type to fix gcc warning
Quoted 58 lines · Mengdong
Quoted 50 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, November 18, 2015 4:19 PMQuoted 19 lines · Mengdong
Quoted 19 lines
-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Wednesday, November 18, 2015 3:16 PM
To: [email protected]Quoted 10 lines · On Wed, 18 Nov 2015 08:23:07 +0100, [email protected] wrote:
From: Mengdong Lin <[email protected]>
Fix warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
ABI objects use type
_le32, which is converted to host unsigned integer. So the iterator 'i' in a loop as below should also be unsigned. for (i = 0; i <pcm->num_streams; i++)^Quoted 7 lines
Quoted 1 line
Using an unsigned int for the generic loop count like i is strange.
Yes.
Quoted 1 line
Rather compare with the original value in the template, which is actually int.
Are you suggesting not change the code?
No.
Quoted 8 lines
The "
pcm->num_streams" here is__le32defined in ABI:struct snd_soc_tplg_pcm { ... __le32 num_streams; /* number of streams */ ... } __attribute__((packed));It seems gcc takes it as unsigned integer and so I get the warning.
The problem isn't only about the endianess.
Conceptually, it's wrong to refer directly to le32 data, as it's not being CPU endian. It should have always an endian conversion. Of course, we support only LE32, so it's no big issue, so far.Quoted 6 lines
What you need to refer to is the value in the template instead. It's guaranteed to be CPU endianess, and it's even int.
So, the code would look like:for (i = 0; i < pcm_tpl->num_streams; i++)Okay, I'll revise the patch. Thanks for your suggestion.
Quoted 7 lines
Quoted 2 lines
BTW, I haven't checked whether topology API would "work" on big-endian architecture; does it return an error properly?
Sorry, no. I'll check if an API can tell us the host endianness and let topology return an error for big-endian machines.
I had thought to use this API when generating the ABI objects from host type to
_le32:uint32_thtole32(uint32_t host_32bits);
Yes, that should work. But then, as I pointed out, many current codes directly refer to the converted data, and they are broken.
Quoted 1 line
But since I have no big-endian machines to test this, maybe it's better to return an error for them.
It's the easiest option, of course :)
Takashi