Skip to contentSkip to conversation

topology: fix some gcc warnings

PATCH Applied [email protected] 2 participants 4 messages Nov 19, 2015

lore
Share & tools
lore
#0 lore raw

v2 cover topology: fix some gcc warnings

From: Mengdong Lin <[email protected]>

History:
v2: Not use ABI __le32 variables but host integers (like template variables)
in the for loop;
Add check on endianess and quit on big-endian machines.

Mengdong Lin (2):
topology: Not compare a for loop iterator with ABI __le32 variables
topology: Quit and show error message on big-endian machines

 src/topology/ctl.c        | 22 +++++++++++-----------
 src/topology/parser.c     | 15 +++++++++++++++
 src/topology/pcm.c        |  4 ++--
 src/topology/tplg_local.h |  2 ++
 4 files changed, 30 insertions(+), 13 deletions(-)
Signature · 1 line
2.5.0
#2 lore raw

PATCH v2 2/2 topology: Quit and show error message on big-endian machines

From: Mengdong Lin <[email protected]>

This tool can only support little-endian machines atm. Many codes directly refer to __le32/__le64 variables of ABI objects, so will be broken on big-endian machines.

src/topology/parser.c +15 -0
index 18bb9c7..2048733 100644
@@ -371,10 +371,25 @@ void snd_tplg_verbose(snd_tplg_t *tplg, int verbose)
 	tplg->verbose = verbose;
 }
 
+static bool is_little_endian(void)
+{
+#ifdef __BYTE_ORDER
+	#if __BYTE_ORDER == __LITTLE_ENDIAN
+		return true;
+	#endif
+#endif
+	return false;
+}
+
 snd_tplg_t *snd_tplg_new(void)
 {
 	snd_tplg_t *tplg;
 
+	if (!is_little_endian()) {
+		SNDERR("error: cannot support big-endian machines\n");
+		return NULL;
+	}
+
 	tplg = calloc(1, sizeof(snd_tplg_t));
 	if (!tplg)
 		return NULL;
src/topology/tplg_local.h +2 -0
index 06cb100..e66d7f4 100644
@@ -12,6 +12,8 @@
 
 #include <limits.h>
 #include <stdint.h>
+#include <stdbool.h>
+#include <endian.h>
 #include <linux/types.h>
 
 #include "local.h"
Signature · 1 line
2.5.0
#1 lore raw

PATCH v2 1/2 topology: Not compare a for loop iterator with ABI __le32 variables

In reply to [email protected]

From: Mengdong Lin <[email protected]>

The iterator 'i' in a loop is a usually a integer. But ABI variables use type _le32, which is converted to host unsigned integer. Comparing them can cause gcc warning: comparison between signed and unsigned integer expressions[-Wsign-compare].

src/topology/ctl.c +11 -11
index 7d8787f..1c073f7 100644
@@ -676,7 +676,7 @@ 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, i, num_channels;
 
 	tplg_dbg(" Control Mixer: %s\n", mixer->hdr.name);
 
@@ -708,9 +708,10 @@ int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer,
 	for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++)
 		mc->channel[i].reg = -1;
 
-	if (mixer->map)
-		mc->num_channels = mixer->map->num_channels;
-	for (i = 0; i < mc->num_channels; i++) {
+	num_channels = mixer->map ? mixer->map->num_channels : 0;
+	mc->num_channels = num_channels;
+
+	for (i = 0; i < num_channels; i++) {
 		struct snd_tplg_channel_elem *channel = &mixer->map->channel[i];
 
 		mc->channel[i].size = channel->size;
@@ -743,7 +744,7 @@ 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, i, num_items;
 
 	tplg_dbg(" Control Enum: %s\n", enum_ctl->hdr.name);
 
@@ -765,15 +766,14 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl,
 		return ret;
 	}
 
-	ec->items = enum_ctl->items;
-	if (ec->items > SND_SOC_TPLG_NUM_TEXTS)
-		ec->items = SND_SOC_TPLG_NUM_TEXTS;
-
+	num_items =  enum_ctl->items < SND_SOC_TPLG_NUM_TEXTS ?
+		enum_ctl->items : SND_SOC_TPLG_NUM_TEXTS;
+	ec->items = num_items;
 	ec->mask = enum_ctl->mask;
 	ec->count = enum_ctl->items;
 
 	if (enum_ctl->texts != NULL) {
-		for (i = 0; i < ec->items; i++) {
+		for (i = 0; i < num_items; i++) {
 			if (enum_ctl->texts[i] != NULL)
 				strncpy(ec->texts[i], enum_ctl->texts[i],
 					SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
@@ -781,7 +781,7 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl,
 	}
 
 	if (enum_ctl->values != NULL) {
-		for (i = 0; i < ec->items; i++) {
+		for (i = 0; i < num_items; i++) {
 			if (enum_ctl->values[i])
 				continue;
 
src/topology/pcm.c +2 -2
index 8eb62e4..d75aad8 100644
@@ -550,7 +550,7 @@ int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
 	}
 
 	pcm->num_streams = pcm_tpl->num_streams;
-	for (i = 0; i < pcm->num_streams; i++)
+	for (i = 0; i < pcm_tpl->num_streams; i++)
 		tplg_add_stream_object(&pcm->stream[i], &pcm_tpl->stream[i]);
 
 	return 0;
@@ -583,7 +583,7 @@ int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t)
 	lk->id = link->id;
 	lk->num_streams = link->num_streams;
 
-	for (i = 0; i < lk->num_streams; i++)
+	for (i = 0; i < link->num_streams; i++)
 		tplg_add_stream_object(&lk->stream[i], &link->stream[i]);
 
 	return 0;
Signature · 1 line
2.5.0
Applied
#3 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, 19 Nov 2015 09:32:57 +0100, [email protected] wrote:

From: Mengdong Lin <[email protected]>

History:
v2: Not use ABI __le32 variables but host integers (like template variables)
in the for loop;
Add check on endianess and quit on big-endian machines.

Mengdong Lin (2):
topology: Not compare a for loop iterator with ABI __le32 variables
topology: Quit and show error message on big-endian machines

Applied both patches. Thanks.

Takashi

Quoted 10 lines
 src/topology/ctl.c        | 22 +++++++++++-----------
 src/topology/parser.c     | 15 +++++++++++++++
 src/topology/pcm.c        |  4 ++--
 src/topology/tplg_local.h |  2 ++
 4 files changed, 30 insertions(+), 13 deletions(-)
Signature · 1 line
2.5.0