[alsa-devel] [PATCH 28/34] conf: remove alloca() from snd_func_private_pcm_subdevice()

Takashi Sakamoto o-takashi at sakamocchi.jp
Thu Jul 14 16:07:45 CEST 2016


Both of alloca() and automatic variables keeps 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 at sakamocchi.jp>
---
 src/confmisc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/confmisc.c b/src/confmisc.c
index 99be48b..a985f14 100644
--- a/src/confmisc.c
+++ b/src/confmisc.c
@@ -1162,7 +1162,7 @@ SND_DLSYM_BUILD_VERSION(snd_func_pcm_args_by_class, SND_CONFIG_DLSYM_VERSION_EVA
 int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED,
 				   snd_config_t *src, snd_config_t *private_data)
 {
-	snd_pcm_info_t *info;
+	snd_pcm_info_t info = {0};
 	const char *id;
 	const void *data;
 	snd_pcm_t *pcm;
@@ -1181,15 +1181,15 @@ int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIB
 		SNDERR("field pcm_handle is not a pointer");
 		return err;
 	}
-	snd_pcm_info_alloca(&info);
-	err = snd_pcm_info(pcm, info);
+	err = snd_pcm_info(pcm, &info);
 	if (err < 0) {
 		SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
 		return err;
 	}
 	err = snd_config_get_id(src, &id);
 	if (err >= 0)
-		err = snd_config_imake_integer(dst, id, snd_pcm_info_get_subdevice(info));
+		err = snd_config_imake_integer(dst, id,
+					snd_pcm_info_get_subdevice(&info));
 	return err;
 }
 #ifndef DOC_HIDDEN
-- 
2.7.4



More information about the Alsa-devel mailing list