Commit a67baeb7 authored by David Vrabel's avatar David Vrabel Committed by Konrad Rzeszutek Wilk

xen/gntdev: don't leak memory from IOCTL_GNTDEV_MAP_GRANT_REF

map->kmap_ops allocated in gntdev_alloc_map() wasn't freed by
gntdev_put_map().

Add a gntdev_free_map() helper function to free everything allocated
by gntdev_alloc_map().
Signed-off-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
parent b6514633
...@@ -105,6 +105,21 @@ static void gntdev_print_maps(struct gntdev_priv *priv, ...@@ -105,6 +105,21 @@ static void gntdev_print_maps(struct gntdev_priv *priv,
#endif #endif
} }
static void gntdev_free_map(struct grant_map *map)
{
if (map == NULL)
return;
if (map->pages)
free_xenballooned_pages(map->count, map->pages);
kfree(map->pages);
kfree(map->grants);
kfree(map->map_ops);
kfree(map->unmap_ops);
kfree(map->kmap_ops);
kfree(map);
}
static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count) static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
{ {
struct grant_map *add; struct grant_map *add;
...@@ -142,12 +157,7 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count) ...@@ -142,12 +157,7 @@ static struct grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count)
return add; return add;
err: err:
kfree(add->pages); gntdev_free_map(add);
kfree(add->grants);
kfree(add->map_ops);
kfree(add->unmap_ops);
kfree(add->kmap_ops);
kfree(add);
return NULL; return NULL;
} }
...@@ -198,17 +208,9 @@ static void gntdev_put_map(struct grant_map *map) ...@@ -198,17 +208,9 @@ static void gntdev_put_map(struct grant_map *map)
evtchn_put(map->notify.event); evtchn_put(map->notify.event);
} }
if (map->pages) { if (map->pages && !use_ptemod)
if (!use_ptemod) unmap_grant_pages(map, 0, map->count);
unmap_grant_pages(map, 0, map->count); gntdev_free_map(map);
free_xenballooned_pages(map->count, map->pages);
}
kfree(map->pages);
kfree(map->grants);
kfree(map->map_ops);
kfree(map->unmap_ops);
kfree(map);
} }
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment