Skip to contentSkip to conversation

fs/pstore: Optimization function ramoops_init_przs

PATCH Superseded Wang Long 2 participants 3 messages Mar 17, 2015 – Mar 18, 2015 Pstore filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wang Long

author
#0 lore raw

PATCH 1/1 fs/pstore: Optimization function ramoops_init_przs

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

---
 fs/pstore/ram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pstore/ram.c +2 -2
index 44a549b..2105a16 100644
@@ -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);
Signature · 1 line
1.8.3.4
#1 lore raw
Quoted 33 lines · Wang Long

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

---
 fs/pstore/ram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pstore/ram.c +2 -3
index 44a549b..2105a16 100644
@@ -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);
--
Quoted 2 lines

1.8.3.4

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

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#2 lore raw
Quoted 39 lines · Kees Cook
Quoted 33 lines · Wang Long

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

---
 fs/pstore/ram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/pstore/ram.c +2 -3
index 44a549b..2105a16 100644
@@ -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);
--
Quoted 2 lines

1.8.3.4

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

Quoted 2 lines

-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