diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-09 12:02:47 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-03-09 12:02:47 -0500 |
commit | a39f009acefd85d3e36bcae828a4e67c9dce9684 (patch) | |
tree | 260b01b049873aa3c9897343ed49eb80dbf83f4e | |
parent | 5bbf1b6d05337c02218f5f351258cd1bf31ffde5 (diff) | |
parent | 93ee4b7d9f0632690713aee604c49e298e634094 (diff) |
Merge tag 'pstore-v5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull pstore cleanups from Kees Cook:
- Remove some needless memory allocations (Yue Hu, Kees Cook)
- Add zero-length checks to avoid no-op calls (Yue Hu)
* tag 'pstore-v5.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
pstore/ram: Avoid needless alloc during header write
pstore/ram: Add kmsg hlen zero check to ramoops_pstore_write()
pstore/ram: Move initialization earlier
pstore: Avoid writing records with zero size
pstore/ram: Replace dummy_data heap memory with stack memory
-rw-r--r-- | fs/pstore/platform.c | 3 | ||||
-rw-r--r-- | fs/pstore/ram.c | 64 |
2 files changed, 32 insertions, 35 deletions
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 2d1066ed3c28..75887a269b64 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c | |||
@@ -501,6 +501,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c) | |||
501 | { | 501 | { |
502 | struct pstore_record record; | 502 | struct pstore_record record; |
503 | 503 | ||
504 | if (!c) | ||
505 | return; | ||
506 | |||
504 | pstore_record_init(&record, psinfo); | 507 | pstore_record_init(&record, psinfo); |
505 | record.type = PSTORE_TYPE_CONSOLE; | 508 | record.type = PSTORE_TYPE_CONSOLE; |
506 | 509 | ||
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 898c8321b343..c5c685589e36 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c | |||
@@ -110,7 +110,6 @@ struct ramoops_context { | |||
110 | }; | 110 | }; |
111 | 111 | ||
112 | static struct platform_device *dummy; | 112 | static struct platform_device *dummy; |
113 | static struct ramoops_platform_data *dummy_data; | ||
114 | 113 | ||
115 | static int ramoops_pstore_open(struct pstore_info *psi) | 114 | static int ramoops_pstore_open(struct pstore_info *psi) |
116 | { | 115 | { |
@@ -346,17 +345,15 @@ out: | |||
346 | static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, | 345 | static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, |
347 | struct pstore_record *record) | 346 | struct pstore_record *record) |
348 | { | 347 | { |
349 | char *hdr; | 348 | char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */ |
350 | size_t len; | 349 | size_t len; |
351 | 350 | ||
352 | hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n", | 351 | len = scnprintf(hdr, sizeof(hdr), |
352 | RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n", | ||
353 | (time64_t)record->time.tv_sec, | 353 | (time64_t)record->time.tv_sec, |
354 | record->time.tv_nsec / 1000, | 354 | record->time.tv_nsec / 1000, |
355 | record->compressed ? 'C' : 'D'); | 355 | record->compressed ? 'C' : 'D'); |
356 | WARN_ON_ONCE(!hdr); | ||
357 | len = hdr ? strlen(hdr) : 0; | ||
358 | persistent_ram_write(prz, hdr, len); | 356 | persistent_ram_write(prz, hdr, len); |
359 | kfree(hdr); | ||
360 | 357 | ||
361 | return len; | 358 | return len; |
362 | } | 359 | } |
@@ -424,6 +421,9 @@ static int notrace ramoops_pstore_write(struct pstore_record *record) | |||
424 | 421 | ||
425 | /* Build header and append record contents. */ | 422 | /* Build header and append record contents. */ |
426 | hlen = ramoops_write_kmsg_hdr(prz, record); | 423 | hlen = ramoops_write_kmsg_hdr(prz, record); |
424 | if (!hlen) | ||
425 | return -ENOMEM; | ||
426 | |||
427 | size = record->size; | 427 | size = record->size; |
428 | if (size + hlen > prz->buffer_size) | 428 | if (size + hlen > prz->buffer_size) |
429 | size = prz->buffer_size - hlen; | 429 | size = prz->buffer_size - hlen; |
@@ -716,15 +716,6 @@ static int ramoops_probe(struct platform_device *pdev) | |||
716 | phys_addr_t paddr; | 716 | phys_addr_t paddr; |
717 | int err = -EINVAL; | 717 | int err = -EINVAL; |
718 | 718 | ||
719 | if (dev_of_node(dev) && !pdata) { | ||
720 | pdata = &pdata_local; | ||
721 | memset(pdata, 0, sizeof(*pdata)); | ||
722 | |||
723 | err = ramoops_parse_dt(pdev, pdata); | ||
724 | if (err < 0) | ||
725 | goto fail_out; | ||
726 | } | ||
727 | |||
728 | /* | 719 | /* |
729 | * Only a single ramoops area allowed at a time, so fail extra | 720 | * Only a single ramoops area allowed at a time, so fail extra |
730 | * probes. | 721 | * probes. |
@@ -734,6 +725,15 @@ static int ramoops_probe(struct platform_device *pdev) | |||
734 | goto fail_out; | 725 | goto fail_out; |
735 | } | 726 | } |
736 | 727 | ||
728 | if (dev_of_node(dev) && !pdata) { | ||
729 | pdata = &pdata_local; | ||
730 | memset(pdata, 0, sizeof(*pdata)); | ||
731 | |||
732 | err = ramoops_parse_dt(pdev, pdata); | ||
733 | if (err < 0) | ||
734 | goto fail_out; | ||
735 | } | ||
736 | |||
737 | /* Make sure we didn't get bogus platform data pointer. */ | 737 | /* Make sure we didn't get bogus platform data pointer. */ |
738 | if (!pdata) { | 738 | if (!pdata) { |
739 | pr_err("NULL platform data\n"); | 739 | pr_err("NULL platform data\n"); |
@@ -892,13 +892,12 @@ static inline void ramoops_unregister_dummy(void) | |||
892 | { | 892 | { |
893 | platform_device_unregister(dummy); | 893 | platform_device_unregister(dummy); |
894 | dummy = NULL; | 894 | dummy = NULL; |
895 | |||
896 | kfree(dummy_data); | ||
897 | dummy_data = NULL; | ||
898 | } | 895 | } |
899 | 896 | ||
900 | static void __init ramoops_register_dummy(void) | 897 | static void __init ramoops_register_dummy(void) |
901 | { | 898 | { |
899 | struct ramoops_platform_data pdata; | ||
900 | |||
902 | /* | 901 | /* |
903 | * Prepare a dummy platform data structure to carry the module | 902 | * Prepare a dummy platform data structure to carry the module |
904 | * parameters. If mem_size isn't set, then there are no module | 903 | * parameters. If mem_size isn't set, then there are no module |
@@ -909,30 +908,25 @@ static void __init ramoops_register_dummy(void) | |||
909 | 908 | ||
910 | pr_info("using module parameters\n"); | 909 | pr_info("using module parameters\n"); |
911 | 910 | ||
912 | dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL); | 911 | memset(&pdata, 0, sizeof(pdata)); |
913 | if (!dummy_data) { | 912 | pdata.mem_size = mem_size; |
914 | pr_info("could not allocate pdata\n"); | 913 | pdata.mem_address = mem_address; |
915 | return; | 914 | pdata.mem_type = mem_type; |
916 | } | 915 | pdata.record_size = record_size; |
917 | 916 | pdata.console_size = ramoops_console_size; | |
918 | dummy_data->mem_size = mem_size; | 917 | pdata.ftrace_size = ramoops_ftrace_size; |
919 | dummy_data->mem_address = mem_address; | 918 | pdata.pmsg_size = ramoops_pmsg_size; |
920 | dummy_data->mem_type = mem_type; | 919 | pdata.dump_oops = dump_oops; |
921 | dummy_data->record_size = record_size; | 920 | pdata.flags = RAMOOPS_FLAG_FTRACE_PER_CPU; |
922 | dummy_data->console_size = ramoops_console_size; | ||
923 | dummy_data->ftrace_size = ramoops_ftrace_size; | ||
924 | dummy_data->pmsg_size = ramoops_pmsg_size; | ||
925 | dummy_data->dump_oops = dump_oops; | ||
926 | dummy_data->flags = RAMOOPS_FLAG_FTRACE_PER_CPU; | ||
927 | 921 | ||
928 | /* | 922 | /* |
929 | * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC | 923 | * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC |
930 | * (using 1 byte for ECC isn't much of use anyway). | 924 | * (using 1 byte for ECC isn't much of use anyway). |
931 | */ | 925 | */ |
932 | dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; | 926 | pdata.ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; |
933 | 927 | ||
934 | dummy = platform_device_register_data(NULL, "ramoops", -1, | 928 | dummy = platform_device_register_data(NULL, "ramoops", -1, |
935 | dummy_data, sizeof(struct ramoops_platform_data)); | 929 | &pdata, sizeof(pdata)); |
936 | if (IS_ERR(dummy)) { | 930 | if (IS_ERR(dummy)) { |
937 | pr_info("could not create platform device: %ld\n", | 931 | pr_info("could not create platform device: %ld\n", |
938 | PTR_ERR(dummy)); | 932 | PTR_ERR(dummy)); |