aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-multimedia/alsa/alsa-lib/0001-pcm_plugin-fix-appl-pointer-not-correct-when-mmap_co.patch
blob: bb2f82b1f5ca8a1fd2bf3ca5f795a35978760e04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
From 7c424edd116e76eee6218a1e9a6ff6c4daaf2a4d Mon Sep 17 00:00:00 2001
From: Shengjiu Wang <shengjiu.wang@freescale.com>
Date: Wed, 6 Apr 2016 19:02:12 +0800
Subject: [PATCH] pcm_plugin: fix appl pointer not correct when mmap_commit()
 return error

When snd_pcm_mmap_commit() return error, the appl pointer is also updated.
which cause the avail_update()'s result wrong.
This patch move the snd_pcm_mmap_appl_forward() to the place when
snd_pcm_mmap_commit() is successfully returned.

Upstream-Status: Accepted [expected in 1.1.2]

Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 src/pcm/pcm_plugin.c | 48 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
index d007e8c..940491d 100644
--- a/src/pcm/pcm_plugin.c
+++ b/src/pcm/pcm_plugin.c
@@ -279,18 +279,22 @@ static snd_pcm_sframes_t snd_pcm_plugin_write_areas(snd_pcm_t *pcm,
 			return -EPIPE;
 		}
 		snd_atomic_write_begin(&plugin->watom);
-		snd_pcm_mmap_appl_forward(pcm, frames);
 		result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
 		if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
 			snd_pcm_sframes_t res;
 			res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
-			if (res < 0)
+			if (res < 0) {
+				snd_atomic_write_end(&plugin->watom);
 				return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
+			}
 			frames -= res;
 		}
-		snd_atomic_write_end(&plugin->watom);
-		if (result <= 0)
+		if (result <= 0) {
+			snd_atomic_write_end(&plugin->watom);
 			return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
+		}
+		snd_pcm_mmap_appl_forward(pcm, frames);
+		snd_atomic_write_end(&plugin->watom);
 		offset += frames;
 		xfer += frames;
 		size -= frames;
@@ -325,19 +329,23 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
 			return -EPIPE;
 		}
 		snd_atomic_write_begin(&plugin->watom);
-		snd_pcm_mmap_appl_forward(pcm, frames);
 		result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
 		if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
 			snd_pcm_sframes_t res;
 			
 			res = plugin->undo_read(slave, areas, offset, frames, slave_frames - result);
-			if (res < 0)
+			if (res < 0) {
+				snd_atomic_write_end(&plugin->watom);
 				return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
+			}
 			frames -= res;
 		}
-		snd_atomic_write_end(&plugin->watom);
-		if (result <= 0)
+		if (result <= 0) {
+			snd_atomic_write_end(&plugin->watom);
 			return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
+		}
+		snd_pcm_mmap_appl_forward(pcm, frames);
+		snd_atomic_write_end(&plugin->watom);
 		offset += frames;
 		xfer += frames;
 		size -= frames;
@@ -423,19 +431,23 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
 		frames = plugin->write(pcm, areas, appl_offset, frames,
 				       slave_areas, slave_offset, &slave_frames);
 		snd_atomic_write_begin(&plugin->watom);
-		snd_pcm_mmap_appl_forward(pcm, frames);
 		result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
-		snd_atomic_write_end(&plugin->watom);
 		if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
 			snd_pcm_sframes_t res;
 			
 			res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
-			if (res < 0)
+			if (res < 0) {
+				snd_atomic_write_end(&plugin->watom);
 				return xfer > 0 ? xfer : res;
+			}
 			frames -= res;
 		}
-		if (result <= 0)
+		if (result <= 0) {
+			snd_atomic_write_end(&plugin->watom);
 			return xfer > 0 ? xfer : result;
+		}
+		snd_pcm_mmap_appl_forward(pcm, frames);
+		snd_atomic_write_end(&plugin->watom);
 		if (frames == cont)
 			appl_offset = 0;
 		else
@@ -490,19 +502,23 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
 			frames = (plugin->read)(pcm, areas, hw_offset, frames,
 					      slave_areas, slave_offset, &slave_frames);
 			snd_atomic_write_begin(&plugin->watom);
-			snd_pcm_mmap_hw_forward(pcm, frames);
 			result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
-			snd_atomic_write_end(&plugin->watom);
 			if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
 				snd_pcm_sframes_t res;
 				
 				res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
-				if (res < 0)
+				if (res < 0) {
+					snd_atomic_write_end(&plugin->watom);
 					return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
+				}
 				frames -= res;
 			}
-			if (result <= 0)
+			if (result <= 0) {
+				snd_atomic_write_end(&plugin->watom);
 				return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
+			}
+			snd_pcm_mmap_hw_forward(pcm, frames);
+			snd_atomic_write_end(&plugin->watom);
 			if (frames == cont)
 				hw_offset = 0;
 			else
-- 
1.9.1