1 From 7c424edd116e76eee6218a1e9a6ff6c4daaf2a4d Mon Sep 17 00:00:00 2001
2 From: Shengjiu Wang <shengjiu.wang@freescale.com>
3 Date: Wed, 6 Apr 2016 19:02:12 +0800
4 Subject: [PATCH] pcm_plugin: fix appl pointer not correct when mmap_commit()
7 When snd_pcm_mmap_commit() return error, the appl pointer is also updated.
8 which cause the avail_update()'s result wrong.
9 This patch move the snd_pcm_mmap_appl_forward() to the place when
10 snd_pcm_mmap_commit() is successfully returned.
12 Upstream-Status: Submitted [https://patchwork.kernel.org/patch/8760881/]
14 Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
15 Signed-off-by: Takashi Iwai <tiwai@suse.de>
17 src/pcm/pcm_plugin.c | 48 ++++++++++++++++++++++++++++++++----------------
18 1 file changed, 32 insertions(+), 16 deletions(-)
20 diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
21 index d007e8c..940491d 100644
22 --- a/src/pcm/pcm_plugin.c
23 +++ b/src/pcm/pcm_plugin.c
24 @@ -279,18 +279,22 @@ static snd_pcm_sframes_t snd_pcm_plugin_write_areas(snd_pcm_t *pcm,
27 snd_atomic_write_begin(&plugin->watom);
28 - snd_pcm_mmap_appl_forward(pcm, frames);
29 result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
30 if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
31 snd_pcm_sframes_t res;
32 res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
35 + snd_atomic_write_end(&plugin->watom);
36 return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
40 - snd_atomic_write_end(&plugin->watom);
43 + snd_atomic_write_end(&plugin->watom);
44 return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
46 + snd_pcm_mmap_appl_forward(pcm, frames);
47 + snd_atomic_write_end(&plugin->watom);
51 @@ -325,19 +329,23 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
54 snd_atomic_write_begin(&plugin->watom);
55 - snd_pcm_mmap_appl_forward(pcm, frames);
56 result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
57 if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
58 snd_pcm_sframes_t res;
60 res = plugin->undo_read(slave, areas, offset, frames, slave_frames - result);
63 + snd_atomic_write_end(&plugin->watom);
64 return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
68 - snd_atomic_write_end(&plugin->watom);
71 + snd_atomic_write_end(&plugin->watom);
72 return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
74 + snd_pcm_mmap_appl_forward(pcm, frames);
75 + snd_atomic_write_end(&plugin->watom);
79 @@ -423,19 +431,23 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
80 frames = plugin->write(pcm, areas, appl_offset, frames,
81 slave_areas, slave_offset, &slave_frames);
82 snd_atomic_write_begin(&plugin->watom);
83 - snd_pcm_mmap_appl_forward(pcm, frames);
84 result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
85 - snd_atomic_write_end(&plugin->watom);
86 if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
87 snd_pcm_sframes_t res;
89 res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
92 + snd_atomic_write_end(&plugin->watom);
93 return xfer > 0 ? xfer : res;
99 + snd_atomic_write_end(&plugin->watom);
100 return xfer > 0 ? xfer : result;
102 + snd_pcm_mmap_appl_forward(pcm, frames);
103 + snd_atomic_write_end(&plugin->watom);
107 @@ -490,19 +502,23 @@ static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
108 frames = (plugin->read)(pcm, areas, hw_offset, frames,
109 slave_areas, slave_offset, &slave_frames);
110 snd_atomic_write_begin(&plugin->watom);
111 - snd_pcm_mmap_hw_forward(pcm, frames);
112 result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
113 - snd_atomic_write_end(&plugin->watom);
114 if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
115 snd_pcm_sframes_t res;
117 res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
120 + snd_atomic_write_end(&plugin->watom);
121 return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
127 + snd_atomic_write_end(&plugin->watom);
128 return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
130 + snd_pcm_mmap_hw_forward(pcm, frames);
131 + snd_atomic_write_end(&plugin->watom);