* [PATCH 1/2] alsaucm: Add list1 command for non-tuple lists
@ 2011-06-02 22:45 Stephen Warren
2011-06-02 22:45 ` [PATCH 2/2] alsaucm: Don't double-free empty lists Stephen Warren
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Warren @ 2011-06-02 22:45 UTC (permalink / raw)
To: tiwai, perex; +Cc: alsa-devel, broonie, Stephen Warren, lrg
snd_use_case_get_list returns lists of strings that are either:
a) A sequence of single strings
b) A sequence of pairs of strings all flattened into a single list
The current list command assumes layout (b) above, and hence prints
nothing when printing a single-entry list that's actually in layout (a).
Add a new command "list1" to dump lists in layout (a).
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
alsaucm/usecase.c | 29 +++++++++++++++++++++--------
1 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/alsaucm/usecase.c b/alsaucm/usecase.c
index 83781d0..f24e63e 100644
--- a/alsaucm/usecase.c
+++ b/alsaucm/usecase.c
@@ -63,7 +63,8 @@ enum uc_cmd {
OM_RESET,
OM_RELOAD,
OM_LISTCARDS,
- OM_LIST,
+ OM_LIST2,
+ OM_LIST1,
/* set/get */
OM_SET,
@@ -87,7 +88,8 @@ static struct cmd cmds[] = {
{ OM_RESET, 0, 1, "reset" },
{ OM_RELOAD, 0, 1, "reload" },
{ OM_LISTCARDS, 0, 0, "listcards" },
- { OM_LIST, 1, 1, "list" },
+ { OM_LIST1, 1, 1, "list1" },
+ { OM_LIST2, 1, 1, "list" },
{ OM_SET, 2, 1, "set" },
{ OM_GET, 1, 1, "get" },
{ OM_GETI, 1, 1, "geti" },
@@ -172,7 +174,7 @@ static int do_one(struct context *context, struct cmd *cmd, char **argv)
{
const char **list, *str;
long lval;
- int err, i;
+ int err, i, j, entries;
if (cmd->opencard && context->uc_mgr == NULL) {
fprintf(stderr, "%s: command '%s' requires an open card\n",
@@ -233,7 +235,17 @@ static int do_one(struct context *context, struct cmd *cmd, char **argv)
}
snd_use_case_free_list(list, err);
break;
- case OM_LIST:
+ case OM_LIST1:
+ case OM_LIST2:
+ switch (cmd->code) {
+ case OM_LIST1:
+ entries = 1;
+ break;
+ case OM_LIST2:
+ entries = 2;
+ break;
+ }
+
err = snd_use_case_get_list(context->uc_mgr,
argv[0],
&list);
@@ -246,10 +258,11 @@ static int do_one(struct context *context, struct cmd *cmd, char **argv)
}
if (err == 0)
printf(" list is empty\n");
- for (i = 0; i < err / 2; i++) {
- printf(" %i: %s\n", i, list[i*2]);
- if (list[i*2+1])
- printf(" %s\n", list[i*2+1]);
+ for (i = 0; i < err / entries; i++) {
+ printf(" %i: %s\n", i, list[i*entries]);
+ for (j = 0; j < entries - 1; j++)
+ if (list[i*entries+j+1])
+ printf(" %s\n", list[i*entries+j+1]);
}
snd_use_case_free_list(list, err);
break;
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] alsaucm: Don't double-free empty lists
2011-06-02 22:45 [PATCH 1/2] alsaucm: Add list1 command for non-tuple lists Stephen Warren
@ 2011-06-02 22:45 ` Stephen Warren
2011-06-03 9:50 ` Jaroslav Kysela
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Warren @ 2011-06-02 22:45 UTC (permalink / raw)
To: tiwai, perex; +Cc: alsa-devel, broonie, Stephen Warren, lrg
When snd_use_case_get_list (and hence also snd_use_case_card_list) returns
an empty list, alsaucm still attempts to free it. This ends up double-
freeing the returned list, or worse, freeing an invalid pointer, depending
on how snd_use_case_get_list gets implemented. Fix alsaucm to return early
on empty lists to avoid this.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
alsaucm/usecase.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/alsaucm/usecase.c b/alsaucm/usecase.c
index f24e63e..1c94680 100644
--- a/alsaucm/usecase.c
+++ b/alsaucm/usecase.c
@@ -226,8 +226,10 @@ static int do_one(struct context *context, struct cmd *cmd, char **argv)
snd_strerror(err));
return err;
}
- if (err == 0)
+ if (err == 0) {
printf(" list is empty\n");
+ return 0;
+ }
for (i = 0; i < err / 2; i++) {
printf(" %i: %s\n", i, list[i*2]);
if (list[i*2+1])
@@ -256,8 +258,10 @@ static int do_one(struct context *context, struct cmd *cmd, char **argv)
snd_strerror(err));
return err;
}
- if (err == 0)
+ if (err == 0) {
printf(" list is empty\n");
+ return 0;
+ }
for (i = 0; i < err / entries; i++) {
printf(" %i: %s\n", i, list[i*entries]);
for (j = 0; j < entries - 1; j++)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/2] alsaucm: Don't double-free empty lists
2011-06-02 22:45 ` [PATCH 2/2] alsaucm: Don't double-free empty lists Stephen Warren
@ 2011-06-03 9:50 ` Jaroslav Kysela
0 siblings, 0 replies; 3+ messages in thread
From: Jaroslav Kysela @ 2011-06-03 9:50 UTC (permalink / raw)
To: Stephen Warren; +Cc: ALSA development
Date 3.6.2011 00:45, Stephen Warren wrote:
> When snd_use_case_get_list (and hence also snd_use_case_card_list) returns
> an empty list, alsaucm still attempts to free it. This ends up double-
> freeing the returned list, or worse, freeing an invalid pointer, depending
> on how snd_use_case_get_list gets implemented. Fix alsaucm to return early
> on empty lists to avoid this.
All four UCM patches were applied to our GIT repos.
Jaroslav
--
Jaroslav Kysela <perex@perex.cz>
Linux Kernel Sound Maintainer
ALSA Project; Red Hat, Inc.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-03 9:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-02 22:45 [PATCH 1/2] alsaucm: Add list1 command for non-tuple lists Stephen Warren
2011-06-02 22:45 ` [PATCH 2/2] alsaucm: Don't double-free empty lists Stephen Warren
2011-06-03 9:50 ` Jaroslav Kysela
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.