public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pan Xinhui <xinhuix.pan@intel.com>
To: "Elliott, Robert (Server Storage)" <Elliott@hp.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"x86@kernel.org" <x86@kernel.org>, "bp@suse.de" <bp@suse.de>,
	"Kani, Toshimitsu" <toshi.kani@hp.com>,
	"jgross@suse.com" <jgross@suse.com>,
	"mcgrof@suse.com" <mcgrof@suse.com>,
	"mnipxh@163.com" <mnipxh@163.com>,
	"yanmin_zhang@linux.intel.com" <yanmin_zhang@linux.intel.com>
Subject: Re: [PATCH] x86/mm/pat: Do a small optimization when dump PAT memtype list
Date: Fri, 24 Jul 2015 10:40:00 +0800	[thread overview]
Message-ID: <55B1A580.7030801@intel.com> (raw)
In-Reply-To: <94D0CD8314A33A4D9D801C0FE68B40295AA04A39@G9W0745.americas.hpqcorp.net>

hi, Elliott
	thanks for your reply. :)

On 2015年07月23日 22:53, Elliott, Robert (Server Storage) wrote:
>> -----Original Message-----
>> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>> owner@vger.kernel.org] On Behalf Of Pan Xinhui
>> Sent: Thursday, July 23, 2015 4:54 AM
>> To: linux-kernel@vger.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.
> 
I know exactly what are you worrying about.
start and stop callback is still not the best place to alloc/free the *entry*. you are worrying about that some codes might touch it.

seq_file.c has offered seq_open_private and seq_release_private. we can make use of them. :)
I will work out patch v2, this time I will Cc you. I am very happy if you could review it at any free time. :)

thanks
xinhui
> ---
> Robert Elliott, HP Server Storage
> 

  reply	other threads:[~2015-07-24  2:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-23  9:54 [PATCH] x86/mm/pat: Do a small optimization when dump PAT memtype list Pan Xinhui
2015-07-23 14:53 ` Elliott, Robert (Server Storage)
2015-07-24  2:40   ` Pan Xinhui [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-07-24  3:11 Pan Xinhui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55B1A580.7030801@intel.com \
    --to=xinhuix.pan@intel.com \
    --cc=Elliott@hp.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@suse.com \
    --cc=mingo@redhat.com \
    --cc=mnipxh@163.com \
    --cc=tglx@linutronix.de \
    --cc=toshi.kani@hp.com \
    --cc=x86@kernel.org \
    --cc=yanmin_zhang@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox