All of lore.kernel.org
 help / color / mirror / Atom feed
* [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables
@ 2016-07-15  0:23 Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 01/29] mixer: include library local header to find layout of structures Takashi Sakamoto
                   ` (29 more replies)
  0 siblings, 30 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Hi,

A batch of this patchset is to apply the same idea to mixer feature as I
posted in this thread.
http://mailman.alsa-project.org/pipermail/alsa-devel/2016-July/110196.html

In short, replacement of alloca() with automatic variables brings us some
advantages; better execution performance and saving local storages just for
a little.

I can see below effect on my environment (Ubuntu 16.04, amd64)
$ git checkout master
$ git show HEAD
commit 33e946fdd32da2b918e88750fcfd78014ae3e079
...
$ ./gitcompile --with-plugindir=/usr/lib/x86_64-linux-gnu/alsa-lib/
...
$ ls -l src/.libs/libasound.so.2.0.0 
-rwxrwxr-x 1 mocchi mocchi 4783080  7月 15 09:08 src/.libs/libasound.so.2.0.0
$ git checkout remove-alloca-mixer
$ make
...
$ ls -l src/.libs/libasound.so.2.0.0 
-rwxrwxr-x 1 mocchi mocchi 4780152  7月 15 09:09 src/.libs/libasound.so.2.0.0
$ gcc -v
...
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1)


Takashi Sakamoto (29):
  mixer: include library local header to find layout of structures
  mixer: change code formatting for elem_read_volume()
  mixer: remove alloca() from elem_read_volume()
  mixer: change code formatting for elem_read_route()
  mixer: remove alloca() from elem_read_route()
  mixer: change code formatting for elem_read_enum()
  mixer: remove alloca() from elem_read_enum()
  mixer: change code formatting for selem_read()
  mixer: remove alloca() from selem_read()
  mixer: change code formatting for elem_write_volume()
  mixer: remove alloca() from elem_write_volume()
  mixer: change code formatting for elem_write_switch()
  mixer: remove alloca() from elem_write_switch()
  mixer: remove alloca() from elem_write_switch_constant()
  mixer: change code formatting for elem_write_enum()
  mixer: remove alloca() from elem_write_enum()
  mixer: change code formatting for elem_write_route()
  mixer: remove alloca() from elem_write_route()
  mixer: change code formatting for selem_write_main()
  mixer: remove alloca() from selem_write_main()
  mixer: change code formatting for init_db_range()
  mixer: remove alloca() from init_db_range()
  mixer: remove alloca() from enum_item_name_ops()
  mixer: remove alloca() from get_enum_item_ops()
  mixer: remove alloca() from set_enum_item_ops()
  mixer: change code formatting for simple_add1()
  mixer: remove alloca() from simple_add1()
  mixer: change code formatting for simple_event_add()
  mixer: remove alloca() from simple_event_add()

 src/mixer/simple_none.c | 208 ++++++++++++++++++++++++------------------------
 1 file changed, 106 insertions(+), 102 deletions(-)

-- 
2.7.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH 01/29] mixer: include library local header to find layout of structures
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 02/29] mixer: change code formatting for elem_read_volume() Takashi Sakamoto
                   ` (28 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Inner this library, implementation of each features can find actual layout
of structures by including local header. Although, mixer feature is written
without the header and as the same way for applications. This brings some
inefficiencies such as usage of alloca() to keep memory objects for the
structures.

This commit includes the header for further improvements in mixer
feature.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 4e55660..1d2112d 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -38,7 +38,7 @@
 #include <assert.h>
 #include <math.h>
 #include <limits.h>
-#include <alsa/asoundlib.h>
+#include "local.h"
 #include "config.h"
 #include "mixer_simple.h"
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 02/29] mixer: change code formatting for elem_read_volume()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 01/29] mixer: include library local header to find layout of structures Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 03/29] mixer: remove alloca() from elem_read_volume() Takashi Sakamoto
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 1d2112d..a90ee84 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -245,7 +245,9 @@ static int elem_read_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
 		unsigned int idx1 = idx;
 		if (idx >= c->values)
 			idx1 = 0;
-		s->str[dir].vol[idx] = to_user(s, dir, c, snd_ctl_elem_value_get_integer(ctl, idx1));
+		s->str[dir].vol[idx] =
+			to_user(s, dir, c,
+				snd_ctl_elem_value_get_integer(ctl, idx1));
 	}
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 03/29] mixer: remove alloca() from elem_read_volume()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 01/29] mixer: include library local header to find layout of structures Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 02/29] mixer: change code formatting for elem_read_volume() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 04/29] mixer: change code formatting for elem_read_route() Takashi Sakamoto
                   ` (26 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index a90ee84..0f23a06 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -234,12 +234,11 @@ static long from_user(selem_none_t *s, int dir, selem_ctl_t *c, long value)
 
 static int elem_read_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < s->str[dir].channels; idx++) {
 		unsigned int idx1 = idx;
@@ -247,25 +246,24 @@ static int elem_read_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
 			idx1 = 0;
 		s->str[dir].vol[idx] =
 			to_user(s, dir, c,
-				snd_ctl_elem_value_get_integer(ctl, idx1));
+				snd_ctl_elem_value_get_integer(&ctl, idx1));
 	}
 	return 0;
 }
 
 static int elem_read_switch(selem_none_t *s, int dir, selem_ctl_type_t type)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < s->str[dir].channels; idx++) {
 		unsigned int idx1 = idx;
 		if (idx >= c->values)
 			idx1 = 0;
-		if (!snd_ctl_elem_value_get_integer(ctl, idx1))
+		if (!snd_ctl_elem_value_get_integer(&ctl, idx1))
 			s->str[dir].sw &= ~(1 << idx);
 	}
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 04/29] mixer: change code formatting for elem_read_route()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (2 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 03/29] mixer: remove alloca() from elem_read_volume() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 05/29] mixer: remove alloca() from elem_read_route() Takashi Sakamoto
                   ` (25 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 0f23a06..65b7b7b 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -282,7 +282,8 @@ static int elem_read_route(selem_none_t *s, int dir, selem_ctl_type_t type)
 		unsigned int idx1 = idx;
 		if (idx >= c->values)
 			idx1 = 0;
-		if (!snd_ctl_elem_value_get_integer(ctl, idx1 * c->values + idx1))
+		if (!snd_ctl_elem_value_get_integer(ctl,
+						    idx1 * c->values + idx1))
 			s->str[dir].sw &= ~(1 << idx);
 	}
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 05/29] mixer: remove alloca() from elem_read_route()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (3 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 04/29] mixer: change code formatting for elem_read_route() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 06/29] mixer: change code formatting for elem_read_enum() Takashi Sakamoto
                   ` (24 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 65b7b7b..c3ce427 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -271,18 +271,17 @@ static int elem_read_switch(selem_none_t *s, int dir, selem_ctl_type_t type)
 
 static int elem_read_route(selem_none_t *s, int dir, selem_ctl_type_t type)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < s->str[dir].channels; idx++) {
 		unsigned int idx1 = idx;
 		if (idx >= c->values)
 			idx1 = 0;
-		if (!snd_ctl_elem_value_get_integer(ctl,
+		if (!snd_ctl_elem_value_get_integer(&ctl,
 						    idx1 * c->values + idx1))
 			s->str[dir].sw &= ~(1 << idx);
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 06/29] mixer: change code formatting for elem_read_enum()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (4 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 05/29] mixer: remove alloca() from elem_read_route() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 07/29] mixer: remove alloca() from elem_read_enum() Takashi Sakamoto
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index c3ce427..27b5699 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -296,7 +296,8 @@ static int elem_read_enum(selem_none_t *s)
 	int type;
 	selem_ctl_t *c;
 	type = CTL_GLOBAL_ENUM;
-	if ( (s->selem.caps & (SM_CAP_CENUM | SM_CAP_PENUM)) == (SM_CAP_CENUM | SM_CAP_PENUM) )
+	if ((s->selem.caps & (SM_CAP_CENUM | SM_CAP_PENUM)) ==
+						(SM_CAP_CENUM | SM_CAP_PENUM))
 		type = CTL_GLOBAL_ENUM;
 	else if (s->selem.caps & SM_CAP_PENUM)
 		type = CTL_PLAYBACK_ENUM;
@@ -310,7 +311,8 @@ static int elem_read_enum(selem_none_t *s)
 		unsigned int idx1 = idx;
 		if (idx >= c->values)
 			idx1 = 0;
-		s->str[0].vol[idx] = snd_ctl_elem_value_get_enumerated(ctl, idx1);
+		s->str[0].vol[idx] =
+				snd_ctl_elem_value_get_enumerated(ctl, idx1);
 	}
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 07/29] mixer: remove alloca() from elem_read_enum()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (5 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 06/29] mixer: change code formatting for elem_read_enum() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 08/29] mixer: change code formatting for selem_read() Takashi Sakamoto
                   ` (22 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 27b5699..bd7d6b5 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -290,7 +290,7 @@ static int elem_read_route(selem_none_t *s, int dir, selem_ctl_type_t type)
 
 static int elem_read_enum(selem_none_t *s)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	int type;
@@ -304,15 +304,14 @@ static int elem_read_enum(selem_none_t *s)
 	else if (s->selem.caps & SM_CAP_CENUM)
 		type = CTL_CAPTURE_ENUM;
 	c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < s->str[0].channels; idx++) {
 		unsigned int idx1 = idx;
 		if (idx >= c->values)
 			idx1 = 0;
 		s->str[0].vol[idx] =
-				snd_ctl_elem_value_get_enumerated(ctl, idx1);
+				snd_ctl_elem_value_get_enumerated(&ctl, idx1);
 	}
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 08/29] mixer: change code formatting for selem_read()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (6 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 07/29] mixer: remove alloca() from elem_read_enum() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 09/29] mixer: remove alloca() from selem_read() Takashi Sakamoto
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index bd7d6b5..39be2d1 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -451,7 +451,8 @@ static int selem_read(snd_mixer_elem_t *elem)
 			unsigned int idx1 = idx;
 			if (idx >= c->values)
 				idx1 = 0;
-			if (snd_ctl_elem_value_get_enumerated(ctl, idx1) != s->capture_item)
+			if (snd_ctl_elem_value_get_enumerated(ctl, idx1) !=
+								s->capture_item)
 				s->str[SM_CAPT].sw &= ~(1 << idx);
 		}
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 09/29] mixer: remove alloca() from selem_read()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (7 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 08/29] mixer: change code formatting for selem_read() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 10/29] mixer: change code formatting for elem_write_volume() Takashi Sakamoto
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 39be2d1..b32bd81 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -441,17 +441,16 @@ static int selem_read(snd_mixer_elem_t *elem)
 			return err;
 	}
 	if (s->ctls[CTL_CAPTURE_SOURCE].elem) {
-		snd_ctl_elem_value_t *ctl;
+		snd_ctl_elem_value_t ctl = {0};
 		selem_ctl_t *c = &s->ctls[CTL_CAPTURE_SOURCE];
-		snd_ctl_elem_value_alloca(&ctl);
-		err = snd_hctl_elem_read(c->elem, ctl);
+		err = snd_hctl_elem_read(c->elem, &ctl);
 		if (err < 0)
 			return err;
 		for (idx = 0; idx < s->str[SM_CAPT].channels; idx++) {
 			unsigned int idx1 = idx;
 			if (idx >= c->values)
 				idx1 = 0;
-			if (snd_ctl_elem_value_get_enumerated(ctl, idx1) !=
+			if (snd_ctl_elem_value_get_enumerated(&ctl, idx1) !=
 								s->capture_item)
 				s->str[SM_CAPT].sw &= ~(1 << idx);
 		}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 10/29] mixer: change code formatting for elem_write_volume()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (8 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 09/29] mixer: remove alloca() from selem_read() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 11/29] mixer: remove alloca() from elem_write_volume() Takashi Sakamoto
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index b32bd81..2ae4b0a 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -475,7 +475,8 @@ static int elem_write_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
 	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx, from_user(s, dir, c, s->str[dir].vol[idx]));
+		snd_ctl_elem_value_set_integer(ctl, idx,
+				from_user(s, dir, c, s->str[dir].vol[idx]));
 	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
 		return err;
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 11/29] mixer: remove alloca() from elem_write_volume()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (9 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 10/29] mixer: change code formatting for elem_write_volume() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 12/29] mixer: change code formatting for elem_write_switch() Takashi Sakamoto
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 2ae4b0a..ee9f84a 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -467,17 +467,16 @@ static int selem_read(snd_mixer_elem_t *elem)
 
 static int elem_write_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx,
+		snd_ctl_elem_value_set_integer(&ctl, idx,
 				from_user(s, dir, c, s->str[dir].vol[idx]));
-	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_write(c->elem, &ctl)) < 0)
 		return err;
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 12/29] mixer: change code formatting for elem_write_switch()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (10 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 11/29] mixer: remove alloca() from elem_write_volume() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 13/29] mixer: remove alloca() from elem_write_switch() Takashi Sakamoto
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index ee9f84a..d0e800e 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -491,7 +491,8 @@ static int elem_write_switch(selem_none_t *s, int dir, selem_ctl_type_t type)
 	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx, !!(s->str[dir].sw & (1 << idx)));
+		snd_ctl_elem_value_set_integer(ctl, idx,
+					!!(s->str[dir].sw & (1 << idx)));
 	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
 		return err;
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 13/29] mixer: remove alloca() from elem_write_switch()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (11 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 12/29] mixer: change code formatting for elem_write_switch() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 14/29] mixer: remove alloca() from elem_write_switch_constant() Takashi Sakamoto
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index d0e800e..c1f2b29 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -483,17 +483,16 @@ static int elem_write_volume(selem_none_t *s, int dir, selem_ctl_type_t type)
 
 static int elem_write_switch(selem_none_t *s, int dir, selem_ctl_type_t type)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx,
+		snd_ctl_elem_value_set_integer(&ctl, idx,
 					!!(s->str[dir].sw & (1 << idx)));
-	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_write(c->elem, &ctl)) < 0)
 		return err;
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 14/29] mixer: remove alloca() from elem_write_switch_constant()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (12 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 13/29] mixer: remove alloca() from elem_write_switch() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 15/29] mixer: change code formatting for elem_write_enum() Takashi Sakamoto
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index c1f2b29..13666b5 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -499,16 +499,15 @@ static int elem_write_switch(selem_none_t *s, int dir, selem_ctl_type_t type)
 
 static int elem_write_switch_constant(selem_none_t *s, selem_ctl_type_t type, int val)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx, !!val);
-	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
+		snd_ctl_elem_value_set_integer(&ctl, idx, !!val);
+	if ((err = snd_hctl_elem_write(c->elem, &ctl)) < 0)
 		return err;
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 15/29] mixer: change code formatting for elem_write_enum()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (13 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 14/29] mixer: remove alloca() from elem_write_switch_constant() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 16/29] mixer: remove alloca() from elem_write_enum() Takashi Sakamoto
                   ` (14 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 13666b5..5ae94d9 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -538,7 +538,8 @@ static int elem_write_enum(selem_none_t *s)
 	int type;
 	selem_ctl_t *c;
 	type = CTL_GLOBAL_ENUM;
-	if ( (s->selem.caps & (SM_CAP_CENUM | SM_CAP_PENUM) ) == (SM_CAP_CENUM | SM_CAP_PENUM) )
+	if ((s->selem.caps & (SM_CAP_CENUM | SM_CAP_PENUM)) ==
+						(SM_CAP_CENUM | SM_CAP_PENUM))
 		type = CTL_GLOBAL_ENUM;
 	else if (s->selem.caps & SM_CAP_PENUM)
 		type = CTL_PLAYBACK_ENUM;
@@ -549,7 +550,8 @@ static int elem_write_enum(selem_none_t *s)
 	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_enumerated(ctl, idx, (unsigned int)s->str[0].vol[idx]);
+		snd_ctl_elem_value_set_enumerated(ctl, idx,
+					(unsigned int)s->str[0].vol[idx]);
 	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
 		return err;
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 16/29] mixer: remove alloca() from elem_write_enum()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (14 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 15/29] mixer: change code formatting for elem_write_enum() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 17/29] mixer: change code formatting for elem_write_route() Takashi Sakamoto
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 5ae94d9..cf57ea5 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -532,7 +532,7 @@ static int elem_write_route(selem_none_t *s, int dir, selem_ctl_type_t type)
 
 static int elem_write_enum(selem_none_t *s)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	int type;
@@ -546,13 +546,12 @@ static int elem_write_enum(selem_none_t *s)
 	else if (s->selem.caps & SM_CAP_CENUM)
 		type = CTL_CAPTURE_ENUM;
 	c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_enumerated(ctl, idx,
+		snd_ctl_elem_value_set_enumerated(&ctl, idx,
 					(unsigned int)s->str[0].vol[idx]);
-	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_write(c->elem, &ctl)) < 0)
 		return err;
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 17/29] mixer: change code formatting for elem_write_route()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (15 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 16/29] mixer: remove alloca() from elem_write_enum() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 18/29] mixer: remove alloca() from elem_write_route() Takashi Sakamoto
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index cf57ea5..0ebaf5e 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -524,7 +524,8 @@ static int elem_write_route(selem_none_t *s, int dir, selem_ctl_type_t type)
 	for (idx = 0; idx < c->values * c->values; idx++)
 		snd_ctl_elem_value_set_integer(ctl, idx, 0);
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx * c->values + idx, !!(s->str[dir].sw & (1 << idx)));
+		snd_ctl_elem_value_set_integer(ctl, idx * c->values + idx,
+					       !!(s->str[dir].sw & (1 << idx)));
 	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
 		return err;
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 18/29] mixer: remove alloca() from elem_write_route()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (16 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 17/29] mixer: change code formatting for elem_write_route() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 19/29] mixer: change code formatting for selem_write_main() Takashi Sakamoto
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 0ebaf5e..d0e8963 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -514,19 +514,18 @@ static int elem_write_switch_constant(selem_none_t *s, selem_ctl_type_t type, in
 
 static int elem_write_route(selem_none_t *s, int dir, selem_ctl_type_t type)
 {
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	unsigned int idx;
 	int err;
 	selem_ctl_t *c = &s->ctls[type];
-	snd_ctl_elem_value_alloca(&ctl);
-	if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 		return err;
 	for (idx = 0; idx < c->values * c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx, 0);
+		snd_ctl_elem_value_set_integer(&ctl, idx, 0);
 	for (idx = 0; idx < c->values; idx++)
-		snd_ctl_elem_value_set_integer(ctl, idx * c->values + idx,
+		snd_ctl_elem_value_set_integer(&ctl, idx * c->values + idx,
 					       !!(s->str[dir].sw & (1 << idx)));
-	if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
+	if ((err = snd_hctl_elem_write(c->elem, &ctl)) < 0)
 		return err;
 	return 0;
 }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 19/29] mixer: change code formatting for selem_write_main()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (17 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 18/29] mixer: remove alloca() from elem_write_route() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 20/29] mixer: remove alloca() from selem_write_main() Takashi Sakamoto
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index d0e8963..10b878e 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -588,8 +588,10 @@ static int selem_write_main(snd_mixer_elem_t *elem)
 			return err;
 	}
 	if (s->ctls[CTL_GLOBAL_SWITCH].elem) {
-		if (s->ctls[CTL_PLAYBACK_SWITCH].elem && s->ctls[CTL_CAPTURE_SWITCH].elem)
-			err = elem_write_switch_constant(s, CTL_GLOBAL_SWITCH, 1);
+		if (s->ctls[CTL_PLAYBACK_SWITCH].elem &&
+					s->ctls[CTL_CAPTURE_SWITCH].elem)
+			err = elem_write_switch_constant(s, CTL_GLOBAL_SWITCH,
+							 1);
 		else
 			err = elem_write_switch(s, SM_PLAY, CTL_GLOBAL_SWITCH);
 		if (err < 0)
@@ -633,7 +635,8 @@ static int selem_write_main(snd_mixer_elem_t *elem)
 			return err;
 		for (idx = 0; idx < c->values; idx++) {
 			if (s->str[SM_CAPT].sw & (1 << idx))
-				snd_ctl_elem_value_set_enumerated(ctl, idx, s->capture_item);
+				snd_ctl_elem_value_set_enumerated(ctl,
+							idx, s->capture_item);
 		}
 		if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
 			return err;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 20/29] mixer: remove alloca() from selem_write_main()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (18 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 19/29] mixer: change code formatting for selem_write_main() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 21/29] mixer: change code formatting for init_db_range() Takashi Sakamoto
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 10b878e..4bd231c 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -628,17 +628,16 @@ static int selem_write_main(snd_mixer_elem_t *elem)
 			return err;
 	}
 	if (s->ctls[CTL_CAPTURE_SOURCE].elem) {
-		snd_ctl_elem_value_t *ctl;
+		snd_ctl_elem_value_t ctl = {0};
 		selem_ctl_t *c = &s->ctls[CTL_CAPTURE_SOURCE];
-		snd_ctl_elem_value_alloca(&ctl);
-		if ((err = snd_hctl_elem_read(c->elem, ctl)) < 0)
+		if ((err = snd_hctl_elem_read(c->elem, &ctl)) < 0)
 			return err;
 		for (idx = 0; idx < c->values; idx++) {
 			if (s->str[SM_CAPT].sw & (1 << idx))
-				snd_ctl_elem_value_set_enumerated(ctl,
+				snd_ctl_elem_value_set_enumerated(&ctl,
 							idx, s->capture_item);
 		}
-		if ((err = snd_hctl_elem_write(c->elem, ctl)) < 0)
+		if ((err = snd_hctl_elem_write(c->elem, &ctl)) < 0)
 			return err;
 		/* update the element, don't remove */
 		err = selem_read(elem);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 21/29] mixer: change code formatting for init_db_range()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (19 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 20/29] mixer: remove alloca() from selem_write_main() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 22/29] mixer: remove alloca() from init_db_range() Takashi Sakamoto
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 4bd231c..05dde41 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1112,10 +1112,10 @@ static int init_db_range(snd_hctl_elem_t *ctl, struct selem_str *rec)
 	snd_ctl_elem_info_alloca(&info);
 	if (snd_hctl_elem_info(ctl, info) < 0)
 		goto error;
-	if (! snd_ctl_elem_info_is_tlv_readable(info))
+	if (!snd_ctl_elem_info_is_tlv_readable(info))
 		goto error;
 	tlv = malloc(tlv_size);
-	if (! tlv)
+	if (!tlv)
 		return -ENOMEM;
 	if (snd_hctl_elem_tlv_read(ctl, tlv, tlv_size) < 0)
 		goto error;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 22/29] mixer: remove alloca() from init_db_range()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (20 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 21/29] mixer: change code formatting for init_db_range() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 23/29] mixer: remove alloca() from enum_item_name_ops() Takashi Sakamoto
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 05dde41..0799ceb 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1098,7 +1098,7 @@ static int convert_to_dB(snd_hctl_elem_t *ctl, struct selem_str *rec,
  */
 static int init_db_range(snd_hctl_elem_t *ctl, struct selem_str *rec)
 {
-	snd_ctl_elem_info_t *info;
+	snd_ctl_elem_info_t info = {0};
 	unsigned int *tlv = NULL;
 	const unsigned int tlv_size = 4096;
 	unsigned int *dbrec;
@@ -1109,10 +1109,9 @@ static int init_db_range(snd_hctl_elem_t *ctl, struct selem_str *rec)
 	if (rec->db_initialized)
 		return 0;
 
-	snd_ctl_elem_info_alloca(&info);
-	if (snd_hctl_elem_info(ctl, info) < 0)
+	if (snd_hctl_elem_info(ctl, &info) < 0)
 		goto error;
-	if (!snd_ctl_elem_info_is_tlv_readable(info))
+	if (!snd_ctl_elem_info_is_tlv_readable(&info))
 		goto error;
 	tlv = malloc(tlv_size);
 	if (!tlv)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 23/29] mixer: remove alloca() from enum_item_name_ops()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (21 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 22/29] mixer: remove alloca() from init_db_range() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 24/29] mixer: remove alloca() from get_enum_item_ops() Takashi Sakamoto
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 0799ceb..ab2b151 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1313,7 +1313,7 @@ static int enum_item_name_ops(snd_mixer_elem_t *elem,
 			      size_t maxlen, char *buf)
 {
 	selem_none_t *s = snd_mixer_elem_get_private(elem);
-	snd_ctl_elem_info_t *info;
+	snd_ctl_elem_info_t info = {0};
 	snd_hctl_elem_t *helem;
 	int type;
 
@@ -1330,11 +1330,10 @@ static int enum_item_name_ops(snd_mixer_elem_t *elem,
 	assert(helem);
 	if (item >= (unsigned int)s->ctls[type].max)
 		return -EINVAL;
-	snd_ctl_elem_info_alloca(&info);
-	snd_hctl_elem_info(helem, info);
-	snd_ctl_elem_info_set_item(info, item);
-	snd_hctl_elem_info(helem, info);
-	strncpy(buf, snd_ctl_elem_info_get_item_name(info), maxlen);
+	snd_hctl_elem_info(helem, &info);
+	snd_ctl_elem_info_set_item(&info, item);
+	snd_hctl_elem_info(helem, &info);
+	strncpy(buf, snd_ctl_elem_info_get_item_name(&info), maxlen);
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 24/29] mixer: remove alloca() from get_enum_item_ops()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (22 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 23/29] mixer: remove alloca() from enum_item_name_ops() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 25/29] mixer: remove alloca() from set_enum_item_ops() Takashi Sakamoto
                   ` (5 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index ab2b151..3362f82 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1342,7 +1342,7 @@ static int get_enum_item_ops(snd_mixer_elem_t *elem,
 			     unsigned int *itemp)
 {
 	selem_none_t *s = snd_mixer_elem_get_private(elem);
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	snd_hctl_elem_t *helem;
 	int err;
 
@@ -1352,10 +1352,9 @@ static int get_enum_item_ops(snd_mixer_elem_t *elem,
 	if (!helem) helem = s->ctls[CTL_PLAYBACK_ENUM].elem;
 	if (!helem) helem = s->ctls[CTL_CAPTURE_ENUM].elem;
 	assert(helem);
-	snd_ctl_elem_value_alloca(&ctl);
-	err = snd_hctl_elem_read(helem, ctl);
+	err = snd_hctl_elem_read(helem, &ctl);
 	if (! err)
-		*itemp = snd_ctl_elem_value_get_enumerated(ctl, channel);
+		*itemp = snd_ctl_elem_value_get_enumerated(&ctl, channel);
 	return err;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 25/29] mixer: remove alloca() from set_enum_item_ops()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (23 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 24/29] mixer: remove alloca() from get_enum_item_ops() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 26/29] mixer: change code formatting for simple_add1() Takashi Sakamoto
                   ` (4 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 3362f82..3ee1168 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1363,7 +1363,7 @@ static int set_enum_item_ops(snd_mixer_elem_t *elem,
 			     unsigned int item)
 {
 	selem_none_t *s = snd_mixer_elem_get_private(elem);
-	snd_ctl_elem_value_t *ctl;
+	snd_ctl_elem_value_t ctl = {0};
 	snd_hctl_elem_t *helem;
 	int err;
 	int type;
@@ -1385,13 +1385,12 @@ static int set_enum_item_ops(snd_mixer_elem_t *elem,
 	if (item >= (unsigned int)s->ctls[type].max) {
 		return -EINVAL;
 	}
-	snd_ctl_elem_value_alloca(&ctl);
-	err = snd_hctl_elem_read(helem, ctl);
+	err = snd_hctl_elem_read(helem, &ctl);
 	if (err < 0) {
 		return err;
 	}
-	snd_ctl_elem_value_set_enumerated(ctl, channel, item);
-	return snd_hctl_elem_write(helem, ctl);
+	snd_ctl_elem_value_set_enumerated(&ctl, channel, item);
+	return snd_hctl_elem_write(helem, &ctl);
 }
 
 static struct sm_elem_ops simple_none_ops = {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 26/29] mixer: change code formatting for simple_add1()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (24 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 25/29] mixer: remove alloca() from set_enum_item_ops() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 27/29] mixer: remove alloca() from simple_add1() Takashi Sakamoto
                   ` (3 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 3ee1168..1ccccc4 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1527,8 +1527,10 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
 		simple->selem.id = id;
 		simple->selem.ops = &simple_none_ops;
 		err = snd_mixer_elem_new(&melem, SND_MIXER_ELEM_SIMPLE,
-					 get_compare_weight(snd_mixer_selem_id_get_name(simple->selem.id), snd_mixer_selem_id_get_index(simple->selem.id)),
-					 simple, selem_free);
+			get_compare_weight(
+				snd_mixer_selem_id_get_name(simple->selem.id),
+				snd_mixer_selem_id_get_index(simple->selem.id)),
+			simple, selem_free);
 		if (err < 0) {
 			snd_mixer_selem_id_free(id);
 			free(simple);
@@ -1541,11 +1543,12 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
 	}
 	if (simple->ctls[type].elem) {
 		SNDERR("helem (%s,'%s',%u,%u,%u) appears twice or more",
-				snd_ctl_elem_iface_name(snd_hctl_elem_get_interface(helem)),
-				snd_hctl_elem_get_name(helem),
-				snd_hctl_elem_get_index(helem),
-				snd_hctl_elem_get_device(helem),
-				snd_hctl_elem_get_subdevice(helem));
+		       snd_ctl_elem_iface_name(
+				snd_hctl_elem_get_interface(helem)),
+		       snd_hctl_elem_get_name(helem),
+		       snd_hctl_elem_get_index(helem),
+		       snd_hctl_elem_get_device(helem),
+		       snd_hctl_elem_get_subdevice(helem));
 		err = -EINVAL;
 		goto __error;
 	}
@@ -1560,8 +1563,10 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
 		simple->ctls[type].max = snd_ctl_elem_info_get_items(info);
 	} else {
 		if (ctype == SND_CTL_ELEM_TYPE_INTEGER) {
-			simple->ctls[type].min = snd_ctl_elem_info_get_min(info);
-			simple->ctls[type].max = snd_ctl_elem_info_get_max(info);
+			simple->ctls[type].min =
+					snd_ctl_elem_info_get_min(info);
+			simple->ctls[type].max =
+					snd_ctl_elem_info_get_max(info);
 		}
 	}
 	switch (type) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 27/29] mixer: remove alloca() from simple_add1()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (25 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 26/29] mixer: change code formatting for simple_add1() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 28/29] mixer: change code formatting for simple_event_add() Takashi Sakamoto
                   ` (2 subsequent siblings)
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 1ccccc4..68ab37e 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1419,18 +1419,17 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
 	snd_mixer_selem_id_t *id;
 	int new = 0;
 	int err;
-	snd_ctl_elem_info_t *info;
+	snd_ctl_elem_info_t info = {0};
 	selem_none_t *simple;
 	const char *name1;
 	snd_ctl_elem_type_t ctype;
 	unsigned long values;
 
-	snd_ctl_elem_info_alloca(&info);
-	err = snd_hctl_elem_info(helem, info);
+	err = snd_hctl_elem_info(helem, &info);
 	if (err < 0)
 		return err;
-	ctype = snd_ctl_elem_info_get_type(info);
-	values = snd_ctl_elem_info_get_count(info);
+	ctype = snd_ctl_elem_info_get_type(&info);
+	values = snd_ctl_elem_info_get_count(&info);
 	switch (type) {
 	case CTL_SINGLE:
 		if (ctype == SND_CTL_ELEM_TYPE_ENUMERATED)
@@ -1553,20 +1552,20 @@ static int simple_add1(snd_mixer_class_t *class, const char *name,
 		goto __error;
 	}
 	simple->ctls[type].elem = helem;
-	simple->ctls[type].type = snd_ctl_elem_info_get_type(info);
-	simple->ctls[type].inactive = snd_ctl_elem_info_is_inactive(info);
+	simple->ctls[type].type = snd_ctl_elem_info_get_type(&info);
+	simple->ctls[type].inactive = snd_ctl_elem_info_is_inactive(&info);
 	simple->ctls[type].values = values;
 	if ( (type == CTL_GLOBAL_ENUM) ||
 	     (type == CTL_PLAYBACK_ENUM) ||
 	     (type == CTL_CAPTURE_ENUM) ) {
 		simple->ctls[type].min = 0;
-		simple->ctls[type].max = snd_ctl_elem_info_get_items(info);
+		simple->ctls[type].max = snd_ctl_elem_info_get_items(&info);
 	} else {
 		if (ctype == SND_CTL_ELEM_TYPE_INTEGER) {
 			simple->ctls[type].min =
-					snd_ctl_elem_info_get_min(info);
+					snd_ctl_elem_info_get_min(&info);
 			simple->ctls[type].max =
-					snd_ctl_elem_info_get_max(info);
+					snd_ctl_elem_info_get_max(&info);
 		}
 	}
 	switch (type) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 28/29] mixer: change code formatting for simple_event_add()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (26 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 27/29] mixer: remove alloca() from simple_add1() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  0:23 ` [PATCH 29/29] mixer: remove alloca() from simple_event_add() Takashi Sakamoto
  2016-07-15  6:20 ` [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Iwai
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

This commit applies code format according to typical and moderate rule.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 68ab37e..9b0705c 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1616,7 +1616,8 @@ static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
 		snd_ctl_elem_info_alloca(&info);
 		err = snd_hctl_elem_info(helem, info);
 		assert(err >= 0);
-		if (snd_ctl_elem_info_get_type(info) != SND_CTL_ELEM_TYPE_ENUMERATED)
+		if (snd_ctl_elem_info_get_type(info) !=
+						SND_CTL_ELEM_TYPE_ENUMERATED)
 			return 0;
 		items = snd_ctl_elem_info_get_items(info);
 		for (k = 0; k < items; ++k) {
@@ -1626,7 +1627,8 @@ static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
 			if (err < 0)
 				return err;
 			n = snd_ctl_elem_info_get_item_name(info);
-			err = simple_add1(class, n, helem, CTL_CAPTURE_SOURCE, k);
+			err = simple_add1(class, n, helem, CTL_CAPTURE_SOURCE,
+					  k);
 			if (err < 0)
 				return err;
 		}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 29/29] mixer: remove alloca() from simple_event_add()
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (27 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 28/29] mixer: change code formatting for simple_event_add() Takashi Sakamoto
@ 2016-07-15  0:23 ` Takashi Sakamoto
  2016-07-15  6:20 ` [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Iwai
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Sakamoto @ 2016-07-15  0:23 UTC (permalink / raw)
  To: tiwai, perex; +Cc: alsa-devel

Both of alloca() and automatic variables keep storages on stack, while
the former generates more instructions than the latter. It's better to use
the latter if the size of storage is computable at pre-compile or compile
time; i.e. just for structures.

This commit obsolete usages of alloca() with automatic variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 src/mixer/simple_none.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 9b0705c..e129514 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1610,23 +1610,22 @@ static int simple_event_add(snd_mixer_class_t *class, snd_hctl_elem_t *helem)
 	if (snd_hctl_elem_get_interface(helem) != SND_CTL_ELEM_IFACE_MIXER)
 		return 0;
 	if (strcmp(name, "Capture Source") == 0) {
-		snd_ctl_elem_info_t *info;
+		snd_ctl_elem_info_t info = {0};
 		unsigned int k, items;
 		int err;
-		snd_ctl_elem_info_alloca(&info);
-		err = snd_hctl_elem_info(helem, info);
+		err = snd_hctl_elem_info(helem, &info);
 		assert(err >= 0);
-		if (snd_ctl_elem_info_get_type(info) !=
+		if (snd_ctl_elem_info_get_type(&info) !=
 						SND_CTL_ELEM_TYPE_ENUMERATED)
 			return 0;
-		items = snd_ctl_elem_info_get_items(info);
+		items = snd_ctl_elem_info_get_items(&info);
 		for (k = 0; k < items; ++k) {
 			const char *n;
-			snd_ctl_elem_info_set_item(info, k);
-			err = snd_hctl_elem_info(helem, info);
+			snd_ctl_elem_info_set_item(&info, k);
+			err = snd_hctl_elem_info(helem, &info);
 			if (err < 0)
 				return err;
-			n = snd_ctl_elem_info_get_item_name(info);
+			n = snd_ctl_elem_info_get_item_name(&info);
 			err = simple_add1(class, n, helem, CTL_CAPTURE_SOURCE,
 					  k);
 			if (err < 0)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables
  2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
                   ` (28 preceding siblings ...)
  2016-07-15  0:23 ` [PATCH 29/29] mixer: remove alloca() from simple_event_add() Takashi Sakamoto
@ 2016-07-15  6:20 ` Takashi Iwai
  29 siblings, 0 replies; 31+ messages in thread
From: Takashi Iwai @ 2016-07-15  6:20 UTC (permalink / raw)
  To: Takashi Sakamoto; +Cc: alsa-devel

On Fri, 15 Jul 2016 02:23:04 +0200,
Takashi Sakamoto wrote:
> 
> Hi,
> 
> A batch of this patchset is to apply the same idea to mixer feature as I
> posted in this thread.
> http://mailman.alsa-project.org/pipermail/alsa-devel/2016-July/110196.html
> 
> In short, replacement of alloca() with automatic variables brings us some
> advantages; better execution performance and saving local storages just for
> a little.
> 
> I can see below effect on my environment (Ubuntu 16.04, amd64)
> $ git checkout master
> $ git show HEAD
> commit 33e946fdd32da2b918e88750fcfd78014ae3e079
> ...
> $ ./gitcompile --with-plugindir=/usr/lib/x86_64-linux-gnu/alsa-lib/
> ...
> $ ls -l src/.libs/libasound.so.2.0.0 
> -rwxrwxr-x 1 mocchi mocchi 4783080  7月 15 09:08 src/.libs/libasound.so.2.0.0
> $ git checkout remove-alloca-mixer
> $ make
> ...
> $ ls -l src/.libs/libasound.so.2.0.0 
> -rwxrwxr-x 1 mocchi mocchi 4780152  7月 15 09:09 src/.libs/libasound.so.2.0.0
> $ gcc -v
> ...
> gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1)
> 
> 
> Takashi Sakamoto (29):
>   mixer: include library local header to find layout of structures
>   mixer: change code formatting for elem_read_volume()
>   mixer: remove alloca() from elem_read_volume()
>   mixer: change code formatting for elem_read_route()
>   mixer: remove alloca() from elem_read_route()
>   mixer: change code formatting for elem_read_enum()
>   mixer: remove alloca() from elem_read_enum()
>   mixer: change code formatting for selem_read()
>   mixer: remove alloca() from selem_read()
>   mixer: change code formatting for elem_write_volume()
>   mixer: remove alloca() from elem_write_volume()
>   mixer: change code formatting for elem_write_switch()
>   mixer: remove alloca() from elem_write_switch()
>   mixer: remove alloca() from elem_write_switch_constant()
>   mixer: change code formatting for elem_write_enum()
>   mixer: remove alloca() from elem_write_enum()
>   mixer: change code formatting for elem_write_route()
>   mixer: remove alloca() from elem_write_route()
>   mixer: change code formatting for selem_write_main()
>   mixer: remove alloca() from selem_write_main()
>   mixer: change code formatting for init_db_range()
>   mixer: remove alloca() from init_db_range()
>   mixer: remove alloca() from enum_item_name_ops()
>   mixer: remove alloca() from get_enum_item_ops()
>   mixer: remove alloca() from set_enum_item_ops()
>   mixer: change code formatting for simple_add1()
>   mixer: remove alloca() from simple_add1()
>   mixer: change code formatting for simple_event_add()
>   mixer: remove alloca() from simple_event_add()

Applied all patches.  Thanks!


Takashi
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2016-07-15  6:20 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-15  0:23 [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 01/29] mixer: include library local header to find layout of structures Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 02/29] mixer: change code formatting for elem_read_volume() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 03/29] mixer: remove alloca() from elem_read_volume() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 04/29] mixer: change code formatting for elem_read_route() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 05/29] mixer: remove alloca() from elem_read_route() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 06/29] mixer: change code formatting for elem_read_enum() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 07/29] mixer: remove alloca() from elem_read_enum() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 08/29] mixer: change code formatting for selem_read() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 09/29] mixer: remove alloca() from selem_read() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 10/29] mixer: change code formatting for elem_write_volume() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 11/29] mixer: remove alloca() from elem_write_volume() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 12/29] mixer: change code formatting for elem_write_switch() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 13/29] mixer: remove alloca() from elem_write_switch() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 14/29] mixer: remove alloca() from elem_write_switch_constant() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 15/29] mixer: change code formatting for elem_write_enum() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 16/29] mixer: remove alloca() from elem_write_enum() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 17/29] mixer: change code formatting for elem_write_route() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 18/29] mixer: remove alloca() from elem_write_route() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 19/29] mixer: change code formatting for selem_write_main() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 20/29] mixer: remove alloca() from selem_write_main() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 21/29] mixer: change code formatting for init_db_range() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 22/29] mixer: remove alloca() from init_db_range() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 23/29] mixer: remove alloca() from enum_item_name_ops() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 24/29] mixer: remove alloca() from get_enum_item_ops() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 25/29] mixer: remove alloca() from set_enum_item_ops() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 26/29] mixer: change code formatting for simple_add1() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 27/29] mixer: remove alloca() from simple_add1() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 28/29] mixer: change code formatting for simple_event_add() Takashi Sakamoto
2016-07-15  0:23 ` [PATCH 29/29] mixer: remove alloca() from simple_event_add() Takashi Sakamoto
2016-07-15  6:20 ` [alsa-lib][PATCH 00/29] mixer: replace usage of alloca() with automatic variables Takashi Iwai

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.