aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorDaniel De Graaf <dgdegra@tycho.nsa.gov>2011-02-23 08:11:35 -0500
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2011-02-23 10:10:34 -0500
commit77c35acb7c81cd94c6b30a3bef488dd2d8145131 (patch)
treededeb89f5905567acdd66ffde0928af4c9bada26 /drivers/xen
parent1f169f66ddcc3b4614f840bef367de1ca20e16fe (diff)
xen-gntdev: Fix incorrect use of zero handle
The handle with numeric value 0 is a valid map handle, so it cannot be used to indicate that a page has not been mapped. Use -1 instead. Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen')
-rw-r--r--drivers/xen/gntdev.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c
index 2a4733c621c0..cdc28dc8b5d9 100644
--- a/drivers/xen/gntdev.c
+++ b/drivers/xen/gntdev.c
@@ -126,6 +126,8 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
126 add->pages[i] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM); 126 add->pages[i] = alloc_page(GFP_KERNEL | __GFP_HIGHMEM);
127 if (add->pages[i] == NULL) 127 if (add->pages[i] == NULL)
128 goto err; 128 goto err;
129 add->map_ops[i].handle = -1;
130 add->unmap_ops[i].handle = -1;
129 } 131 }
130 132
131 add->index = 0; 133 add->index = 0;
@@ -248,7 +250,7 @@ static int find_grant_ptes(pte_t *pte, pgtable_t token,
248 map->grants[pgnr].ref, 250 map->grants[pgnr].ref,
249 map->grants[pgnr].domid); 251 map->grants[pgnr].domid);
250 gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, 252 gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags,
251 0 /* handle */); 253 -1 /* handle */);
252 return 0; 254 return 0;
253} 255}
254 256
@@ -259,7 +261,7 @@ static int map_grant_pages(struct grant_map *map)
259 261
260 if (!use_ptemod) { 262 if (!use_ptemod) {
261 /* Note: it could already be mapped */ 263 /* Note: it could already be mapped */
262 if (map->map_ops[0].handle) 264 if (map->map_ops[0].handle != -1)
263 return 0; 265 return 0;
264 for (i = 0; i < map->count; i++) { 266 for (i = 0; i < map->count; i++) {
265 addr = (phys_addr_t) 267 addr = (phys_addr_t)
@@ -268,7 +270,7 @@ static int map_grant_pages(struct grant_map *map)
268 map->grants[i].ref, 270 map->grants[i].ref,
269 map->grants[i].domid); 271 map->grants[i].domid);
270 gnttab_set_unmap_op(&map->unmap_ops[i], addr, 272 gnttab_set_unmap_op(&map->unmap_ops[i], addr,
271 map->flags, 0 /* handle */); 273 map->flags, -1 /* handle */);
272 } 274 }
273 } 275 }
274 276
@@ -280,7 +282,11 @@ static int map_grant_pages(struct grant_map *map)
280 for (i = 0; i < map->count; i++) { 282 for (i = 0; i < map->count; i++) {
281 if (map->map_ops[i].status) 283 if (map->map_ops[i].status)
282 err = -EINVAL; 284 err = -EINVAL;
283 map->unmap_ops[i].handle = map->map_ops[i].handle; 285 else {
286 BUG_ON(map->map_ops[i].handle == -1);
287 map->unmap_ops[i].handle = map->map_ops[i].handle;
288 pr_debug("map handle=%d\n", map->map_ops[i].handle);
289 }
284 } 290 }
285 return err; 291 return err;
286} 292}
@@ -313,7 +319,10 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
313 for (i = 0; i < pages; i++) { 319 for (i = 0; i < pages; i++) {
314 if (map->unmap_ops[offset+i].status) 320 if (map->unmap_ops[offset+i].status)
315 err = -EINVAL; 321 err = -EINVAL;
316 map->unmap_ops[offset+i].handle = 0; 322 pr_debug("unmap handle=%d st=%d\n",
323 map->unmap_ops[offset+i].handle,
324 map->unmap_ops[offset+i].status);
325 map->unmap_ops[offset+i].handle = -1;
317 } 326 }
318 return err; 327 return err;
319} 328}
@@ -328,13 +337,13 @@ static int unmap_grant_pages(struct grant_map *map, int offset, int pages)
328 * already unmapped some of the grants. Only unmap valid ranges. 337 * already unmapped some of the grants. Only unmap valid ranges.
329 */ 338 */
330 while (pages && !err) { 339 while (pages && !err) {
331 while (pages && !map->unmap_ops[offset].handle) { 340 while (pages && map->unmap_ops[offset].handle == -1) {
332 offset++; 341 offset++;
333 pages--; 342 pages--;
334 } 343 }
335 range = 0; 344 range = 0;
336 while (range < pages) { 345 while (range < pages) {
337 if (!map->unmap_ops[offset+range].handle) { 346 if (map->unmap_ops[offset+range].handle == -1) {
338 range--; 347 range--;
339 break; 348 break;
340 } 349 }