Blame SOURCES/alsa-git.patch

02270a
From 63ba5243ab7a33b77be5b65c0a8a2a0d5e26983f Mon Sep 17 00:00:00 2001
02270a
From: Vanitha Channaiah <vanitha.channaiah@in.bosch.com>
02270a
Date: Wed, 15 May 2019 11:56:32 +0530
02270a
Subject: [PATCH 01/25] pcm: direct: Add generic hw_ptr_alignment function for
02270a
 dmix, dshare and dsnoop
02270a
02270a
Move the code snd_pcm_direct_reset_slave_ptr() from pcm_dmix.c
02270a
to pcm_direct.c and its header so that the helper function can be
02270a
re-used by other direct-pcm plugins.
02270a
There is no change in the behavior or the functionality.
02270a
02270a
Signed-off-by: Vanitha Channaiah <vanitha.channaiah@in.bosch.com>
02270a
Signed-off-by: Takashi Iwai <tiwai@suse.de>
02270a
---
02270a
 src/pcm/pcm_direct.c | 19 +++++++++++++++++++
02270a
 src/pcm/pcm_direct.h |  8 ++++++++
02270a
 src/pcm/pcm_dmix.c   | 25 ++-----------------------
02270a
 3 files changed, 29 insertions(+), 23 deletions(-)
02270a
02270a
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
02270a
index 666a8ce5..411a035b 100644
02270a
--- a/src/pcm/pcm_direct.c
02270a
+++ b/src/pcm/pcm_direct.c
02270a
@@ -2040,3 +2040,22 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
02270a
 
02270a
 	return 0;
02270a
 }
02270a
+
02270a
+void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix)
02270a
+{
02270a
+	dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
02270a
+
02270a
+	if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP ||
02270a
+		(dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO &&
02270a
+		pcm->buffer_size <= pcm->period_size * 2))
02270a
+		dmix->slave_appl_ptr =
02270a
+			((dmix->slave_appl_ptr + dmix->slave_period_size - 1) /
02270a
+			dmix->slave_period_size) * dmix->slave_period_size;
02270a
+	else if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDDOWN ||
02270a
+		(dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO &&
02270a
+		(dmix->slave_period_size * SEC_TO_MS) /
02270a
+		pcm->rate < LOW_LATENCY_PERIOD_TIME))
02270a
+		dmix->slave_appl_ptr = dmix->slave_hw_ptr =
02270a
+			((dmix->slave_hw_ptr / dmix->slave_period_size) *
02270a
+			dmix->slave_period_size);
02270a
+}
02270a
diff --git a/src/pcm/pcm_direct.h b/src/pcm/pcm_direct.h
02270a
index da5e280e..a71aab13 100644
02270a
--- a/src/pcm/pcm_direct.h
02270a
+++ b/src/pcm/pcm_direct.h
02270a
@@ -24,6 +24,11 @@
02270a
 
02270a
 #define DIRECT_IPC_SEMS         1
02270a
 #define DIRECT_IPC_SEM_CLIENT   0
02270a
+/* Seconds representing in Milli seconds */
02270a
+#define SEC_TO_MS               1000
02270a
+/* slave_period time for low latency requirements in ms */
02270a
+#define LOW_LATENCY_PERIOD_TIME 10
02270a
+
02270a
 
02270a
 typedef void (mix_areas_t)(unsigned int size,
02270a
 			   volatile void *dst, void *src,
02270a
@@ -257,6 +262,8 @@ struct snd_pcm_direct {
02270a
 	snd1_pcm_direct_get_chmap
02270a
 #define snd_pcm_direct_set_chmap \
02270a
 	snd1_pcm_direct_set_chmap
02270a
+#define snd_pcm_direct_reset_slave_ptr \
02270a
+	snd1_pcm_direct_reset_slave_ptr
02270a
 
02270a
 int snd_pcm_direct_semaphore_create_or_connect(snd_pcm_direct_t *dmix);
02270a
 
02270a
@@ -341,6 +348,7 @@ int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct);
02270a
 int snd_pcm_direct_client_chk_xrun(snd_pcm_direct_t *direct, snd_pcm_t *pcm);
02270a
 int snd_timer_async(snd_timer_t *timer, int sig, pid_t pid);
02270a
 struct timespec snd_pcm_hw_fast_tstamp(snd_pcm_t *pcm);
02270a
+void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix);
02270a
 
02270a
 struct snd_pcm_direct_open_conf {
02270a
 	key_t ipc_key;
02270a
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
02270a
index c5592cdb..dcde40d9 100644
02270a
--- a/src/pcm/pcm_dmix.c
02270a
+++ b/src/pcm/pcm_dmix.c
02270a
@@ -55,9 +55,6 @@ const char *_snd_module_pcm_dmix = "";
02270a
 #define STATE_RUN_PENDING	1024
02270a
 #endif
02270a
 
02270a
-#define SEC_TO_MS	1000			/* Seconds representing in Milli seconds */
02270a
-#define LOW_LATENCY_PERIOD_TIME	10	/* slave_period time for low latency requirements in ms */
02270a
-
02270a
 /*
02270a
  *
02270a
  */
02270a
@@ -560,30 +557,12 @@ static int snd_pcm_dmix_hwsync(snd_pcm_t *pcm)
02270a
 	}
02270a
 }
02270a
 
02270a
-static void reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix)
02270a
-{
02270a
-	dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
02270a
-
02270a
-	if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP ||
02270a
-	    (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO &&
02270a
-	     pcm->buffer_size <= pcm->period_size * 2))
02270a
-		dmix->slave_appl_ptr =
02270a
-			((dmix->slave_appl_ptr + dmix->slave_period_size - 1)
02270a
-			 / dmix->slave_period_size) * dmix->slave_period_size;
02270a
-	else if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDDOWN ||
02270a
-		 (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO &&
02270a
-		  (dmix->slave_period_size * SEC_TO_MS) / pcm->rate < LOW_LATENCY_PERIOD_TIME))
02270a
-		dmix->slave_appl_ptr = dmix->slave_hw_ptr =
02270a
-			((dmix->slave_hw_ptr / dmix->slave_period_size) *
02270a
-			 dmix->slave_period_size);
02270a
-}
02270a
-
02270a
 static int snd_pcm_dmix_reset(snd_pcm_t *pcm)
02270a
 {
02270a
 	snd_pcm_direct_t *dmix = pcm->private_data;
02270a
 	dmix->hw_ptr %= pcm->period_size;
02270a
 	dmix->appl_ptr = dmix->last_appl_ptr = dmix->hw_ptr;
02270a
-	reset_slave_ptr(pcm, dmix);
02270a
+	snd_pcm_direct_reset_slave_ptr(pcm, dmix);
02270a
 	return 0;
02270a
 }
02270a
 
02270a
@@ -592,7 +571,7 @@ static int snd_pcm_dmix_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dmix)
02270a
 	int err;
02270a
 
02270a
 	snd_pcm_hwsync(dmix->spcm);
02270a
-	reset_slave_ptr(pcm, dmix);
02270a
+	snd_pcm_direct_reset_slave_ptr(pcm, dmix);
02270a
 	err = snd_timer_start(dmix->timer);
02270a
 	if (err < 0)
02270a
 		return err;
02270a
-- 
02270a
2.20.1
02270a
02270a
02270a
From 7265e603bf880a9ec2cd01c3cf2afbd7709e5af4 Mon Sep 17 00:00:00 2001
02270a
From: Vanitha Channaiah <vanitha.channaiah@in.bosch.com>
02270a
Date: Wed, 15 May 2019 11:56:33 +0530
02270a
Subject: [PATCH 02/25] pcm: dshare: Added "hw_ptr_alignment" option in
02270a
 configuration for alignment of slave pointers
02270a
02270a
This change adapt the fix commit 6b058fda9dce
02270a
("pcm: dmix: Add option to allow alignment of slave pointers")
02270a
for dshare plugin
02270a
02270a
Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr
02270a
is not period aligned. Therefore snd_pcm_wait() will block for a longer
02270a
time as required.
02270a
02270a
With these rcar driver changes the exact position of the dma is returned.
02270a
During snd_pcm_start they read hw_ptr as reference, and this hw_ptr
02270a
is now not period aligned, and is a little ahead over the period while it
02270a
is read. Therefore when the avail is calculated during snd_pcm_wait(),
02270a
it is missing the avail_min by a few frames.
02270a
02270a
An additional option hw_ptr_alignment is provided to dshare configuration,
02270a
to allow the user to configure the slave application and hw pointer
02270a
alignment at startup
02270a
02270a
Signed-off-by: Vanitha Channaiah <vanitha.channaiah@in.bosch.com>
02270a
Signed-off-by: Takashi Iwai <tiwai@suse.de>
02270a
---
02270a
 src/pcm/pcm_dshare.c | 40 +++++++++++++++++++++++++++++++++++-----
02270a
 1 file changed, 35 insertions(+), 5 deletions(-)
02270a
02270a
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
02270a
index f135b5df..cf8a8631 100644
02270a
--- a/src/pcm/pcm_dshare.c
02270a
+++ b/src/pcm/pcm_dshare.c
02270a
@@ -333,16 +333,16 @@ static int snd_pcm_dshare_reset(snd_pcm_t *pcm)
02270a
 	snd_pcm_direct_t *dshare = pcm->private_data;
02270a
 	dshare->hw_ptr %= pcm->period_size;
02270a
 	dshare->appl_ptr = dshare->last_appl_ptr = dshare->hw_ptr;
02270a
-	dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr;
02270a
+	snd_pcm_direct_reset_slave_ptr(pcm, dshare);
02270a
 	return 0;
02270a
 }
02270a
 
02270a
-static int snd_pcm_dshare_start_timer(snd_pcm_direct_t *dshare)
02270a
+static int snd_pcm_dshare_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dshare)
02270a
 {
02270a
 	int err;
02270a
 
02270a
 	snd_pcm_hwsync(dshare->spcm);
02270a
-	dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr;
02270a
+	snd_pcm_direct_reset_slave_ptr(pcm, dshare);
02270a
 	err = snd_timer_start(dshare->timer);
02270a
 	if (err < 0)
02270a
 		return err;
02270a
@@ -364,7 +364,8 @@ static int snd_pcm_dshare_start(snd_pcm_t *pcm)
02270a
 	else if (avail < 0)
02270a
 		return 0;
02270a
 	else {
02270a
-		if ((err = snd_pcm_dshare_start_timer(dshare)) < 0)
02270a
+		err = snd_pcm_dshare_start_timer(pcm, dshare);
02270a
+		if (err < 0)
02270a
 			return err;
02270a
 		snd_pcm_dshare_sync_area(pcm);
02270a
 	}
02270a
@@ -547,7 +548,8 @@ static snd_pcm_sframes_t snd_pcm_dshare_mmap_commit(snd_pcm_t *pcm,
02270a
 		return 0;
02270a
 	snd_pcm_mmap_appl_forward(pcm, size);
02270a
 	if (dshare->state == STATE_RUN_PENDING) {
02270a
-		if ((err = snd_pcm_dshare_start_timer(dshare)) < 0)
02270a
+		err = snd_pcm_dshare_start_timer(pcm, dshare);
02270a
+		if (err < 0)
02270a
 			return err;
02270a
 	} else if (dshare->state == SND_PCM_STATE_RUNNING ||
02270a
 		   dshare->state == SND_PCM_STATE_DRAINING) {
02270a
@@ -755,6 +757,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,
02270a
 	dshare->slowptr = opts->slowptr;
02270a
 	dshare->max_periods = opts->max_periods;
02270a
 	dshare->var_periodsize = opts->var_periodsize;
02270a
+	dshare->hw_ptr_alignment = opts->hw_ptr_alignment;
02270a
 	dshare->sync_ptr = snd_pcm_dshare_sync_ptr;
02270a
 
02270a
  retry:
02270a
@@ -912,6 +915,12 @@ pcm.name {
02270a
 	ipc_key INT		# unique IPC key
02270a
 	ipc_key_add_uid BOOL	# add current uid to unique IPC key
02270a
 	ipc_perm INT		# IPC permissions (octal, default 0600)
02270a
+	hw_ptr_alignment STR	# Slave application and hw pointer alignment type
02270a
+		# STR can be one of the below strings :
02270a
+		# no
02270a
+		# roundup
02270a
+		# rounddown
02270a
+		# auto (default)
02270a
 	slave STR
02270a
 	# or
02270a
 	slave {			# Slave definition
02270a
@@ -936,6 +945,27 @@ pcm.name {
02270a
 }
02270a
 \endcode
02270a
 
02270a
+hw_ptr_alignment specifies slave application and hw
02270a
+pointer alignment type. By default hw_ptr_alignment is auto. Below are
02270a
+the possible configurations:
02270a
+- no: minimal latency with minimal frames dropped at startup. But
02270a
+  wakeup of application (return from snd_pcm_wait() or poll()) can
02270a
+  take up to 2 * period.
02270a
+- roundup: It is guaranteed that all frames will be played at
02270a
+  startup. But the latency will increase upto period-1 frames.
02270a
+- rounddown: It is guaranteed that a wakeup will happen for each
02270a
+  period and frames can be written from application. But on startup
02270a
+  upto period-1 frames will be dropped.
02270a
+- auto: Selects the best approach depending on the used period and
02270a
+  buffer size.
02270a
+  If the application buffer size is < 2 * application period,
02270a
+  "roundup" will be selected to avoid under runs. If the slave_period
02270a
+  is < 10ms we could expect that there are low latency
02270a
+  requirements. Therefore "rounddown" will be chosen to avoid long
02270a
+  wakeup times. Such wakeup delay could otherwise end up with Xruns in
02270a
+  case of a dependency to another sound device (e.g. forwarding of
02270a
+  microphone to speaker). Else "no" will be chosen.
02270a
+
02270a
 \subsection pcm_plugins_dshare_funcref Function reference
02270a
 
02270a
 
    02270a
    -- 
    02270a
    2.20.1
    02270a
    02270a
    02270a
    From 3ab798004733ce65bd5c7a48d650de3465825210 Mon Sep 17 00:00:00 2001
    02270a
    From: Vanitha Channaiah <vanitha.channaiah@in.bosch.com>
    02270a
    Date: Wed, 15 May 2019 11:56:34 +0530
    02270a
    Subject: [PATCH 03/25] pcm: dsnoop: Added "hw_ptr_alignment" option in
    02270a
     configuration for slave pointer alignment
    02270a
    02270a
    This change adapt the fix commit 6b058fda9dce
    02270a
    ("pcm: dmix: Add option to allow alignment of slave pointers")
    02270a
    for dsnoop plugin
    02270a
    02270a
    Issue is that snd_pcm_wait() goes back to waiting because the hw_ptr
    02270a
    is not period aligned. Therefore snd_pcm_wait() will block for a longer
    02270a
    time as required.
    02270a
    02270a
    With these rcar driver changes the exact position of the dma is returned.
    02270a
    During snd_pcm_start they read hw_ptr as reference, and this hw_ptr
    02270a
    is now not period aligned, and is a little ahead over the period while it
    02270a
    is read. Therefore when the avail is calculated during snd_pcm_wait(),
    02270a
    it is missing the avail_min by a few frames.
    02270a
    02270a
    An additional option hw_ptr_alignment is provided to dsnoop configuration,
    02270a
    to allow the user to configure the slave application and hw pointer
    02270a
    alignment at startup
    02270a
    02270a
    Signed-off-by: Vanitha Channaiah <vanitha.channaiah@in.bosch.com>
    02270a
    Signed-off-by: Takashi Iwai <tiwai@suse.de>
    02270a
    ---
    02270a
     src/pcm/pcm_direct.c |  1 -
    02270a
     src/pcm/pcm_dmix.c   |  2 ++
    02270a
     src/pcm/pcm_dshare.c |  2 ++
    02270a
     src/pcm/pcm_dsnoop.c | 30 +++++++++++++++++++++++++++++-
    02270a
     4 files changed, 33 insertions(+), 2 deletions(-)
    02270a
    02270a
    diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
    02270a
    index 411a035b..54d99005 100644
    02270a
    --- a/src/pcm/pcm_direct.c
    02270a
    +++ b/src/pcm/pcm_direct.c
    02270a
    @@ -2043,7 +2043,6 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf,
    02270a
     
    02270a
     void snd_pcm_direct_reset_slave_ptr(snd_pcm_t *pcm, snd_pcm_direct_t *dmix)
    02270a
     {
    02270a
    -	dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
    02270a
     
    02270a
     	if (dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_ROUNDUP ||
    02270a
     		(dmix->hw_ptr_alignment == SND_PCM_HW_PTR_ALIGNMENT_AUTO &&
    02270a
    diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
    02270a
    index dcde40d9..274726e4 100644
    02270a
    --- a/src/pcm/pcm_dmix.c
    02270a
    +++ b/src/pcm/pcm_dmix.c
    02270a
    @@ -562,6 +562,7 @@ static int snd_pcm_dmix_reset(snd_pcm_t *pcm)
    02270a
     	snd_pcm_direct_t *dmix = pcm->private_data;
    02270a
     	dmix->hw_ptr %= pcm->period_size;
    02270a
     	dmix->appl_ptr = dmix->last_appl_ptr = dmix->hw_ptr;
    02270a
    +	dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
    02270a
     	snd_pcm_direct_reset_slave_ptr(pcm, dmix);
    02270a
     	return 0;
    02270a
     }
    02270a
    @@ -571,6 +572,7 @@ static int snd_pcm_dmix_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dmix)
    02270a
     	int err;
    02270a
     
    02270a
     	snd_pcm_hwsync(dmix->spcm);
    02270a
    +	dmix->slave_appl_ptr = dmix->slave_hw_ptr = *dmix->spcm->hw.ptr;
    02270a
     	snd_pcm_direct_reset_slave_ptr(pcm, dmix);
    02270a
     	err = snd_timer_start(dmix->timer);
    02270a
     	if (err < 0)
    02270a
    diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
    02270a
    index cf8a8631..b75809c8 100644
    02270a
    --- a/src/pcm/pcm_dshare.c
    02270a
    +++ b/src/pcm/pcm_dshare.c
    02270a
    @@ -333,6 +333,7 @@ static int snd_pcm_dshare_reset(snd_pcm_t *pcm)
    02270a
     	snd_pcm_direct_t *dshare = pcm->private_data;
    02270a
     	dshare->hw_ptr %= pcm->period_size;
    02270a
     	dshare->appl_ptr = dshare->last_appl_ptr = dshare->hw_ptr;
    02270a
    +	dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr;
    02270a
     	snd_pcm_direct_reset_slave_ptr(pcm, dshare);
    02270a
     	return 0;
    02270a
     }
    02270a
    @@ -342,6 +343,7 @@ static int snd_pcm_dshare_start_timer(snd_pcm_t *pcm, snd_pcm_direct_t *dshare)
    02270a
     	int err;
    02270a
     
    02270a
     	snd_pcm_hwsync(dshare->spcm);
    02270a
    +	dshare->slave_appl_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr;
    02270a
     	snd_pcm_direct_reset_slave_ptr(pcm, dshare);
    02270a
     	err = snd_timer_start(dshare->timer);
    02270a
     	if (err < 0)
    02270a
    diff --git a/src/pcm/pcm_dsnoop.c b/src/pcm/pcm_dsnoop.c
    02270a
    index d08b6241..58b1e534 100644
    02270a
    --- a/src/pcm/pcm_dsnoop.c
    02270a
    +++ b/src/pcm/pcm_dsnoop.c
    02270a
    @@ -278,6 +278,7 @@ static int snd_pcm_dsnoop_reset(snd_pcm_t *pcm)
    02270a
     	dsnoop->hw_ptr %= pcm->period_size;
    02270a
     	dsnoop->appl_ptr = dsnoop->hw_ptr;
    02270a
     	dsnoop->slave_appl_ptr = dsnoop->slave_hw_ptr;
    02270a
    +	snd_pcm_direct_reset_slave_ptr(pcm, dsnoop);
    02270a
     	return 0;
    02270a
     }
    02270a
     
    02270a
    @@ -285,12 +286,13 @@ static int snd_pcm_dsnoop_start(snd_pcm_t *pcm)
    02270a
     {
    02270a
     	snd_pcm_direct_t *dsnoop = pcm->private_data;
    02270a
     	int err;
    02270a
    -	
    02270a
    +
    02270a
     	if (dsnoop->state != SND_PCM_STATE_PREPARED)
    02270a
     		return -EBADFD;
    02270a
     	snd_pcm_hwsync(dsnoop->spcm);
    02270a
     	snoop_timestamp(pcm);
    02270a
     	dsnoop->slave_appl_ptr = dsnoop->slave_hw_ptr;
    02270a
    +	snd_pcm_direct_reset_slave_ptr(pcm, dsnoop);
    02270a
     	err = snd_timer_start(dsnoop->timer);
    02270a
     	if (err < 0)
    02270a
     		return err;
    02270a
    @@ -627,6 +629,7 @@ int snd_pcm_dsnoop_open(snd_pcm_t **pcmp, const char *name,
    02270a
     	dsnoop->max_periods = opts->max_periods;
    02270a
     	dsnoop->var_periodsize = opts->var_periodsize;
    02270a
     	dsnoop->sync_ptr = snd_pcm_dsnoop_sync_ptr;
    02270a
    +	dsnoop->hw_ptr_alignment = opts->hw_ptr_alignment;
    02270a
     
    02270a
      retry:
    02270a
     	if (first_instance) {
    02270a
    @@ -771,6 +774,12 @@ pcm.name {
    02270a
     	ipc_key INT		# unique IPC key
    02270a
     	ipc_key_add_uid BOOL	# add current uid to unique IPC key
    02270a
     	ipc_perm INT		# IPC permissions (octal, default 0600)
    02270a
    +	hw_ptr_alignment STR	# Slave application and hw pointer alignment type
    02270a
    +		# STR can be one of the below strings :
    02270a
    +		# no
    02270a
    +		# roundup
    02270a
    +		# rounddown
    02270a
    +		# auto (default)
    02270a
     	slave STR
    02270a
     	# or
    02270a
     	slave {			# Slave definition
    02270a
    @@ -795,6 +804,25 @@ pcm.name {
    02270a
     }
    02270a
     \endcode
    02270a
     
    02270a
    +hw_ptr_alignment specifies slave application and hw
    02270a
    +pointer alignment type. By default hw_ptr_alignment is auto. Below are
    02270a
    +the possible configurations:
    02270a
    +- no: minimal latency with minimal frames dropped at startup. But
    02270a
    +  wakeup of application (return from snd_pcm_wait() or poll()) can
    02270a
    +  take up to 2 * period.
    02270a
    +- roundup: It is guaranteed that all frames will be played at
    02270a
    +  startup. But the latency will increase upto period-1 frames.
    02270a
    +- rounddown: It is guaranteed that a wakeup will happen for each
    02270a
    +  period and frames can be written from application. But on startup
    02270a
    +  upto period-1 frames will be dropped.
    02270a
    +- auto: Selects the best approach depending on the used period and
    02270a
    +  buffer size.
    02270a
    +  If the application buffer size is < 2 * application period,
    02270a
    +  "roundup" will be selected to avoid over runs. If the slave_period
    02270a
    +  is < 10ms we could expect that there are low latency
    02270a
    +  requirements. Therefore "rounddown" will be chosen to avoid long
    02270a
    +  wakeup times. Else "no" will be chosen.
    02270a
    +
    02270a
     \subsection pcm_plugins_dsnoop_funcref Function reference
    02270a
     
    02270a
     
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 5f2e5af61b0b8cfbf310e8b1e08a034d993e432f Mon Sep 17 00:00:00 2001
      02270a
      From: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Date: Tue, 21 May 2019 15:32:47 +0200
      02270a
      Subject: [PATCH 04/25] pcm: file: add support for infile reading in non
      02270a
       interleaved mode
      02270a
      02270a
      add helper function to copy input file data to buffer mapped by areas,
      02270a
      in case of an error, do not fill the areas, allowing device read buffer
      02270a
      to be provided to api caller
      02270a
      02270a
      previously unused rbuf variable is reused for this purpose
      02270a
      02270a
      Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Reviewed-by: Timo Wischer <twischer@de.adit-jv.com>
      02270a
      Signed-off-by: Takashi Iwai <tiwai@suse.de>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 67 ++++++++++++++++++++++++++++++++++++++--------
      02270a
       1 file changed, 56 insertions(+), 11 deletions(-)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index 3a19cef9..3c682659 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -77,6 +77,7 @@ typedef struct {
      02270a
       	snd_pcm_uframes_t appl_ptr;
      02270a
       	snd_pcm_uframes_t file_ptr_bytes;
      02270a
       	snd_pcm_uframes_t wbuf_size;
      02270a
      +	snd_pcm_uframes_t rbuf_size;
      02270a
       	size_t wbuf_size_bytes;
      02270a
       	size_t wbuf_used_bytes;
      02270a
       	char *wbuf;
      02270a
      @@ -266,6 +267,39 @@ static int snd_pcm_file_open_output_file(snd_pcm_file_t *file)
      02270a
       	return 0;
      02270a
       }
      02270a
       
      02270a
      +/* fill areas with data from input file, return bytes red */
      02270a
      +static int snd_pcm_file_areas_read_infile(snd_pcm_t *pcm,
      02270a
      +					  const snd_pcm_channel_area_t *areas,
      02270a
      +					  snd_pcm_uframes_t offset,
      02270a
      +					  snd_pcm_uframes_t frames)
      02270a
      +{
      02270a
      +	snd_pcm_file_t *file = pcm->private_data;
      02270a
      +	snd_pcm_channel_area_t areas_if[pcm->channels];
      02270a
      +	ssize_t bytes;
      02270a
      +
      02270a
      +	if (file->ifd < 0)
      02270a
      +		return -EBADF;
      02270a
      +
      02270a
      +	if (file->rbuf == NULL)
      02270a
      +		return -ENOMEM;
      02270a
      +
      02270a
      +	if (file->rbuf_size < frames) {
      02270a
      +		SYSERR("requested more frames than pcm buffer");
      02270a
      +		return -ENOMEM;
      02270a
      +	}
      02270a
      +
      02270a
      +	bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm, frames));
      02270a
      +	if (bytes < 0) {
      02270a
      +		SYSERR("read from file failed, error: %d", bytes);
      02270a
      +		return bytes;
      02270a
      +	}
      02270a
      +
      02270a
      +	snd_pcm_areas_from_buf(pcm, areas_if, file->rbuf);
      02270a
      +	snd_pcm_areas_copy(areas, offset, areas_if, 0, pcm->channels, snd_pcm_bytes_to_frames(pcm, bytes), pcm->format);
      02270a
      +
      02270a
      +	return bytes;
      02270a
      +}
      02270a
      +
      02270a
       static void setup_wav_header(snd_pcm_t *pcm, struct wav_fmt *fmt)
      02270a
       {
      02270a
       	fmt->fmt = TO_LE16(0x01);
      02270a
      @@ -568,19 +602,19 @@ static snd_pcm_sframes_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, snd_pcm
      02270a
       {
      02270a
       	snd_pcm_file_t *file = pcm->private_data;
      02270a
       	snd_pcm_channel_area_t areas[pcm->channels];
      02270a
      -	snd_pcm_sframes_t n;
      02270a
      +	snd_pcm_sframes_t frames;
      02270a
       
      02270a
      -	if (file->ifd >= 0) {
      02270a
      -		SNDERR("DEBUG: Noninterleaved read not yet implemented.\n");
      02270a
      -		return 0;	/* TODO: Noninterleaved read */
      02270a
      -	}
      02270a
      +	__snd_pcm_lock(pcm);
      02270a
      +	frames = _snd_pcm_readn(file->gen.slave, bufs, size);
      02270a
      +	if (frames <= 0)
      02270a
      +		return frames;
      02270a
       
      02270a
      -	n = _snd_pcm_readn(file->gen.slave, bufs, size);
      02270a
      -	if (n > 0) {
      02270a
      -		snd_pcm_areas_from_bufs(pcm, areas, bufs);
      02270a
      -		snd_pcm_file_add_frames(pcm, areas, 0, n);
      02270a
      -	}
      02270a
      -	return n;
      02270a
      +	snd_pcm_areas_from_bufs(pcm, areas, bufs);
      02270a
      +	snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
      02270a
      +	snd_pcm_file_add_frames(pcm, areas, 0, frames);
      02270a
      +
      02270a
      +	__snd_pcm_unlock(pcm);
      02270a
      +	return frames;
      02270a
       }
      02270a
       
      02270a
       static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
      02270a
      @@ -609,9 +643,11 @@ static int snd_pcm_file_hw_free(snd_pcm_t *pcm)
      02270a
       	free(file->wbuf);
      02270a
       	free(file->wbuf_areas);
      02270a
       	free(file->final_fname);
      02270a
      +	free(file->rbuf);
      02270a
       	file->wbuf = NULL;
      02270a
       	file->wbuf_areas = NULL;
      02270a
       	file->final_fname = NULL;
      02270a
      +	file->rbuf = NULL;
      02270a
       	return snd_pcm_hw_free(file->gen.slave);
      02270a
       }
      02270a
       
      02270a
      @@ -638,6 +674,15 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
      02270a
       		snd_pcm_file_hw_free(pcm);
      02270a
       		return -ENOMEM;
      02270a
       	}
      02270a
      +	assert(!file->rbuf);
      02270a
      +	file->rbuf_size = slave->buffer_size;
      02270a
      +	file->rbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->rbuf_size);
      02270a
      +	file->rbuf_used_bytes = 0;
      02270a
      +	file->rbuf = malloc(file->rbuf_size_bytes);
      02270a
      +	if (file->rbuf == NULL) {
      02270a
      +		snd_pcm_file_hw_free(pcm);
      02270a
      +		return -ENOMEM;
      02270a
      +	}
      02270a
       	file->appl_ptr = file->file_ptr_bytes = 0;
      02270a
       	for (channel = 0; channel < slave->channels; ++channel) {
      02270a
       		snd_pcm_channel_area_t *a = &file->wbuf_areas[channel];
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 349b42f5477c904fa3e10bac2fa2429fad2cbc65 Mon Sep 17 00:00:00 2001
      02270a
      From: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Date: Tue, 21 May 2019 15:33:08 +0200
      02270a
      Subject: [PATCH 05/25] pcm: file: use snd_pcm_file_areas_read_infile for readi
      02270a
      02270a
      use previously introduced helper function, this commit unifies behavior
      02270a
      of readi and readn
      02270a
      02270a
      corner case behavior of readi is changed by this commit, previously,
      02270a
      in case 0 bytes were red from file (EOF), frames = 0 was returned,
      02270a
      signaling api user as if no data was red from slave, after the patch,
      02270a
      amount of frames red from slave with data red from slave stored in buffer
      02270a
      is returned when EOF is reached
      02270a
      02270a
      Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Reviewed-by: Timo Wischer <twischer@de.adit-jv.com>
      02270a
      Signed-off-by: Takashi Iwai <tiwai@suse.de>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 27 +++++++++++++--------------
      02270a
       1 file changed, 13 insertions(+), 14 deletions(-)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index 3c682659..dcaa41d1 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -579,22 +579,21 @@ static snd_pcm_sframes_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, snd_pc
      02270a
       {
      02270a
       	snd_pcm_file_t *file = pcm->private_data;
      02270a
       	snd_pcm_channel_area_t areas[pcm->channels];
      02270a
      -	snd_pcm_sframes_t n;
      02270a
      +	snd_pcm_sframes_t frames;
      02270a
      +
      02270a
      +	__snd_pcm_lock(pcm);
      02270a
      +
      02270a
      +	frames = _snd_pcm_readi(file->gen.slave, buffer, size);
      02270a
      +	if (frames <= 0)
      02270a
      +		return frames;
      02270a
       
      02270a
      -	n = _snd_pcm_readi(file->gen.slave, buffer, size);
      02270a
      -	if (n <= 0)
      02270a
      -		return n;
      02270a
      -	if (file->ifd >= 0) {
      02270a
      -		__snd_pcm_lock(pcm);
      02270a
      -		n = read(file->ifd, buffer, n * pcm->frame_bits / 8);
      02270a
      -		__snd_pcm_unlock(pcm);
      02270a
      -		if (n < 0)
      02270a
      -			return n;
      02270a
      -		n = n * 8 / pcm->frame_bits;
      02270a
      -	}
      02270a
       	snd_pcm_areas_from_buf(pcm, areas, buffer);
      02270a
      -	snd_pcm_file_add_frames(pcm, areas, 0, n);
      02270a
      -	return n;
      02270a
      +	snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
      02270a
      +	snd_pcm_file_add_frames(pcm, areas, 0, frames);
      02270a
      +
      02270a
      +	__snd_pcm_unlock(pcm);
      02270a
      +
      02270a
      +	return frames;
      02270a
       }
      02270a
       
      02270a
       /* locking */
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 33c7ea0865b7f87cef1c3d3e767734c0edd02e84 Mon Sep 17 00:00:00 2001
      02270a
      From: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Date: Thu, 23 May 2019 11:44:30 +0200
      02270a
      Subject: [PATCH 06/25] pcm: file: add missing unlock on early return
      02270a
      02270a
      Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Signed-off-by: Takashi Iwai <tiwai@suse.de>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 8 ++++++--
      02270a
       1 file changed, 6 insertions(+), 2 deletions(-)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index dcaa41d1..8e2c70b1 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -584,8 +584,10 @@ static snd_pcm_sframes_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, snd_pc
      02270a
       	__snd_pcm_lock(pcm);
      02270a
       
      02270a
       	frames = _snd_pcm_readi(file->gen.slave, buffer, size);
      02270a
      -	if (frames <= 0)
      02270a
      +	if (frames <= 0) {
      02270a
      +		__snd_pcm_unlock(pcm);
      02270a
       		return frames;
      02270a
      +	}
      02270a
       
      02270a
       	snd_pcm_areas_from_buf(pcm, areas, buffer);
      02270a
       	snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
      02270a
      @@ -605,8 +607,10 @@ static snd_pcm_sframes_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, snd_pcm
      02270a
       
      02270a
       	__snd_pcm_lock(pcm);
      02270a
       	frames = _snd_pcm_readn(file->gen.slave, bufs, size);
      02270a
      -	if (frames <= 0)
      02270a
      +	if (frames <= 0) {
      02270a
      +		__snd_pcm_unlock(pcm);
      02270a
       		return frames;
      02270a
      +	}
      02270a
       
      02270a
       	snd_pcm_areas_from_bufs(pcm, areas, bufs);
      02270a
       	snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 108a2f43791fe769fd58726881b12ad908ebd2e0 Mon Sep 17 00:00:00 2001
      02270a
      From: Takashi Iwai <tiwai@suse.de>
      02270a
      Date: Thu, 18 Apr 2019 20:40:18 +0200
      02270a
      Subject: [PATCH 07/25] ucm: Add UCM profile for CX2072X codec on
      02270a
       Baytrail/Cherrytrail profiles
      02270a
      02270a
      Adding a new Conexant CX2072X codec profile and reusing the existing
      02270a
      BYT/CHT platform snippets.
      02270a
      02270a
      Currently tested only on ASUS E200HA laptop.
      02270a
      02270a
      Signed-off-by: Takashi Iwai <tiwai@suse.de>
      02270a
      ---
      02270a
       configure.ac                                  |  2 ++
      02270a
       src/conf/ucm/Makefile.am                      |  1 +
      02270a
       src/conf/ucm/bytcht-cx2072x/HiFi.conf         | 24 ++++++++++++++++++
      02270a
       src/conf/ucm/bytcht-cx2072x/Makefile.am       |  4 +++
      02270a
       .../ucm/bytcht-cx2072x/bytcht-cx2072x.conf    |  8 ++++++
      02270a
       src/conf/ucm/codecs/Makefile.am               |  1 +
      02270a
       src/conf/ucm/codecs/cx2072x/DisableSeq.conf   |  7 ++++++
      02270a
       src/conf/ucm/codecs/cx2072x/EnableSeq.conf    | 13 ++++++++++
      02270a
       src/conf/ucm/codecs/cx2072x/HeadPhones.conf   | 24 ++++++++++++++++++
      02270a
       src/conf/ucm/codecs/cx2072x/HeadsetMic.conf   | 25 +++++++++++++++++++
      02270a
       src/conf/ucm/codecs/cx2072x/InternalMic.conf  | 24 ++++++++++++++++++
      02270a
       src/conf/ucm/codecs/cx2072x/Makefile.am       |  6 +++++
      02270a
       src/conf/ucm/codecs/cx2072x/Speaker.conf      | 23 +++++++++++++++++
      02270a
       13 files changed, 162 insertions(+)
      02270a
       create mode 100644 src/conf/ucm/bytcht-cx2072x/HiFi.conf
      02270a
       create mode 100644 src/conf/ucm/bytcht-cx2072x/Makefile.am
      02270a
       create mode 100644 src/conf/ucm/bytcht-cx2072x/bytcht-cx2072x.conf
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/DisableSeq.conf
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/EnableSeq.conf
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/HeadPhones.conf
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/HeadsetMic.conf
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/InternalMic.conf
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/Makefile.am
      02270a
       create mode 100644 src/conf/ucm/codecs/cx2072x/Speaker.conf
      02270a
      02270a
      diff --git a/configure.ac b/configure.ac
      02270a
      index 0fb34de4..2e955760 100644
      02270a
      --- a/configure.ac
      02270a
      +++ b/configure.ac
      02270a
      @@ -720,6 +720,7 @@ AC_OUTPUT(Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg \
      02270a
       	  src/conf/ucm/ASUSTeKCOMPUTERINC.-T100HAN-1.0-T100HAN/Makefile \
      02270a
       	  src/conf/ucm/broadwell-rt286/Makefile \
      02270a
       	  src/conf/ucm/broxton-rt298/Makefile \
      02270a
      +	  src/conf/ucm/bytcht-cx2072x/Makefile \
      02270a
       	  src/conf/ucm/bytcht-es8316/Makefile \
      02270a
       	  src/conf/ucm/bytcht-es8316-mono-spk-in1-mic/Makefile \
      02270a
       	  src/conf/ucm/bytcht-es8316-mono-spk-in2-mic/Makefile \
      02270a
      @@ -765,6 +766,7 @@ AC_OUTPUT(Makefile doc/Makefile doc/pictures/Makefile doc/doxygen.cfg \
      02270a
       	  src/conf/ucm/tegraalc5632/Makefile \
      02270a
       	  src/conf/ucm/VEYRON-I2S/Makefile \
      02270a
       	  src/conf/ucm/codecs/Makefile \
      02270a
      +	  src/conf/ucm/codecs/cx2072x/Makefile \
      02270a
       	  src/conf/ucm/codecs/es8316/Makefile \
      02270a
       	  src/conf/ucm/codecs/nau8824/Makefile \
      02270a
       	  src/conf/ucm/codecs/rt5640/Makefile \
      02270a
      diff --git a/src/conf/ucm/Makefile.am b/src/conf/ucm/Makefile.am
      02270a
      index e9f88ed6..02257048 100644
      02270a
      --- a/src/conf/ucm/Makefile.am
      02270a
      +++ b/src/conf/ucm/Makefile.am
      02270a
      @@ -4,6 +4,7 @@ platforms \
      02270a
       ASUSTeKCOMPUTERINC.-T100HAN-1.0-T100HAN \
      02270a
       broadwell-rt286 \
      02270a
       broxton-rt298 \
      02270a
      +bytcht-cx2072x \
      02270a
       bytcht-es8316 \
      02270a
       bytcht-es8316-mono-spk-in1-mic \
      02270a
       bytcht-es8316-mono-spk-in2-mic \
      02270a
      diff --git a/src/conf/ucm/bytcht-cx2072x/HiFi.conf b/src/conf/ucm/bytcht-cx2072x/HiFi.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..e9c1f757
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/bytcht-cx2072x/HiFi.conf
      02270a
      @@ -0,0 +1,24 @@
      02270a
      +SectionVerb {
      02270a
      +	EnableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		<platforms/bytcr/PlatformEnableSeq.conf>
      02270a
      +		<codecs/cx2072x/EnableSeq.conf>
      02270a
      +	]
      02270a
      +
      02270a
      +	DisableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		<codecs/cx2072x/DisableSeq.conf>
      02270a
      +		<platforms/bytcr/PlatformDisableSeq.conf>
      02270a
      +	]
      02270a
      +
      02270a
      +	Value {
      02270a
      +		PlaybackPCM "hw:bytchtcx2072x"
      02270a
      +		CapturePCM "hw:bytchtcx2072x"
      02270a
      +	}
      02270a
      +}
      02270a
      +
      02270a
      +<codecs/cx2072x/Speaker.conf>
      02270a
      +<codecs/cx2072x/HeadPhones.conf>
      02270a
      +
      02270a
      +<codecs/cx2072x/InternalMic.conf>
      02270a
      +<codecs/cx2072x/HeadsetMic.conf>
      02270a
      diff --git a/src/conf/ucm/bytcht-cx2072x/Makefile.am b/src/conf/ucm/bytcht-cx2072x/Makefile.am
      02270a
      new file mode 100644
      02270a
      index 00000000..373b2a77
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/bytcht-cx2072x/Makefile.am
      02270a
      @@ -0,0 +1,4 @@
      02270a
      +alsaconfigdir = @ALSA_CONFIG_DIR@
      02270a
      +ucmdir = $(alsaconfigdir)/ucm/bytcht-cx2072x
      02270a
      +ucm_DATA = bytcht-cx2072x.conf HiFi.conf
      02270a
      +EXTRA_DIST = $(ucm_DATA)
      02270a
      diff --git a/src/conf/ucm/bytcht-cx2072x/bytcht-cx2072x.conf b/src/conf/ucm/bytcht-cx2072x/bytcht-cx2072x.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..fce04456
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/bytcht-cx2072x/bytcht-cx2072x.conf
      02270a
      @@ -0,0 +1,8 @@
      02270a
      +SectionUseCase."HiFi" {
      02270a
      +	File "HiFi.conf"
      02270a
      +	Comment "Play HiFi quality Music"
      02270a
      +}
      02270a
      +
      02270a
      +SectionDefaults [
      02270a
      +	cdev "hw:bytchtcx2072x"
      02270a
      +]
      02270a
      diff --git a/src/conf/ucm/codecs/Makefile.am b/src/conf/ucm/codecs/Makefile.am
      02270a
      index f78fd081..5987b9cf 100644
      02270a
      --- a/src/conf/ucm/codecs/Makefile.am
      02270a
      +++ b/src/conf/ucm/codecs/Makefile.am
      02270a
      @@ -1,4 +1,5 @@
      02270a
       SUBDIRS=\
      02270a
      +cx2072x \
      02270a
       es8316 \
      02270a
       rt5640 \
      02270a
       rt5645 \
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/DisableSeq.conf b/src/conf/ucm/codecs/cx2072x/DisableSeq.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..1e3d5489
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/DisableSeq.conf
      02270a
      @@ -0,0 +1,7 @@
      02270a
      +# Output Configuration
      02270a
      +cset "name='I2S DAC1L Switch' off"
      02270a
      +cset "name='I2S DAC1R Switch' off"
      02270a
      +
      02270a
      +# Input Configuration
      02270a
      +cset "name='I2S ADC1L Switch' off"
      02270a
      +cset "name='I2S ADC1R Switch' off"
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/EnableSeq.conf b/src/conf/ucm/codecs/cx2072x/EnableSeq.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..fb8e3fe2
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/EnableSeq.conf
      02270a
      @@ -0,0 +1,13 @@
      02270a
      +# Disable all inputs / outputs
      02270a
      +cset "name='Ext Spk Switch' off"
      02270a
      +cset "name='Headphone Switch' off"
      02270a
      +cset "name='Headset Mic Switch' off"
      02270a
      +cset "name='Int Mic Switch' off"
      02270a
      +
      02270a
      +# Output Configuration
      02270a
      +cset "name='I2S DAC1L Switch' on"
      02270a
      +cset "name='I2S DAC1R Switch' on"
      02270a
      +
      02270a
      +# Input Configuration
      02270a
      +cset "name='I2S ADC1L Switch' on"
      02270a
      +cset "name='I2S ADC1R Switch' on"
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/HeadPhones.conf b/src/conf/ucm/codecs/cx2072x/HeadPhones.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..4e3ff950
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/HeadPhones.conf
      02270a
      @@ -0,0 +1,24 @@
      02270a
      +SectionDevice."Headphones" {
      02270a
      +	Comment "Headphones"
      02270a
      +
      02270a
      +	ConflictingDevice [
      02270a
      +		"Speaker"
      02270a
      +	]
      02270a
      +
      02270a
      +	EnableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Headphone Switch' on"
      02270a
      +		cset "name='PortA Out En Switch' on"
      02270a
      +	]
      02270a
      +
      02270a
      +	DisableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Headphone Switch' off"
      02270a
      +		cset "name='PortA Out En Switch' off"
      02270a
      +	]
      02270a
      +
      02270a
      +	Value {
      02270a
      +		PlaybackChannels "2"
      02270a
      +		JackControl "Headphone Jack"
      02270a
      +	}
      02270a
      +}
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/HeadsetMic.conf b/src/conf/ucm/codecs/cx2072x/HeadsetMic.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..26b8df16
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/HeadsetMic.conf
      02270a
      @@ -0,0 +1,25 @@
      02270a
      +SectionDevice."HeadsetMic" {
      02270a
      +	Comment "Headset Microphone"
      02270a
      +
      02270a
      +	ConflictingDevice [
      02270a
      +		"InternalMic"
      02270a
      +	]
      02270a
      +
      02270a
      +	EnableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Headset Mic Switch' on"
      02270a
      +		cset "name='ADC1 Mux' 'PortD Switch'"
      02270a
      +		cset "name='PortD In En Switch' on"
      02270a
      +	]
      02270a
      +
      02270a
      +	DisableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Headset Mic Switch' off"
      02270a
      +		cset "name='PortD In En Switch' off"
      02270a
      +	]
      02270a
      +
      02270a
      +	Value {
      02270a
      +		CaptureChannels "2"
      02270a
      +		JackControl "Headset Mic Jack"
      02270a
      +	}
      02270a
      +}
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/InternalMic.conf b/src/conf/ucm/codecs/cx2072x/InternalMic.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..a3e14538
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/InternalMic.conf
      02270a
      @@ -0,0 +1,24 @@
      02270a
      +SectionDevice."InternalMic" {
      02270a
      +	Comment "Internal Microphone"
      02270a
      +
      02270a
      +	ConflictingDevice [
      02270a
      +		"HeadsetMic"
      02270a
      +	]
      02270a
      +
      02270a
      +	EnableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Int Mic Switch' on"
      02270a
      +		cset "name='ADC1 Mux' 'PortC Switch'"
      02270a
      +		cset "name='PortC In En Switch' on"
      02270a
      +	]
      02270a
      +
      02270a
      +	DisableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Int Mic Switch' off"
      02270a
      +		cset "name='PortC In En Switch' off"
      02270a
      +	]
      02270a
      +
      02270a
      +	Value {
      02270a
      +		CaptureChannels "2"
      02270a
      +	}
      02270a
      +}
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/Makefile.am b/src/conf/ucm/codecs/cx2072x/Makefile.am
      02270a
      new file mode 100644
      02270a
      index 00000000..2990fd09
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/Makefile.am
      02270a
      @@ -0,0 +1,6 @@
      02270a
      +alsaconfigdir = @ALSA_CONFIG_DIR@
      02270a
      +ucmdir = $(alsaconfigdir)/ucm/codecs/cx2072x
      02270a
      +ucm_DATA = EnableSeq.conf DisableSeq.conf \
      02270a
      +	HeadPhones.conf Speaker.conf \
      02270a
      +	InternalMic.conf HeadsetMic.conf
      02270a
      +EXTRA_DIST = $(ucm_DATA)
      02270a
      diff --git a/src/conf/ucm/codecs/cx2072x/Speaker.conf b/src/conf/ucm/codecs/cx2072x/Speaker.conf
      02270a
      new file mode 100644
      02270a
      index 00000000..55e2b2ba
      02270a
      --- /dev/null
      02270a
      +++ b/src/conf/ucm/codecs/cx2072x/Speaker.conf
      02270a
      @@ -0,0 +1,23 @@
      02270a
      +SectionDevice."Speaker" {
      02270a
      +	Comment "Speakers"
      02270a
      +
      02270a
      +	ConflictingDevice [
      02270a
      +		"Headphones"
      02270a
      +	]
      02270a
      +
      02270a
      +	EnableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Ext Spk Switch' on"
      02270a
      +		cset "name='PortG Out En Switch' on"
      02270a
      +	]
      02270a
      +
      02270a
      +	DisableSequence [
      02270a
      +		cdev "hw:bytchtcx2072x"
      02270a
      +		cset "name='Ext Spk Switch' off"
      02270a
      +		cset "name='PortG Out En Switch' off"
      02270a
      +	]
      02270a
      +
      02270a
      +	Value {
      02270a
      +		PlaybackChannels "2"
      02270a
      +	}
      02270a
      +}
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From e520f454803acfdb9af5cd7224129b37904eef4a Mon Sep 17 00:00:00 2001
      02270a
      From: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Date: Thu, 23 May 2019 15:00:39 +0200
      02270a
      Subject: [PATCH 08/25] pcm: add mmap_begin callback to snd_pcm_fast_ops_t api
      02270a
      02270a
      main motivation for adding the callback is to use it to enable operation
      02270a
      on mmaped buffer before user access for pcm_file plugin
      02270a
      02270a
      support for MMAP read access with masking by data from input file is not
      02270a
      implemented for pcm_file plugin, by adding this callback implementing
      02270a
      such feature can be done by rewriting next continuous portion of buffer
      02270a
      on each mmap_begin call
      02270a
      02270a
      plugins like softvol use pcm_plugin interface and overwrite the buffer by
      02270a
      looping around it in avail_update callback, this patch hopes to simplify
      02270a
      the task by adding new api callback, removing the need for rewriting
      02270a
      pcm_file (to use pcm_plugin callbacks) and careful checking when looping
      02270a
      around whole mmaped buffer
      02270a
      02270a
      Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Reviewed-by: Timo Wischer <twischer@de.adit-jv.com>
      02270a
      Signed-off-by: Takashi Iwai <tiwai@suse.de>
      02270a
      ---
      02270a
       src/pcm/pcm.c       | 6 ++++++
      02270a
       src/pcm/pcm_local.h | 1 +
      02270a
       2 files changed, 7 insertions(+)
      02270a
      02270a
      diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
      02270a
      index 3a71d79b..323926e1 100644
      02270a
      --- a/src/pcm/pcm.c
      02270a
      +++ b/src/pcm/pcm.c
      02270a
      @@ -7129,7 +7129,13 @@ int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
      02270a
       	snd_pcm_uframes_t f;
      02270a
       	snd_pcm_uframes_t avail;
      02270a
       	const snd_pcm_channel_area_t *xareas;
      02270a
      +
      02270a
       	assert(pcm && areas && offset && frames);
      02270a
      +
      02270a
      +	if (pcm->fast_ops->mmap_begin)
      02270a
      +		return pcm->fast_ops->mmap_begin(pcm->fast_op_arg, areas, offset, frames);
      02270a
      +
      02270a
      +	/* fallback for plugins that do not specify new callback */
      02270a
       	xareas = snd_pcm_mmap_areas(pcm);
      02270a
       	if (xareas == NULL)
      02270a
       		return -EBADFD;
      02270a
      diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h
      02270a
      index d52229d8..d5726eb2 100644
      02270a
      --- a/src/pcm/pcm_local.h
      02270a
      +++ b/src/pcm/pcm_local.h
      02270a
      @@ -184,6 +184,7 @@ typedef struct {
      02270a
       	int (*poll_descriptors)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space); /* locked */
      02270a
       	int (*poll_revents)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents); /* locked */
      02270a
       	int (*may_wait_for_avail_min)(snd_pcm_t *pcm, snd_pcm_uframes_t avail);
      02270a
      +	int (*mmap_begin)(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames); /* locked */
      02270a
       } snd_pcm_fast_ops_t;
      02270a
       
      02270a
       struct _snd_pcm {
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From fe7ff721a954c3f8c2183febc7c3fa5736357b67 Mon Sep 17 00:00:00 2001
      02270a
      From: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Date: Thu, 23 May 2019 15:00:40 +0200
      02270a
      Subject: [PATCH 09/25] pcm: file: add infile read support for mmap mode
      02270a
      02270a
      mmap_begin callback is used to copy data from input file to mmaped
      02270a
      buffer
      02270a
      02270a
      guard for corner use of api (multiple mmap_begin calls by user) is
      02270a
      introduced to check if next continuous buffer was already overwritten
      02270a
      02270a
      buffer is overwritten with input file data only in case of stream capture
      02270a
      02270a
      Signed-off-by: Adam Miartus <amiartus@de.adit-jv.com>
      02270a
      Reviewed-by: Timo Wischer <twischer@de.adit-jv.com>
      02270a
      Signed-off-by: Takashi Iwai <tiwai@suse.de>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 31 +++++++++++++++++++++++++++++++
      02270a
       1 file changed, 31 insertions(+)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index 8e2c70b1..52cc10a9 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -88,6 +88,7 @@ typedef struct {
      02270a
       	size_t buffer_bytes;
      02270a
       	struct wav_fmt wav_header;
      02270a
       	size_t filelen;
      02270a
      +	char ifmmap_overwritten;
      02270a
       } snd_pcm_file_t;
      02270a
       
      02270a
       #if __BYTE_ORDER == __LITTLE_ENDIAN
      02270a
      @@ -630,6 +631,8 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
      02270a
       	const snd_pcm_channel_area_t *areas;
      02270a
       	snd_pcm_sframes_t result;
      02270a
       
      02270a
      +	file->ifmmap_overwritten = 0;
      02270a
      +
      02270a
       	result = snd_pcm_mmap_begin(file->gen.slave, &areas, &ofs, &siz;;
      02270a
       	if (result >= 0) {
      02270a
       		assert(ofs == offset && siz == size);
      02270a
      @@ -640,6 +643,32 @@ static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
      02270a
       	return result;
      02270a
       }
      02270a
       
      02270a
      +static int snd_pcm_file_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
      02270a
      +	snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
      02270a
      +{
      02270a
      +	snd_pcm_file_t *file = pcm->private_data;
      02270a
      +	snd_pcm_channel_area_t areas_if[pcm->channels];
      02270a
      +	snd_pcm_uframes_t frames_if;
      02270a
      +	void *buffer = NULL;
      02270a
      +	int result;
      02270a
      +
      02270a
      +	result = snd_pcm_mmap_begin(file->gen.slave, areas, offset, frames);
      02270a
      +	if (result < 0)
      02270a
      +		return result;
      02270a
      +
      02270a
      +	if (pcm->stream != SND_PCM_STREAM_CAPTURE)
      02270a
      +		return result;
      02270a
      +
      02270a
      +	/* user may run mmap_begin without mmap_commit multiple times in row */
      02270a
      +	if (file->ifmmap_overwritten)
      02270a
      +		return result;
      02270a
      +	file->ifmmap_overwritten = 1;
      02270a
      +
      02270a
      +	snd_pcm_file_areas_read_infile(pcm, *areas, *offset, *frames);
      02270a
      +
      02270a
      +	return result;
      02270a
      +}
      02270a
      +
      02270a
       static int snd_pcm_file_hw_free(snd_pcm_t *pcm)
      02270a
       {
      02270a
       	snd_pcm_file_t *file = pcm->private_data;
      02270a
      @@ -666,6 +695,7 @@ static int snd_pcm_file_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
      02270a
       	file->wbuf_size = slave->buffer_size * 2;
      02270a
       	file->wbuf_size_bytes = snd_pcm_frames_to_bytes(slave, file->wbuf_size);
      02270a
       	file->wbuf_used_bytes = 0;
      02270a
      +	file->ifmmap_overwritten = 0;
      02270a
       	assert(!file->wbuf);
      02270a
       	file->wbuf = malloc(file->wbuf_size_bytes);
      02270a
       	if (file->wbuf == NULL) {
      02270a
      @@ -777,6 +807,7 @@ static const snd_pcm_fast_ops_t snd_pcm_file_fast_ops = {
      02270a
       	.poll_descriptors = snd_pcm_generic_poll_descriptors,
      02270a
       	.poll_revents = snd_pcm_generic_poll_revents,
      02270a
       	.htimestamp = snd_pcm_generic_htimestamp,
      02270a
      +	.mmap_begin = snd_pcm_file_mmap_begin,
      02270a
       };
      02270a
       
      02270a
       /**
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 47bc6d534102aca9cc2aed1b6bdd5633ef645a3f Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 10:27:25 +0200
      02270a
      Subject: [PATCH 10/25] aserver: fix resource leak coverity
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       aserver/aserver.c | 33 +++++++++++++++++++--------------
      02270a
       1 file changed, 19 insertions(+), 14 deletions(-)
      02270a
      02270a
      diff --git a/aserver/aserver.c b/aserver/aserver.c
      02270a
      index 066414d8..6d20f330 100644
      02270a
      --- a/aserver/aserver.c
      02270a
      +++ b/aserver/aserver.c
      02270a
      @@ -75,6 +75,7 @@ static int make_local_socket(const char *filename)
      02270a
       	if (bind(sock, (struct sockaddr *) addr, size) < 0) {
      02270a
       		int result = -errno;
      02270a
       		SYSERROR("bind failed");
      02270a
      +		close(sock);
      02270a
       		return result;
      02270a
       	}
      02270a
       
      02270a
      @@ -101,6 +102,7 @@ static int make_inet_socket(int port)
      02270a
       	if (bind(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
      02270a
       		int result = -errno;
      02270a
       		SYSERROR("bind failed");
      02270a
      +		close(sock);
      02270a
       		return result;
      02270a
       	}
      02270a
       
      02270a
      @@ -916,10 +918,9 @@ static int inet_handler(waiter_t *waiter, unsigned short events ATTRIBUTE_UNUSED
      02270a
       
      02270a
       static int server(const char *sockname, int port)
      02270a
       {
      02270a
      -	int err;
      02270a
      +	int err, result, sockn = -1, socki = -1;
      02270a
       	unsigned int k;
      02270a
       	long open_max;
      02270a
      -	int result;
      02270a
       
      02270a
       	if (!sockname && port < 0)
      02270a
       		return -EINVAL;
      02270a
      @@ -933,36 +934,36 @@ static int server(const char *sockname, int port)
      02270a
       	waiters = calloc((size_t) open_max, sizeof(*waiters));
      02270a
       
      02270a
       	if (sockname) {
      02270a
      -		int sock = make_local_socket(sockname);
      02270a
      -		if (sock < 0)
      02270a
      -			return sock;
      02270a
      -		if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
      02270a
      +		sockn = make_local_socket(sockname);
      02270a
      +		if (sockn < 0)
      02270a
      +			return sockn;
      02270a
      +		if (fcntl(sockn, F_SETFL, O_NONBLOCK) < 0) {
      02270a
       			result = -errno;
      02270a
       			SYSERROR("fcntl O_NONBLOCK failed");
      02270a
       			goto _end;
      02270a
       		}
      02270a
      -		if (listen(sock, 4) < 0) {
      02270a
      +		if (listen(sockn, 4) < 0) {
      02270a
       			result = -errno;
      02270a
       			SYSERROR("listen failed");
      02270a
       			goto _end;
      02270a
       		}
      02270a
      -		add_waiter(sock, POLLIN, local_handler, NULL);
      02270a
      +		add_waiter(sockn, POLLIN, local_handler, NULL);
      02270a
       	}
      02270a
       	if (port >= 0) {
      02270a
      -		int sock = make_inet_socket(port);
      02270a
      -		if (sock < 0)
      02270a
      -			return sock;
      02270a
      -		if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
      02270a
      +		socki = make_inet_socket(port);
      02270a
      +		if (socki < 0)
      02270a
      +			return socki;
      02270a
      +		if (fcntl(socki, F_SETFL, O_NONBLOCK) < 0) {
      02270a
       			result = -errno;
      02270a
       			SYSERROR("fcntl failed");
      02270a
       			goto _end;
      02270a
       		}
      02270a
      -		if (listen(sock, 4) < 0) {
      02270a
      +		if (listen(socki, 4) < 0) {
      02270a
       			result = -errno;
      02270a
       			SYSERROR("listen failed");
      02270a
       			goto _end;
      02270a
       		}
      02270a
      -		add_waiter(sock, POLLIN, inet_handler, NULL);
      02270a
      +		add_waiter(socki, POLLIN, inet_handler, NULL);
      02270a
       	}
      02270a
       
      02270a
       	while (1) {
      02270a
      @@ -991,6 +992,10 @@ static int server(const char *sockname, int port)
      02270a
       		}
      02270a
       	}
      02270a
        _end:
      02270a
      +	if (sockn >= 0)
      02270a
      +		close(sockn);
      02270a
      +	if (socki >= 0)
      02270a
      +		close(socki);
      02270a
       	free(pollfds);
      02270a
       	free(waiters);
      02270a
       	return result;
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 4aa960c48b4d292425597d283f3ef15d02590082 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 10:39:05 +0200
      02270a
      Subject: [PATCH 11/25] src/conf.c: add missing va_end() call (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/conf.c | 8 ++++++--
      02270a
       1 file changed, 6 insertions(+), 2 deletions(-)
      02270a
      02270a
      diff --git a/src/conf.c b/src/conf.c
      02270a
      index cda5518e..3a3c91bf 100644
      02270a
      --- a/src/conf.c
      02270a
      +++ b/src/conf.c
      02270a
      @@ -3034,8 +3034,10 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
      02270a
       		if (!k) \
      02270a
       			break; \
      02270a
       		err = fcn(config, k, &n); \
      02270a
      -		if (err < 0) \
      02270a
      +		if (err < 0) { \
      02270a
      +			va_end(arg); \
      02270a
       			return err; \
      02270a
      +		} \
      02270a
       		config = n; \
      02270a
       	} \
      02270a
       	va_end(arg); \
      02270a
      @@ -3056,8 +3058,10 @@ int snd_config_save(snd_config_t *config, snd_output_t *out)
      02270a
       		if (!k) \
      02270a
       			break; \
      02270a
       		err = fcn(root, config, k, &n); \
      02270a
      -		if (err < 0) \
      02270a
      +		if (err < 0) { \
      02270a
      +			va_end(arg); \
      02270a
       			return err; \
      02270a
      +		} \
      02270a
       		config = n; \
      02270a
       	} \
      02270a
       	va_end(arg); \
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 990b1a53ed800caac0bab1c2b7987205569861fe Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 10:44:49 +0200
      02270a
      Subject: [PATCH 12/25] config: parse_string() fix the dynamic buffer
      02270a
       allocation failure code (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/conf.c | 16 ++++++++++++----
      02270a
       1 file changed, 12 insertions(+), 4 deletions(-)
      02270a
      02270a
      diff --git a/src/conf.c b/src/conf.c
      02270a
      index 3a3c91bf..3e4b76a3 100644
      02270a
      --- a/src/conf.c
      02270a
      +++ b/src/conf.c
      02270a
      @@ -4747,8 +4747,11 @@ static int parse_string(const char **ptr, char **val)
      02270a
       			return -EINVAL;
      02270a
       		case '\\':
      02270a
       			c = parse_char(ptr);
      02270a
      -			if (c < 0)
      02270a
      +			if (c < 0) {
      02270a
      +				if (alloc > bufsize)
      02270a
      +					free(buf);
      02270a
       				return c;
      02270a
      +			}
      02270a
       			break;
      02270a
       		default:
      02270a
       			(*ptr)++;
      02270a
      @@ -4768,12 +4771,17 @@ static int parse_string(const char **ptr, char **val)
      02270a
       			alloc *= 2;
      02270a
       			if (old_alloc == bufsize) {
      02270a
       				buf = malloc(alloc);
      02270a
      +				if (!buf)
      02270a
      +					return -ENOMEM;
      02270a
       				memcpy(buf, _buf, old_alloc);
      02270a
       			} else {
      02270a
      -				buf = realloc(buf, alloc);
      02270a
      +				char *buf2 = realloc(buf, alloc);
      02270a
      +				if (!buf2) {
      02270a
      +					free(buf);
      02270a
      +					return -ENOMEM;
      02270a
      +				}
      02270a
      +				buf = buf2;
      02270a
       			}
      02270a
      -			if (!buf)
      02270a
      -				return -ENOMEM;
      02270a
       		}
      02270a
       		buf[idx++] = c;
      02270a
       	}
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 51881cacc05e7d5e3cc8fc1ec9a4ac93a6327703 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 10:51:47 +0200
      02270a
      Subject: [PATCH 13/25] control_shm: remove duplicate code (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/control/control_shm.c | 18 +++---------------
      02270a
       1 file changed, 3 insertions(+), 15 deletions(-)
      02270a
      02270a
      diff --git a/src/control/control_shm.c b/src/control/control_shm.c
      02270a
      index d7b41398..1d9de8b7 100644
      02270a
      --- a/src/control/control_shm.c
      02270a
      +++ b/src/control/control_shm.c
      02270a
      @@ -302,13 +302,9 @@ static int snd_ctl_shm_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
      02270a
       {
      02270a
       	snd_ctl_shm_t *shm = ctl->private_data;
      02270a
       	volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
      02270a
      -	int err;
      02270a
       	ctrl->u.pcm_prefer_subdevice = subdev;
      02270a
       	ctrl->cmd = SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE;
      02270a
      -	err = snd_ctl_shm_action(ctl);
      02270a
      -	if (err < 0)
      02270a
      -		return err;
      02270a
      -	return err;
      02270a
      +	return snd_ctl_shm_action(ctl);
      02270a
       }
      02270a
       
      02270a
       static int snd_ctl_shm_rawmidi_next_device(snd_ctl_t *ctl, int * device)
      02270a
      @@ -343,26 +339,18 @@ static int snd_ctl_shm_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev)
      02270a
       {
      02270a
       	snd_ctl_shm_t *shm = ctl->private_data;
      02270a
       	volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
      02270a
      -	int err;
      02270a
       	ctrl->u.rawmidi_prefer_subdevice = subdev;
      02270a
       	ctrl->cmd = SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE;
      02270a
      -	err = snd_ctl_shm_action(ctl);
      02270a
      -	if (err < 0)
      02270a
      -		return err;
      02270a
      -	return err;
      02270a
      +	return snd_ctl_shm_action(ctl);
      02270a
       }
      02270a
       
      02270a
       static int snd_ctl_shm_set_power_state(snd_ctl_t *ctl, unsigned int state)
      02270a
       {
      02270a
       	snd_ctl_shm_t *shm = ctl->private_data;
      02270a
       	volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
      02270a
      -	int err;
      02270a
       	ctrl->u.power_state = state;
      02270a
       	ctrl->cmd = SNDRV_CTL_IOCTL_POWER;
      02270a
      -	err = snd_ctl_shm_action(ctl);
      02270a
      -	if (err < 0)
      02270a
      -		return err;
      02270a
      -	return err;
      02270a
      +	return snd_ctl_shm_action(ctl);
      02270a
       }
      02270a
       
      02270a
       static int snd_ctl_shm_get_power_state(snd_ctl_t *ctl, unsigned int *state)
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From d6ba264038fde08baf5e62bdde2a5614792db5c8 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 10:53:09 +0200
      02270a
      Subject: [PATCH 14/25] control_shm: add missing socket close to the error path
      02270a
       (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/control/control_shm.c | 4 +++-
      02270a
       1 file changed, 3 insertions(+), 1 deletion(-)
      02270a
      02270a
      diff --git a/src/control/control_shm.c b/src/control/control_shm.c
      02270a
      index 1d9de8b7..40d42643 100644
      02270a
      --- a/src/control/control_shm.c
      02270a
      +++ b/src/control/control_shm.c
      02270a
      @@ -424,8 +424,10 @@ static int make_local_socket(const char *filename)
      02270a
       	addr->sun_family = AF_LOCAL;
      02270a
       	memcpy(addr->sun_path, filename, l);
      02270a
       
      02270a
      -	if (connect(sock, (struct sockaddr *) addr, size) < 0)
      02270a
      +	if (connect(sock, (struct sockaddr *) addr, size) < 0) {
      02270a
      +		close(sock);
      02270a
       		return -errno;
      02270a
      +	}
      02270a
       	return sock;
      02270a
       }
      02270a
       
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From d5a1cf35b710d255508e56ed19633e1fbf41a2d4 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 10:57:20 +0200
      02270a
      Subject: [PATCH 15/25] pcm: fix memory leak in _snd_pcm_parse_config_chmaps()
      02270a
       (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/pcm/pcm.c | 1 +
      02270a
       1 file changed, 1 insertion(+)
      02270a
      02270a
      diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
      02270a
      index 323926e1..fa51ca99 100644
      02270a
      --- a/src/pcm/pcm.c
      02270a
      +++ b/src/pcm/pcm.c
      02270a
      @@ -8391,6 +8391,7 @@ _snd_pcm_parse_config_chmaps(snd_config_t *conf)
      02270a
       			free(chmap);
      02270a
       			goto error;
      02270a
       		}
      02270a
      +		free(chmap);
      02270a
       		nums++;
      02270a
       	}
      02270a
       	return maps;
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 22ade9b8c150240a960ca683ee6d8f53ce8bc6ea Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 11:09:43 +0200
      02270a
      Subject: [PATCH 16/25] pcm_file: call pclose() correctly for popen()
      02270a
       (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 9 ++++++++-
      02270a
       1 file changed, 8 insertions(+), 1 deletion(-)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index 52cc10a9..99db3754 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -227,7 +227,14 @@ static int snd_pcm_file_open_output_file(snd_pcm_file_t *file)
      02270a
       					file->final_fname);
      02270a
       			return -errno;
      02270a
       		}
      02270a
      -		fd = fileno(pipe);
      02270a
      +		fd = dup(fileno(pipe));
      02270a
      +		err = -errno;
      02270a
      +		pclose(pipe);
      02270a
      +		if (fd < 0) {
      02270a
      +			SYSERR("unable to dup pipe file handle for command %s",
      02270a
      +					file->final_fname);
      02270a
      +			return err;
      02270a
      +		}
      02270a
       	} else {
      02270a
       		if (file->trunc)
      02270a
       			fd = open(file->final_fname, O_WRONLY|O_CREAT|O_TRUNC,
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 3ae743efea704c16c9464f38d502c23759b71245 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 11:11:46 +0200
      02270a
      Subject: [PATCH 17/25] pcm_hw: close file descriptor in the error path in
      02270a
       snd_pcm_hw_open() (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/pcm/pcm_hw.c | 3 +++
      02270a
       1 file changed, 3 insertions(+)
      02270a
      02270a
      diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c
      02270a
      index 91370a88..77d4dae1 100644
      02270a
      --- a/src/pcm/pcm_hw.c
      02270a
      +++ b/src/pcm/pcm_hw.c
      02270a
      @@ -1724,12 +1724,15 @@ int snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
      02270a
       		}
      02270a
       		if (info.subdevice != (unsigned int) subdevice) {
      02270a
       			close(fd);
      02270a
      +			fd = -1;
      02270a
       			goto __again;
      02270a
       		}
      02270a
       	}
      02270a
       	snd_ctl_close(ctl);
      02270a
       	return snd_pcm_hw_open_fd(pcmp, name, fd, sync_ptr_ioctl);
      02270a
              _err:
      02270a
      +	if (fd >= 0)
      02270a
      +		close(fd);
      02270a
       	snd_ctl_close(ctl);
      02270a
       	return ret;
      02270a
       }
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 8ab0393b42e08655a5fee0a8e84b3ba84932465b Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 20:31:24 +0200
      02270a
      Subject: [PATCH 18/25] rawmidi: use snd_dlobj_cache_get2() in rawmidi open
      02270a
       (coverity)
      02270a
      02270a
      Use proper reference counting for the dynamic symbol.
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       include/local.h             |  3 +++
      02270a
       src/dlmisc.c                | 41 +++++++++++++++++++++++++++++------
      02270a
       src/rawmidi/rawmidi.c       | 43 ++++++++++++++++---------------------
      02270a
       src/rawmidi/rawmidi_local.h |  2 +-
      02270a
       4 files changed, 57 insertions(+), 32 deletions(-)
      02270a
      02270a
      diff --git a/include/local.h b/include/local.h
      02270a
      index 5edad317..e8390df5 100644
      02270a
      --- a/include/local.h
      02270a
      +++ b/include/local.h
      02270a
      @@ -328,6 +328,8 @@ static inline int snd_open_device(const char *filename, int fmode)
      02270a
       /* make local functions really local */
      02270a
       #define snd_dlobj_cache_get \
      02270a
       	snd1_dlobj_cache_get
      02270a
      +#define snd_dlobj_cache_get2 \
      02270a
      +	snd1_dlobj_cache_get2
      02270a
       #define snd_dlobj_cache_put \
      02270a
       	snd1_dlobj_cache_put
      02270a
       #define snd_dlobj_cache_cleanup \
      02270a
      @@ -341,6 +343,7 @@ static inline int snd_open_device(const char *filename, int fmode)
      02270a
       
      02270a
       /* dlobj cache */
      02270a
       void *snd_dlobj_cache_get(const char *lib, const char *name, const char *version, int verbose);
      02270a
      +void *snd_dlobj_cache_get2(const char *lib, const char *name, const char *version, int verbose);
      02270a
       int snd_dlobj_cache_put(void *open_func);
      02270a
       void snd_dlobj_cache_cleanup(void);
      02270a
       
      02270a
      diff --git a/src/dlmisc.c b/src/dlmisc.c
      02270a
      index 012e61bc..8c8f3ff7 100644
      02270a
      --- a/src/dlmisc.c
      02270a
      +++ b/src/dlmisc.c
      02270a
      @@ -251,15 +251,15 @@ static inline void snd_dlobj_unlock(void) {}
      02270a
       
      02270a
       static LIST_HEAD(pcm_dlobj_list);
      02270a
       
      02270a
      -void *snd_dlobj_cache_get(const char *lib, const char *name,
      02270a
      -			  const char *version, int verbose)
      02270a
      +static struct dlobj_cache *
      02270a
      +snd_dlobj_cache_get0(const char *lib, const char *name,
      02270a
      +		     const char *version, int verbose)
      02270a
       {
      02270a
       	struct list_head *p;
      02270a
       	struct dlobj_cache *c;
      02270a
       	void *func, *dlobj;
      02270a
       	char errbuf[256];
      02270a
       
      02270a
      -	snd_dlobj_lock();
      02270a
       	list_for_each(p, &pcm_dlobj_list) {
      02270a
       		c = list_entry(p, struct dlobj_cache, list);
      02270a
       		if (c->lib && lib && strcmp(c->lib, lib) != 0)
      02270a
      @@ -270,9 +270,7 @@ void *snd_dlobj_cache_get(const char *lib, const char *name,
      02270a
       			continue;
      02270a
       		if (strcmp(c->name, name) == 0) {
      02270a
       			c->refcnt++;
      02270a
      -			func = c->func;
      02270a
      -			snd_dlobj_unlock();
      02270a
      -			return func;
      02270a
      +			return c;
      02270a
       		}
      02270a
       	}
      02270a
       
      02270a
      @@ -285,7 +283,6 @@ void *snd_dlobj_cache_get(const char *lib, const char *name,
      02270a
       			SNDERR("Cannot open shared library %s (%s)",
      02270a
       						lib ? lib : "[builtin]",
      02270a
       						errbuf);
      02270a
      -		snd_dlobj_unlock();
      02270a
       		return NULL;
      02270a
       	}
      02270a
       
      02270a
      @@ -314,6 +311,36 @@ void *snd_dlobj_cache_get(const char *lib, const char *name,
      02270a
       	c->dlobj = dlobj;
      02270a
       	c->func = func;
      02270a
       	list_add_tail(&c->list, &pcm_dlobj_list);
      02270a
      +	return c;
      02270a
      +}
      02270a
      +
      02270a
      +void *snd_dlobj_cache_get(const char *lib, const char *name,
      02270a
      +			  const char *version, int verbose)
      02270a
      +{
      02270a
      +	struct dlobj_cache *c;
      02270a
      +	void *func = NULL;
      02270a
      +
      02270a
      +	snd_dlobj_lock();
      02270a
      +	c = snd_dlobj_cache_get0(lib, name, version, verbose);
      02270a
      +	if (c)
      02270a
      +		func = c->func;
      02270a
      +	snd_dlobj_unlock();
      02270a
      +	return func;
      02270a
      +}
      02270a
      +
      02270a
      +void *snd_dlobj_cache_get2(const char *lib, const char *name,
      02270a
      +			   const char *version, int verbose)
      02270a
      +{
      02270a
      +	struct dlobj_cache *c;
      02270a
      +	void *func = NULL;
      02270a
      +
      02270a
      +	snd_dlobj_lock();
      02270a
      +	c = snd_dlobj_cache_get0(lib, name, version, verbose);
      02270a
      +	if (c) {
      02270a
      +		func = c->func;
      02270a
      +		/* double reference */
      02270a
      +		c->refcnt++;
      02270a
      +	}
      02270a
       	snd_dlobj_unlock();
      02270a
       	return func;
      02270a
       }
      02270a
      diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c
      02270a
      index 2f419142..1b5f8525 100644
      02270a
      --- a/src/rawmidi/rawmidi.c
      02270a
      +++ b/src/rawmidi/rawmidi.c
      02270a
      @@ -162,7 +162,7 @@ static int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp
      02270a
       				 snd_config_t *rawmidi_conf, int mode)
      02270a
       {
      02270a
       	const char *str;
      02270a
      -	char buf[256], errbuf[256];
      02270a
      +	char buf[256];
      02270a
       	int err;
      02270a
       	snd_config_t *conf, *type_conf = NULL;
      02270a
       	snd_config_iterator_t i, next;
      02270a
      @@ -174,7 +174,6 @@ static int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp
      02270a
       #ifndef PIC
      02270a
       	extern void *snd_rawmidi_open_symbols(void);
      02270a
       #endif
      02270a
      -	void *h = NULL;
      02270a
       	if (snd_config_get_type(rawmidi_conf) != SND_CONFIG_TYPE_COMPOUND) {
      02270a
       		if (name)
      02270a
       			SNDERR("Invalid type for RAWMIDI %s definition", name);
      02270a
      @@ -239,41 +238,37 @@ static int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp
      02270a
       #ifndef PIC
      02270a
       	snd_rawmidi_open_symbols();
      02270a
       #endif
      02270a
      -	h = INTERNAL(snd_dlopen)(lib, RTLD_NOW, errbuf, sizeof(errbuf));
      02270a
      -	if (h)
      02270a
      -		open_func = snd_dlsym(h, open_name, SND_DLSYM_VERSION(SND_RAWMIDI_DLSYM_VERSION));
      02270a
      -	err = 0;
      02270a
      -	if (!h) {
      02270a
      -		SNDERR("Cannot open shared library %s (%s)", lib, errbuf);
      02270a
      -		err = -ENOENT;
      02270a
      -	} else if (!open_func) {
      02270a
      -		SNDERR("symbol %s is not defined inside %s", open_name, lib);
      02270a
      -		snd_dlclose(h);
      02270a
      +	open_func = snd_dlobj_cache_get2(lib, open_name,
      02270a
      +			SND_DLSYM_VERSION(SND_RAWMIDI_DLSYM_VERSION), 1);
      02270a
      +	if (!open_func) {
      02270a
       		err = -ENXIO;
      02270a
      +		goto _err;
      02270a
       	}
      02270a
      -       _err:
      02270a
       	if (type_conf)
      02270a
       		snd_config_delete(type_conf);
      02270a
      -	if (err >= 0)
      02270a
      -		err = open_func(inputp, outputp, name, rawmidi_root, rawmidi_conf, mode);
      02270a
      -	if (err < 0) {
      02270a
      -		if (h)
      02270a
      -			snd_dlclose(h);
      02270a
      -		return err;
      02270a
      -	}
      02270a
      +	err = open_func(inputp, outputp, name, rawmidi_root, rawmidi_conf, mode);
      02270a
      +	if (err < 0)
      02270a
      +		goto _err;
      02270a
       	if (inputp) {
      02270a
      -		(*inputp)->dl_handle = h; h = NULL;
      02270a
      +		(*inputp)->open_func = open_func;
      02270a
       		snd_rawmidi_params_default(*inputp, &params);
      02270a
       		err = snd_rawmidi_params(*inputp, &params);
      02270a
       		assert(err >= 0);
      02270a
       	}
      02270a
       	if (outputp) {
      02270a
      -		(*outputp)->dl_handle = h;
      02270a
      +		(*outputp)->open_func = open_func;
      02270a
       		snd_rawmidi_params_default(*outputp, &params);
      02270a
       		err = snd_rawmidi_params(*outputp, &params);
      02270a
       		assert(err >= 0);
      02270a
       	}
      02270a
       	return 0;
      02270a
      +
      02270a
      +       _err:
      02270a
      +	if (open_func)
      02270a
      +		snd_dlobj_cache_put(open_func);
      02270a
      +	if (type_conf)
      02270a
      +		snd_config_delete(type_conf);
      02270a
      +	return err;
      02270a
       }
      02270a
       
      02270a
       static int snd_rawmidi_open_noupdate(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
      02270a
      @@ -350,8 +345,8 @@ int snd_rawmidi_close(snd_rawmidi_t *rawmidi)
      02270a
         	assert(rawmidi);
      02270a
       	err = rawmidi->ops->close(rawmidi);
      02270a
       	free(rawmidi->name);
      02270a
      -	if (rawmidi->dl_handle)
      02270a
      -		snd_dlclose(rawmidi->dl_handle);
      02270a
      +	if (rawmidi->open_func)
      02270a
      +		snd_dlobj_cache_put(rawmidi->open_func);
      02270a
       	free(rawmidi);
      02270a
       	return err;
      02270a
       }
      02270a
      diff --git a/src/rawmidi/rawmidi_local.h b/src/rawmidi/rawmidi_local.h
      02270a
      index d76b35a3..721e1ec9 100644
      02270a
      --- a/src/rawmidi/rawmidi_local.h
      02270a
      +++ b/src/rawmidi/rawmidi_local.h
      02270a
      @@ -37,7 +37,7 @@ typedef struct {
      02270a
       } snd_rawmidi_ops_t;
      02270a
       
      02270a
       struct _snd_rawmidi {
      02270a
      -	void *dl_handle;
      02270a
      +	void *open_func;
      02270a
       	char *name;
      02270a
       	snd_rawmidi_type_t type;
      02270a
       	snd_rawmidi_stream_t stream;
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 6efa23f2837a6fa9982b4f34b837401a66941ee3 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 20:45:26 +0200
      02270a
      Subject: [PATCH 19/25] rawmidi_hw: add sanity check for the invalid stream
      02270a
       arguments (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/rawmidi/rawmidi_hw.c | 2 ++
      02270a
       1 file changed, 2 insertions(+)
      02270a
      02270a
      diff --git a/src/rawmidi/rawmidi_hw.c b/src/rawmidi/rawmidi_hw.c
      02270a
      index 7cc8c0d1..eaa8a76d 100644
      02270a
      --- a/src/rawmidi/rawmidi_hw.c
      02270a
      +++ b/src/rawmidi/rawmidi_hw.c
      02270a
      @@ -186,6 +186,8 @@ int snd_rawmidi_hw_open(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
      02270a
       		*inputp = NULL;
      02270a
       	if (outputp)
      02270a
       		*outputp = NULL;
      02270a
      +	if (!inputp && !outputp)
      02270a
      +		return -EINVAL;
      02270a
       	
      02270a
       	if ((ret = snd_ctl_hw_open(&ctl, NULL, card, 0)) < 0)
      02270a
       		return ret;
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 0d97f53c25b4dd36d3f6511fae85b597aebc61a1 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 20:52:00 +0200
      02270a
      Subject: [PATCH 20/25] topology: various coverity fixes
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/topology/ctl.c    |  4 ++--
      02270a
       src/topology/data.c   | 19 +++++++++++++------
      02270a
       src/topology/parser.c |  5 +++--
      02270a
       3 files changed, 18 insertions(+), 10 deletions(-)
      02270a
      02270a
      diff --git a/src/topology/ctl.c b/src/topology/ctl.c
      02270a
      index 9c13b12c..a0962522 100644
      02270a
      --- a/src/topology/ctl.c
      02270a
      +++ b/src/topology/ctl.c
      02270a
      @@ -880,8 +880,8 @@ int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl,
      02270a
       	if (enum_ctl->texts != NULL) {
      02270a
       		for (i = 0; i < num_items; i++) {
      02270a
       			if (enum_ctl->texts[i] != NULL)
      02270a
      -				strncpy(ec->texts[i], enum_ctl->texts[i],
      02270a
      -					SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
      02270a
      +				snd_strlcpy(ec->texts[i], enum_ctl->texts[i],
      02270a
      +					    SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
      02270a
       		}
      02270a
       	}
      02270a
       
      02270a
      diff --git a/src/topology/data.c b/src/topology/data.c
      02270a
      index fd72abbb..aa2b87e7 100644
      02270a
      --- a/src/topology/data.c
      02270a
      +++ b/src/topology/data.c
      02270a
      @@ -124,12 +124,12 @@ static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem)
      02270a
       
      02270a
       	if (fclose(fp) == EOF) {
      02270a
       		SNDERR("Cannot close data file.");
      02270a
      -		ret = -errno;
      02270a
      -		goto err;
      02270a
      +		return -errno;
      02270a
       	}
      02270a
       	return 0;
      02270a
       
      02270a
       err:
      02270a
      +	fclose(fp);
      02270a
       	if (priv)
      02270a
       		free(priv);
      02270a
       	return ret;
      02270a
      @@ -422,7 +422,7 @@ static unsigned int get_tuple_size(int type)
      02270a
       static int copy_tuples(struct tplg_elem *elem,
      02270a
       	struct tplg_vendor_tuples *tuples, struct tplg_vendor_tokens *tokens)
      02270a
       {
      02270a
      -	struct snd_soc_tplg_private *priv = elem->data;
      02270a
      +	struct snd_soc_tplg_private *priv = elem->data, *priv2;
      02270a
       	struct tplg_tuple_set *tuple_set;
      02270a
       	struct tplg_tuple *tuple;
      02270a
       	struct snd_soc_tplg_vendor_array *array;
      02270a
      @@ -447,10 +447,17 @@ static int copy_tuples(struct tplg_elem *elem,
      02270a
       			return -EINVAL;
      02270a
       		}
      02270a
       
      02270a
      -		if (priv != NULL)
      02270a
      -			priv = realloc(priv, sizeof(*priv) + size);
      02270a
      -		else
      02270a
      +		if (priv != NULL) {
      02270a
      +			priv2 = realloc(priv, sizeof(*priv) + size);
      02270a
      +			if (priv2 == NULL) {
      02270a
      +				free(priv);
      02270a
      +				priv = NULL;
      02270a
      +			} else {
      02270a
      +				priv = priv2;
      02270a
      +			}
      02270a
      +		} else {
      02270a
       			priv = calloc(1, sizeof(*priv) + size);
      02270a
      +		}
      02270a
       		if (!priv)
      02270a
       			return -ENOMEM;
      02270a
       
      02270a
      diff --git a/src/topology/parser.c b/src/topology/parser.c
      02270a
      index cfc20e00..a7cff1c3 100644
      02270a
      --- a/src/topology/parser.c
      02270a
      +++ b/src/topology/parser.c
      02270a
      @@ -237,8 +237,9 @@ static int tplg_load_config(const char *file, snd_config_t **cfg)
      02270a
       
      02270a
       	ret = snd_input_stdio_attach(&in, fp, 1);
      02270a
       	if (ret < 0) {
      02270a
      +		fclose(fp);
      02270a
       		SNDERR("error: could not attach stdio %s", file);
      02270a
      -		goto err;
      02270a
      +		return ret;
      02270a
       	}
      02270a
       	ret = snd_config_top(&top);
      02270a
       	if (ret < 0)
      02270a
      @@ -261,7 +262,7 @@ static int tplg_load_config(const char *file, snd_config_t **cfg)
      02270a
       err_load:
      02270a
       	snd_config_delete(top);
      02270a
       err:
      02270a
      -	fclose(fp);
      02270a
      +	snd_input_close(in);
      02270a
       	return ret;
      02270a
       }
      02270a
       
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From ed156a218644e3334bc452ef2bc948409735c330 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Fri, 24 May 2019 21:11:00 +0200
      02270a
      Subject: [PATCH 21/25] ucm: coverity fixes
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/ucm/parser.c | 18 ++++++++++++++----
      02270a
       src/ucm/utils.c  | 12 +++++++++---
      02270a
       2 files changed, 23 insertions(+), 7 deletions(-)
      02270a
      02270a
      diff --git a/src/ucm/parser.c b/src/ucm/parser.c
      02270a
      index ad6bcec7..61d5d7f9 100644
      02270a
      --- a/src/ucm/parser.c
      02270a
      +++ b/src/ucm/parser.c
      02270a
      @@ -1114,7 +1114,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr,
      02270a
       			if (err < 0) {
      02270a
       				uc_error("error: %s failed to parse verb",
      02270a
       						file);
      02270a
      -				return err;
      02270a
      +				goto _err;
      02270a
       			}
      02270a
       			continue;
      02270a
       		}
      02270a
      @@ -1126,7 +1126,7 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr,
      02270a
       			if (err < 0) {
      02270a
       				uc_error("error: %s failed to parse device",
      02270a
       						file);
      02270a
      -				return err;
      02270a
      +				goto _err;
      02270a
       			}
      02270a
       			continue;
      02270a
       		}
      02270a
      @@ -1138,18 +1138,24 @@ static int parse_verb_file(snd_use_case_mgr_t *uc_mgr,
      02270a
       			if (err < 0) {
      02270a
       				uc_error("error: %s failed to parse modifier",
      02270a
       						file);
      02270a
      -				return err;
      02270a
      +				goto _err;
      02270a
       			}
      02270a
       			continue;
      02270a
       		}
      02270a
       	}
      02270a
       
      02270a
      +	snd_config_delete(cfg);
      02270a
      +
      02270a
       	/* use case verb must have at least 1 device */
      02270a
       	if (list_empty(&verb->device_list)) {
      02270a
       		uc_error("error: no use case device defined", file);
      02270a
       		return -EINVAL;
      02270a
       	}
      02270a
       	return 0;
      02270a
      +
      02270a
      +       _err:
      02270a
      +	snd_config_delete(cfg);
      02270a
      +	return err;
      02270a
       }
      02270a
       
      02270a
       /*
      02270a
      @@ -1399,6 +1405,7 @@ next_card:
      02270a
       
      02270a
       	return -1;
      02270a
       }
      02270a
      +
      02270a
       static int load_master_config(const char *card_name, snd_config_t **cfg)
      02270a
       {
      02270a
       	char filename[MAX_FILE];
      02270a
      @@ -1610,8 +1617,11 @@ int uc_mgr_scan_master_configs(const char **_list[])
      02270a
       	}
      02270a
       	free(namelist);
      02270a
       
      02270a
      -	if (err >= 0)
      02270a
      +	if (err >= 0) {
      02270a
       		*_list = list;
      02270a
      +	} else {
      02270a
      +		free(list);
      02270a
      +	}
      02270a
       
      02270a
       	return err;
      02270a
       }
      02270a
      diff --git a/src/ucm/utils.c b/src/ucm/utils.c
      02270a
      index 14227e0a..efd5a979 100644
      02270a
      --- a/src/ucm/utils.c
      02270a
      +++ b/src/ucm/utils.c
      02270a
      @@ -58,14 +58,18 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg)
      02270a
       	int err;
      02270a
       
      02270a
       	fp = fopen(file, "r");
      02270a
      -	err = fp == NULL ? -errno : snd_input_stdio_attach(&in, fp, 1);
      02270a
      -	if (err < 0) {
      02270a
      +	if (!fp) {
      02270a
      +		err = -errno;
      02270a
      +  __err0:
      02270a
       		uc_error("could not open configuration file %s", file);
      02270a
       		return err;
      02270a
       	}
      02270a
      +	err = snd_input_stdio_attach(&in, fp, 1);
      02270a
      +	if (err < 0)
      02270a
      +		goto __err0;
      02270a
       	err = snd_config_top(&top);
      02270a
       	if (err < 0)
      02270a
      -		return err;
      02270a
      +		goto __err1;
      02270a
       
      02270a
       	default_path = getenv(ALSA_CONFIG_UCM_VAR);
      02270a
       	if (!default_path || !*default_path)
      02270a
      @@ -88,6 +92,8 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg)
      02270a
       
      02270a
        __err2:
      02270a
               snd_config_delete(top);
      02270a
      + __err1:
      02270a
      +	snd_input_close(in);
      02270a
       	return err;
      02270a
       }
      02270a
       
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 022c790aabc300eabad4da8947a3f2bdadce41e1 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Mon, 27 May 2019 13:57:12 +0200
      02270a
      Subject: [PATCH 22/25] pcm_file: coverity fixes (including double locking)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 16 ++++++----------
      02270a
       1 file changed, 6 insertions(+), 10 deletions(-)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index 99db3754..54142a3d 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -296,7 +296,10 @@ static int snd_pcm_file_areas_read_infile(snd_pcm_t *pcm,
      02270a
       		return -ENOMEM;
      02270a
       	}
      02270a
       
      02270a
      -	bytes = read(file->ifd, file->rbuf, snd_pcm_frames_to_bytes(pcm, frames));
      02270a
      +	bytes = snd_pcm_frames_to_bytes(pcm, frames);
      02270a
      +	if (bytes < 0)
      02270a
      +		return bytes;
      02270a
      +	bytes = read(file->ifd, file->rbuf, bytes);
      02270a
       	if (bytes < 0) {
      02270a
       		SYSERR("read from file failed, error: %d", bytes);
      02270a
       		return bytes;
      02270a
      @@ -589,18 +592,14 @@ static snd_pcm_sframes_t snd_pcm_file_readi(snd_pcm_t *pcm, void *buffer, snd_pc
      02270a
       	snd_pcm_channel_area_t areas[pcm->channels];
      02270a
       	snd_pcm_sframes_t frames;
      02270a
       
      02270a
      -	__snd_pcm_lock(pcm);
      02270a
      -
      02270a
       	frames = _snd_pcm_readi(file->gen.slave, buffer, size);
      02270a
      -	if (frames <= 0) {
      02270a
      -		__snd_pcm_unlock(pcm);
      02270a
      +	if (frames <= 0)
      02270a
       		return frames;
      02270a
      -	}
      02270a
       
      02270a
       	snd_pcm_areas_from_buf(pcm, areas, buffer);
      02270a
       	snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
      02270a
      +	__snd_pcm_lock(pcm);
      02270a
       	snd_pcm_file_add_frames(pcm, areas, 0, frames);
      02270a
      -
      02270a
       	__snd_pcm_unlock(pcm);
      02270a
       
      02270a
       	return frames;
      02270a
      @@ -654,9 +653,6 @@ static int snd_pcm_file_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t
      02270a
       	snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames)
      02270a
       {
      02270a
       	snd_pcm_file_t *file = pcm->private_data;
      02270a
      -	snd_pcm_channel_area_t areas_if[pcm->channels];
      02270a
      -	snd_pcm_uframes_t frames_if;
      02270a
      -	void *buffer = NULL;
      02270a
       	int result;
      02270a
       
      02270a
       	result = snd_pcm_mmap_begin(file->gen.slave, areas, offset, frames);
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From c6e7fd8b1e0d8729c7220734ca0b529c35d926ed Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Mon, 27 May 2019 14:05:12 +0200
      02270a
      Subject: [PATCH 23/25] topology: next round of coverity fixes
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/topology/data.c   | 5 ++---
      02270a
       src/topology/parser.c | 7 +++++--
      02270a
       2 files changed, 7 insertions(+), 5 deletions(-)
      02270a
      02270a
      diff --git a/src/topology/data.c b/src/topology/data.c
      02270a
      index aa2b87e7..b3f4421f 100644
      02270a
      --- a/src/topology/data.c
      02270a
      +++ b/src/topology/data.c
      02270a
      @@ -88,8 +88,7 @@ static int tplg_parse_data_file(snd_config_t *cfg, struct tplg_elem *elem)
      02270a
       	if (fp == NULL) {
      02270a
       		SNDERR("error: invalid data file path '%s'\n",
      02270a
       			filename);
      02270a
      -		ret = -errno;
      02270a
      -		goto err;
      02270a
      +		return -errno;
      02270a
       	}
      02270a
       
      02270a
       	fseek(fp, 0L, SEEK_END);
      02270a
      @@ -463,6 +462,7 @@ static int copy_tuples(struct tplg_elem *elem,
      02270a
       
      02270a
       		off = priv->size;
      02270a
       		priv->size = size; /* update private data size */
      02270a
      +		elem->data = priv;
      02270a
       
      02270a
       		array = (struct snd_soc_tplg_vendor_array *)(priv->data + off);
      02270a
       		array->size = set_size;
      02270a
      @@ -499,7 +499,6 @@ static int copy_tuples(struct tplg_elem *elem,
      02270a
       		}
      02270a
       	}
      02270a
       
      02270a
      -	elem->data = priv;
      02270a
       	return 0;
      02270a
       }
      02270a
       
      02270a
      diff --git a/src/topology/parser.c b/src/topology/parser.c
      02270a
      index a7cff1c3..5940692d 100644
      02270a
      --- a/src/topology/parser.c
      02270a
      +++ b/src/topology/parser.c
      02270a
      @@ -253,8 +253,10 @@ static int tplg_load_config(const char *file, snd_config_t **cfg)
      02270a
       	}
      02270a
       
      02270a
       	ret = snd_input_close(in);
      02270a
      -	if (ret < 0)
      02270a
      +	if (ret < 0) {
      02270a
      +		in = NULL;
      02270a
       		goto err_load;
      02270a
      +	}
      02270a
       
      02270a
       	*cfg = top;
      02270a
       	return 0;
      02270a
      @@ -262,7 +264,8 @@ static int tplg_load_config(const char *file, snd_config_t **cfg)
      02270a
       err_load:
      02270a
       	snd_config_delete(top);
      02270a
       err:
      02270a
      -	snd_input_close(in);
      02270a
      +	if (in)
      02270a
      +		snd_input_close(in);
      02270a
       	return ret;
      02270a
       }
      02270a
       
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From ac6df1106c314de5d027176d910b9bc43a1fa7f9 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Mon, 27 May 2019 20:10:32 +0200
      02270a
      Subject: [PATCH 24/25] pcm_file: another locking fix (coverity)
      02270a
      02270a
      Signed-off-by: Jaroslav Kysela <perex@perex.cz>
      02270a
      ---
      02270a
       src/pcm/pcm_file.c | 8 +++-----
      02270a
       1 file changed, 3 insertions(+), 5 deletions(-)
      02270a
      02270a
      diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c
      02270a
      index 54142a3d..1ef80b59 100644
      02270a
      --- a/src/pcm/pcm_file.c
      02270a
      +++ b/src/pcm/pcm_file.c
      02270a
      @@ -612,18 +612,16 @@ static snd_pcm_sframes_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, snd_pcm
      02270a
       	snd_pcm_channel_area_t areas[pcm->channels];
      02270a
       	snd_pcm_sframes_t frames;
      02270a
       
      02270a
      -	__snd_pcm_lock(pcm);
      02270a
       	frames = _snd_pcm_readn(file->gen.slave, bufs, size);
      02270a
      -	if (frames <= 0) {
      02270a
      -		__snd_pcm_unlock(pcm);
      02270a
      +	if (frames <= 0)
      02270a
       		return frames;
      02270a
      -	}
      02270a
       
      02270a
       	snd_pcm_areas_from_bufs(pcm, areas, bufs);
      02270a
       	snd_pcm_file_areas_read_infile(pcm, areas, 0, frames);
      02270a
      +	__snd_pcm_lock(pcm);
      02270a
       	snd_pcm_file_add_frames(pcm, areas, 0, frames);
      02270a
      -
      02270a
       	__snd_pcm_unlock(pcm);
      02270a
      +
      02270a
       	return frames;
      02270a
       }
      02270a
       
      02270a
      -- 
      02270a
      2.20.1
      02270a
      02270a
      02270a
      From 5905af199670ca34eaaafbd3319d94d230b7e4d4 Mon Sep 17 00:00:00 2001
      02270a
      From: Jaroslav Kysela <perex@perex.cz>
      02270a
      Date: Mon, 27 May 2019 20:10:52 +0200
      02270a
      Subject: [PATCH 25/25] ucm: another coverity fix in uc_mgr_config_load()
      02270a
      02270a
      ---
      02270a
       src/ucm/utils.c | 9 ++++++---
      02270a
       1 file changed, 6 insertions(+), 3 deletions(-)
      02270a
      02270a
      diff --git a/src/ucm/utils.c b/src/ucm/utils.c
      02270a
      index efd5a979..5607304e 100644
      02270a
      --- a/src/ucm/utils.c
      02270a
      +++ b/src/ucm/utils.c
      02270a
      @@ -85,15 +85,18 @@ int uc_mgr_config_load(const char *file, snd_config_t **cfg)
      02270a
       		goto __err2;
      02270a
       	}
      02270a
       	err = snd_input_close(in);
      02270a
      -	if (err < 0)
      02270a
      +	if (err < 0) {
      02270a
      +		in = NULL;
      02270a
       		goto __err2;
      02270a
      +	}
      02270a
       	*cfg = top;
      02270a
       	return 0;
      02270a
       
      02270a
        __err2:
      02270a
      -        snd_config_delete(top);
      02270a
      +	snd_config_delete(top);
      02270a
        __err1:
      02270a
      -	snd_input_close(in);
      02270a
      +	if (in)
      02270a
      +		snd_input_close(in);
      02270a
       	return err;
      02270a
       }
      02270a
       
      02270a
      -- 
      02270a
      2.20.1
      02270a