x86, pat: Fix memory leak in free_memtype
Reserve_memtype will allocate memory for new memtype, but in free_memtype, after the memtype erased from rbtree, the memory is not freed. Changes since V1: make rbt_memtype_erase return erased memtype so that it can be freed in free_memtype. [ hpa: not for -stable: 2.6.34 and earlier not affected ] Signed-off-by: Xiaotian Feng <dfeng@redhat.com> LKML-Reference: <1274838670-8731-1-git-send-email-dfeng@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Cc: Jack Steiner <steiner@sgi.com> Acked-by: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
fe501f1e89
commit
20413f2716
|
@ -336,6 +336,7 @@ int free_memtype(u64 start, u64 end)
|
||||||
{
|
{
|
||||||
int err = -EINVAL;
|
int err = -EINVAL;
|
||||||
int is_range_ram;
|
int is_range_ram;
|
||||||
|
struct memtype *entry;
|
||||||
|
|
||||||
if (!pat_enabled)
|
if (!pat_enabled)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -355,17 +356,20 @@ int free_memtype(u64 start, u64 end)
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&memtype_lock);
|
spin_lock(&memtype_lock);
|
||||||
err = rbt_memtype_erase(start, end);
|
entry = rbt_memtype_erase(start, end);
|
||||||
spin_unlock(&memtype_lock);
|
spin_unlock(&memtype_lock);
|
||||||
|
|
||||||
if (err) {
|
if (!entry) {
|
||||||
printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
|
printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
|
||||||
current->comm, current->pid, start, end);
|
current->comm, current->pid, start, end);
|
||||||
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kfree(entry);
|
||||||
|
|
||||||
dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
|
dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
|
||||||
|
|
||||||
return err;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ static inline char *cattr_name(unsigned long flags)
|
||||||
#ifdef CONFIG_X86_PAT
|
#ifdef CONFIG_X86_PAT
|
||||||
extern int rbt_memtype_check_insert(struct memtype *new,
|
extern int rbt_memtype_check_insert(struct memtype *new,
|
||||||
unsigned long *new_type);
|
unsigned long *new_type);
|
||||||
extern int rbt_memtype_erase(u64 start, u64 end);
|
extern struct memtype *rbt_memtype_erase(u64 start, u64 end);
|
||||||
extern struct memtype *rbt_memtype_lookup(u64 addr);
|
extern struct memtype *rbt_memtype_lookup(u64 addr);
|
||||||
extern int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos);
|
extern int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos);
|
||||||
#else
|
#else
|
||||||
static inline int rbt_memtype_check_insert(struct memtype *new,
|
static inline int rbt_memtype_check_insert(struct memtype *new,
|
||||||
unsigned long *new_type)
|
unsigned long *new_type)
|
||||||
{ return 0; }
|
{ return 0; }
|
||||||
static inline int rbt_memtype_erase(u64 start, u64 end)
|
static inline struct memtype *rbt_memtype_erase(u64 start, u64 end)
|
||||||
{ return 0; }
|
{ return NULL; }
|
||||||
static inline struct memtype *rbt_memtype_lookup(u64 addr)
|
static inline struct memtype *rbt_memtype_lookup(u64 addr)
|
||||||
{ return NULL; }
|
{ return NULL; }
|
||||||
static inline int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos)
|
static inline int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos)
|
||||||
|
|
|
@ -231,16 +231,17 @@ int rbt_memtype_check_insert(struct memtype *new, unsigned long *ret_type)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rbt_memtype_erase(u64 start, u64 end)
|
struct memtype *rbt_memtype_erase(u64 start, u64 end)
|
||||||
{
|
{
|
||||||
struct memtype *data;
|
struct memtype *data;
|
||||||
|
|
||||||
data = memtype_rb_exact_match(&memtype_rbroot, start, end);
|
data = memtype_rb_exact_match(&memtype_rbroot, start, end);
|
||||||
if (!data)
|
if (!data)
|
||||||
return -EINVAL;
|
goto out;
|
||||||
|
|
||||||
rb_erase(&data->rb, &memtype_rbroot);
|
rb_erase(&data->rb, &memtype_rbroot);
|
||||||
return 0;
|
out:
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct memtype *rbt_memtype_lookup(u64 addr)
|
struct memtype *rbt_memtype_lookup(u64 addr)
|
||||||
|
|
Loading…
Reference in New Issue