diff options
author | Kees Cook <keescook@chromium.org> | 2017-03-03 20:35:25 -0500 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2017-03-07 17:00:54 -0500 |
commit | 634f8f5167c88052ce6d28e519ff6325172191dc (patch) | |
tree | 8709cf4baac0d127482b31d1df849ae1c1d2489d | |
parent | 9abdcccc3d5f3c72f25cd48160f60d911353bee9 (diff) |
pstore: Move record decompression to function
This moves the record decompression logic out to a separate function
to avoid the deep indentation.
Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r-- | fs/pstore/platform.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index f45228eac3e6..0503380704de 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c | |||
@@ -757,6 +757,37 @@ void pstore_unregister(struct pstore_info *psi) | |||
757 | } | 757 | } |
758 | EXPORT_SYMBOL_GPL(pstore_unregister); | 758 | EXPORT_SYMBOL_GPL(pstore_unregister); |
759 | 759 | ||
760 | static void decompress_record(struct pstore_record *record) | ||
761 | { | ||
762 | int unzipped_len; | ||
763 | |||
764 | /* Only PSTORE_TYPE_DMESG support compression. */ | ||
765 | if (!record->compressed || record->type != PSTORE_TYPE_DMESG) { | ||
766 | pr_warn("ignored compressed record type %d\n", record->type); | ||
767 | return; | ||
768 | } | ||
769 | |||
770 | /* No compression method has created the common buffer. */ | ||
771 | if (!big_oops_buf) { | ||
772 | pr_warn("no decompression buffer allocated\n"); | ||
773 | return; | ||
774 | } | ||
775 | |||
776 | unzipped_len = pstore_decompress(record->buf, big_oops_buf, | ||
777 | record->size, big_oops_buf_sz); | ||
778 | if (unzipped_len > 0) { | ||
779 | if (record->ecc_notice_size) | ||
780 | memcpy(big_oops_buf + unzipped_len, | ||
781 | record->buf + record->size, | ||
782 | record->ecc_notice_size); | ||
783 | kfree(record->buf); | ||
784 | record->buf = big_oops_buf; | ||
785 | record->size = unzipped_len; | ||
786 | record->compressed = false; | ||
787 | } else | ||
788 | pr_err("decompression failed: %d\n", unzipped_len); | ||
789 | } | ||
790 | |||
760 | /* | 791 | /* |
761 | * Read all the records from the persistent store. Create | 792 | * Read all the records from the persistent store. Create |
762 | * files in our filesystem. Don't warn about -EEXIST errors | 793 | * files in our filesystem. Don't warn about -EEXIST errors |
@@ -768,7 +799,6 @@ void pstore_get_records(int quiet) | |||
768 | struct pstore_info *psi = psinfo; | 799 | struct pstore_info *psi = psinfo; |
769 | struct pstore_record record = { .psi = psi, }; | 800 | struct pstore_record record = { .psi = psi, }; |
770 | int failed = 0, rc; | 801 | int failed = 0, rc; |
771 | int unzipped_len = -1; | ||
772 | 802 | ||
773 | if (!psi) | 803 | if (!psi) |
774 | return; | 804 | return; |
@@ -782,41 +812,18 @@ void pstore_get_records(int quiet) | |||
782 | &record.buf, &record.compressed, | 812 | &record.buf, &record.compressed, |
783 | &record.ecc_notice_size, | 813 | &record.ecc_notice_size, |
784 | record.psi)) > 0) { | 814 | record.psi)) > 0) { |
785 | if (record.compressed && | 815 | |
786 | record.type == PSTORE_TYPE_DMESG) { | 816 | decompress_record(&record); |
787 | if (big_oops_buf) | ||
788 | unzipped_len = pstore_decompress( | ||
789 | record.buf, | ||
790 | big_oops_buf, | ||
791 | record.size, | ||
792 | big_oops_buf_sz); | ||
793 | |||
794 | if (unzipped_len > 0) { | ||
795 | if (record.ecc_notice_size) | ||
796 | memcpy(big_oops_buf + unzipped_len, | ||
797 | record.buf + record.size, | ||
798 | record.ecc_notice_size); | ||
799 | kfree(record.buf); | ||
800 | record.buf = big_oops_buf; | ||
801 | record.size = unzipped_len; | ||
802 | record.compressed = false; | ||
803 | } else { | ||
804 | pr_err("decompression failed;returned %d\n", | ||
805 | unzipped_len); | ||
806 | record.compressed = true; | ||
807 | } | ||
808 | } | ||
809 | rc = pstore_mkfile(record.type, psi->name, record.id, | 817 | rc = pstore_mkfile(record.type, psi->name, record.id, |
810 | record.count, record.buf, | 818 | record.count, record.buf, |
811 | record.compressed, | 819 | record.compressed, |
812 | record.size + record.ecc_notice_size, | 820 | record.size + record.ecc_notice_size, |
813 | record.time, record.psi); | 821 | record.time, record.psi); |
814 | if (unzipped_len < 0) { | 822 | |
815 | /* Free buffer other than big oops */ | 823 | /* Free buffer other than big oops */ |
824 | if (record.buf != big_oops_buf) | ||
816 | kfree(record.buf); | 825 | kfree(record.buf); |
817 | record.buf = NULL; | 826 | |
818 | } else | ||
819 | unzipped_len = -1; | ||
820 | if (rc && (rc != -EEXIST || !quiet)) | 827 | if (rc && (rc != -EEXIST || !quiet)) |
821 | failed++; | 828 | failed++; |
822 | 829 | ||