aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/mspec.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index 049a46cc9f87..04ac155d3a07 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -155,23 +155,22 @@ mspec_open(struct vm_area_struct *vma)
155 * mspec_close 155 * mspec_close
156 * 156 *
157 * Called when unmapping a device mapping. Frees all mspec pages 157 * Called when unmapping a device mapping. Frees all mspec pages
158 * belonging to the vma. 158 * belonging to all the vma's sharing this vma_data structure.
159 */ 159 */
160static void 160static void
161mspec_close(struct vm_area_struct *vma) 161mspec_close(struct vm_area_struct *vma)
162{ 162{
163 struct vma_data *vdata; 163 struct vma_data *vdata;
164 int index, last_index, result; 164 int index, last_index;
165 unsigned long my_page; 165 unsigned long my_page;
166 166
167 vdata = vma->vm_private_data; 167 vdata = vma->vm_private_data;
168 168
169 BUG_ON(vma->vm_start < vdata->vm_start || vma->vm_end > vdata->vm_end); 169 if (!atomic_dec_and_test(&vdata->refcnt))
170 return;
170 171
171 spin_lock(&vdata->lock); 172 last_index = (vdata->vm_end - vdata->vm_start) >> PAGE_SHIFT;
172 index = (vma->vm_start - vdata->vm_start) >> PAGE_SHIFT; 173 for (index = 0; index < last_index; index++) {
173 last_index = (vma->vm_end - vdata->vm_start) >> PAGE_SHIFT;
174 for (; index < last_index; index++) {
175 if (vdata->maddr[index] == 0) 174 if (vdata->maddr[index] == 0)
176 continue; 175 continue;
177 /* 176 /*
@@ -180,20 +179,12 @@ mspec_close(struct vm_area_struct *vma)
180 */ 179 */
181 my_page = vdata->maddr[index]; 180 my_page = vdata->maddr[index];
182 vdata->maddr[index] = 0; 181 vdata->maddr[index] = 0;
183 spin_unlock(&vdata->lock); 182 if (!mspec_zero_block(my_page, PAGE_SIZE))
184 result = mspec_zero_block(my_page, PAGE_SIZE);
185 if (!result)
186 uncached_free_page(my_page); 183 uncached_free_page(my_page);
187 else 184 else
188 printk(KERN_WARNING "mspec_close(): " 185 printk(KERN_WARNING "mspec_close(): "
189 "failed to zero page %i\n", 186 "failed to zero page %ld\n", my_page);
190 result);
191 spin_lock(&vdata->lock);
192 } 187 }
193 spin_unlock(&vdata->lock);
194
195 if (!atomic_dec_and_test(&vdata->refcnt))
196 return;
197 188
198 if (vdata->flags & VMD_VMALLOCED) 189 if (vdata->flags & VMD_VMALLOCED)
199 vfree(vdata); 190 vfree(vdata);
@@ -201,7 +192,6 @@ mspec_close(struct vm_area_struct *vma)
201 kfree(vdata); 192 kfree(vdata);
202} 193}
203 194
204
205/* 195/*
206 * mspec_nopfn 196 * mspec_nopfn
207 * 197 *