[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <94D0CD8314A33A4D9D801C0FE68B40295AA04A39@G9W0745.americas.hpqcorp.net>
Date: Thu, 23 Jul 2015 14:53:46 +0000
From: "Elliott, Robert (Server Storage)" <Elliott@...com>
To: Pan Xinhui <xinhuix.pan@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC: Thomas Gleixner <tglx@...utronix.de>,
Borislav Petkov <bp@...en8.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"hpa@...or.com" <hpa@...or.com>, "x86@...nel.org" <x86@...nel.org>,
"bp@...e.de" <bp@...e.de>, "Kani, Toshimitsu" <toshi.kani@...com>,
"jgross@...e.com" <jgross@...e.com>,
"mcgrof@...e.com" <mcgrof@...e.com>,
"mnipxh@....com" <mnipxh@....com>,
"yanmin_zhang@...ux.intel.com" <yanmin_zhang@...ux.intel.com>
Subject: RE: [PATCH] x86/mm/pat: Do a small optimization when dump PAT
memtype list
> -----Original Message-----
> From: linux-kernel-owner@...r.kernel.org [mailto:linux-kernel-
> owner@...r.kernel.org] On Behalf Of Pan Xinhui
> Sent: Thursday, July 23, 2015 4:54 AM
> To: linux-kernel@...r.kernel.org
> Subject: [PATCH] x86/mm/pat: Do a small optimization when dump PAT memtype
> list
...
> diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
> index 268b2c8..6302119 100644
> --- a/arch/x86/mm/pat.c
> +++ b/arch/x86/mm/pat.c
> @@ -1001,45 +1001,42 @@ EXPORT_SYMBOL_GPL(pgprot_writethrough);
>
> #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT)
>
> -static struct memtype *memtype_get_idx(loff_t pos)
> +static struct memtype *memtype_get_idx(struct memtype *entry, loff_t pos)
> {
> - struct memtype *print_entry;
> int ret;
>
> - print_entry = kzalloc(sizeof(struct memtype), GFP_KERNEL);
> - if (!print_entry)
> - return NULL;
> -
> spin_lock(&memtype_lock);
> - ret = rbt_memtype_copy_nth_element(print_entry, pos);
> + ret = rbt_memtype_copy_nth_element(entry, pos);
> spin_unlock(&memtype_lock);
>
> - if (!ret) {
> - return print_entry;
> - } else {
> - kfree(print_entry);
> - return NULL;
> - }
> + return ret ? NULL : entry;
> }
>
...
> static void memtype_seq_stop(struct seq_file *seq, void *v)
> {
> + kfree(seq->private);
> }
>
Consider adding
seq->private = NULL;
so the stale pointer isn't left around. There's probably not
much risk of accessing it, but NULL is safer in case it is.
---
Robert Elliott, HP Server Storage
Powered by blists - more mailing lists