]> code.ossystems Code Review - openembedded-core.git/blob
9fd69f301d744e31774ebd73e09158e9fe4c8aa5
[openembedded-core.git] /
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()
5  return error
6
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.
11
12 Upstream-Status: Submitted [https://patchwork.kernel.org/patch/8760881/]
13
14 Signed-off-by: Shengjiu Wang <shengjiu.wang@freescale.com>
15 Signed-off-by: Takashi Iwai <tiwai@suse.de>
16 ---
17  src/pcm/pcm_plugin.c | 48 ++++++++++++++++++++++++++++++++----------------
18  1 file changed, 32 insertions(+), 16 deletions(-)
19
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,
25                         return -EPIPE;
26                 }
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);
33 -                       if (res < 0)
34 +                       if (res < 0) {
35 +                               snd_atomic_write_end(&plugin->watom);
36                                 return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
37 +                       }
38                         frames -= res;
39                 }
40 -               snd_atomic_write_end(&plugin->watom);
41 -               if (result <= 0)
42 +               if (result <= 0) {
43 +                       snd_atomic_write_end(&plugin->watom);
44                         return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
45 +               }
46 +               snd_pcm_mmap_appl_forward(pcm, frames);
47 +               snd_atomic_write_end(&plugin->watom);
48                 offset += frames;
49                 xfer += frames;
50                 size -= frames;
51 @@ -325,19 +329,23 @@ static snd_pcm_sframes_t snd_pcm_plugin_read_areas(snd_pcm_t *pcm,
52                         return -EPIPE;
53                 }
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;
59                         
60                         res = plugin->undo_read(slave, areas, offset, frames, slave_frames - result);
61 -                       if (res < 0)
62 +                       if (res < 0) {
63 +                               snd_atomic_write_end(&plugin->watom);
64                                 return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
65 +                       }
66                         frames -= res;
67                 }
68 -               snd_atomic_write_end(&plugin->watom);
69 -               if (result <= 0)
70 +               if (result <= 0) {
71 +                       snd_atomic_write_end(&plugin->watom);
72                         return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
73 +               }
74 +               snd_pcm_mmap_appl_forward(pcm, frames);
75 +               snd_atomic_write_end(&plugin->watom);
76                 offset += frames;
77                 xfer += frames;
78                 size -= frames;
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;
88                         
89                         res = plugin->undo_write(pcm, slave_areas, slave_offset + result, slave_frames, slave_frames - result);
90 -                       if (res < 0)
91 +                       if (res < 0) {
92 +                               snd_atomic_write_end(&plugin->watom);
93                                 return xfer > 0 ? xfer : res;
94 +                       }
95                         frames -= res;
96                 }
97 -               if (result <= 0)
98 +               if (result <= 0) {
99 +                       snd_atomic_write_end(&plugin->watom);
100                         return xfer > 0 ? xfer : result;
101 +               }
102 +               snd_pcm_mmap_appl_forward(pcm, frames);
103 +               snd_atomic_write_end(&plugin->watom);
104                 if (frames == cont)
105                         appl_offset = 0;
106                 else
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;
116                                 
117                                 res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
118 -                               if (res < 0)
119 +                               if (res < 0) {
120 +                                       snd_atomic_write_end(&plugin->watom);
121                                         return xfer > 0 ? (snd_pcm_sframes_t)xfer : res;
122 +                               }
123                                 frames -= res;
124                         }
125 -                       if (result <= 0)
126 +                       if (result <= 0) {
127 +                               snd_atomic_write_end(&plugin->watom);
128                                 return xfer > 0 ? (snd_pcm_sframes_t)xfer : result;
129 +                       }
130 +                       snd_pcm_mmap_hw_forward(pcm, frames);
131 +                       snd_atomic_write_end(&plugin->watom);
132                         if (frames == cont)
133                                 hw_offset = 0;
134                         else
135 -- 
136 1.9.1
137