public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/pstore: Optimization function ramoops_init_przs
@ 2015-03-17  9:31 Wang Long
  2015-03-17 17:39 ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Wang Long @ 2015-03-17  9:31 UTC (permalink / raw)
  To: anton, ccross, keescook, tony.luck
  Cc: linux-kernel, long.wanglong, peifeiyue, marco.stornelli,
	anton.vorontsov, salyzyn, sergiu

The value of cxt->record_size does not change in the loop,
so this patch optimize the assign statement by moving
it to outer.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
---
 fs/pstore/ram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 44a549b..2105a16 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -373,6 +373,7 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
 {
 	int err = -ENOMEM;
 	int i;
+	size_t sz;
 
 	if (!cxt->record_size)
 		return 0;
@@ -393,9 +394,8 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
 		goto fail_prz;
 	}
 
+	sz = cxt->record_size;
 	for (i = 0; i < cxt->max_dump_cnt; i++) {
-		size_t sz = cxt->record_size;
-
 		cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
 						  &cxt->ecc_info,
 						  cxt->memtype);
-- 
1.8.3.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/pstore: Optimization function ramoops_init_przs
  2015-03-17  9:31 [PATCH] fs/pstore: Optimization function ramoops_init_przs Wang Long
@ 2015-03-17 17:39 ` Kees Cook
  2015-03-18  1:34   ` long.wanglong
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2015-03-17 17:39 UTC (permalink / raw)
  To: Wang Long
  Cc: Anton Vorontsov, Colin Cross, Tony Luck, LKML, peifeiyue,
	Marco Stornelli, Anton Vorontsov, Mark Salyzyn, Sergiu Iordache

On Tue, Mar 17, 2015 at 2:31 AM, Wang Long <long.wanglong@huawei.com> wrote:
> The value of cxt->record_size does not change in the loop,
> so this patch optimize the assign statement by moving
> it to outer.
>
> Signed-off-by: Wang Long <long.wanglong@huawei.com>
> ---
>  fs/pstore/ram.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 44a549b..2105a16 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -373,6 +373,7 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
>  {
>         int err = -ENOMEM;
>         int i;
> +       size_t sz;
>
>         if (!cxt->record_size)
>                 return 0;
> @@ -393,9 +394,8 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
>                 goto fail_prz;
>         }
>
> +       sz = cxt->record_size;
>         for (i = 0; i < cxt->max_dump_cnt; i++) {
> -               size_t sz = cxt->record_size;
> -
>                 cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
>                                                   &cxt->ecc_info,
>                                                   cxt->memtype);
> --
> 1.8.3.4
>

Actually, can't we drop sz entirely and just use cxt->record_size in its place?

-Kees

-- 
Kees Cook
Chrome OS Security

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/pstore: Optimization function ramoops_init_przs
  2015-03-17 17:39 ` Kees Cook
@ 2015-03-18  1:34   ` long.wanglong
  0 siblings, 0 replies; 3+ messages in thread
From: long.wanglong @ 2015-03-18  1:34 UTC (permalink / raw)
  To: Kees Cook
  Cc: Anton Vorontsov, Colin Cross, Tony Luck, LKML, peifeiyue,
	Marco Stornelli, Anton Vorontsov, Mark Salyzyn, Sergiu Iordache

On 2015/3/18 1:39, Kees Cook wrote:
> On Tue, Mar 17, 2015 at 2:31 AM, Wang Long <long.wanglong@huawei.com> wrote:
>> The value of cxt->record_size does not change in the loop,
>> so this patch optimize the assign statement by moving
>> it to outer.
>>
>> Signed-off-by: Wang Long <long.wanglong@huawei.com>
>> ---
>>  fs/pstore/ram.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
>> index 44a549b..2105a16 100644
>> --- a/fs/pstore/ram.c
>> +++ b/fs/pstore/ram.c
>> @@ -373,6 +373,7 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
>>  {
>>         int err = -ENOMEM;
>>         int i;
>> +       size_t sz;
>>
>>         if (!cxt->record_size)
>>                 return 0;
>> @@ -393,9 +394,8 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
>>                 goto fail_prz;
>>         }
>>
>> +       sz = cxt->record_size;
>>         for (i = 0; i < cxt->max_dump_cnt; i++) {
>> -               size_t sz = cxt->record_size;
>> -
>>                 cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
>>                                                   &cxt->ecc_info,
>>                                                   cxt->memtype);
>> --
>> 1.8.3.4
>>
> 
> Actually, can't we drop sz entirely and just use cxt->record_size in its place?
> 
> -Kees
> 
I agree with you.
drop sz entirely and  use cxt->record_size in its place can improve readability.

I will send another patch.

Best Regards

Wang Long


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-18  1:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-17  9:31 [PATCH] fs/pstore: Optimization function ramoops_init_przs Wang Long
2015-03-17 17:39 ` Kees Cook
2015-03-18  1:34   ` long.wanglong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox