History

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

Linus Torvalds committed 7 years ago

Commit a39f0092 parents 5bbf1b6 93ee4b72 files · +32 −35Browse files

Unified · Split

2 files
  1. fs/pstore/platform.c +3 −0
  2. fs/pstore/ram.c +29 −35
fs/pstore/platform.c+3−0
@@ -501,6 +501,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c) · 500 unmodified lines
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
fs/pstore/ram.c+29−35
@@ -110,7 +110,6 @@ struct ramoops_context { · 109 unmodified lines
110};110};
111 111
112static struct platform_device *dummy;112static struct platform_device *dummy;
113static struct ramoops_platform_data *dummy_data;
114 113
115static int ramoops_pstore_open(struct pstore_info *psi)114static int ramoops_pstore_open(struct pstore_info *psi)
116{115{
@@ -346,17 +345,15 @@ out: · 229 unmodified lines
346static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,345static 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) · 61 unmodified lines
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) · 286 unmodified lines
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 extra720 * 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) · 3 unmodified lines
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) · 152 unmodified lines
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
900static void __init ramoops_register_dummy(void)897static 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 module902 * Prepare a dummy platform data structure to carry the module
904 * parameters. If mem_size isn't set, then there are no module903 * parameters. If mem_size isn't set, then there are no module
@@ -909,30 +908,25 @@ static void __init ramoops_register_dummy(void) · 4 unmodified lines
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 ECC923 * 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));