Commit a39f009a authored by Linus Torvalds's avatar Linus Torvalds

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
parents 5bbf1b6d 93ee4b7d
...@@ -501,6 +501,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c) ...@@ -501,6 +501,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
{ {
struct pstore_record record; struct pstore_record record;
if (!c)
return;
pstore_record_init(&record, psinfo); pstore_record_init(&record, psinfo);
record.type = PSTORE_TYPE_CONSOLE; record.type = PSTORE_TYPE_CONSOLE;
......
...@@ -110,7 +110,6 @@ struct ramoops_context { ...@@ -110,7 +110,6 @@ struct ramoops_context {
}; };
static struct platform_device *dummy; static struct platform_device *dummy;
static struct ramoops_platform_data *dummy_data;
static int ramoops_pstore_open(struct pstore_info *psi) static int ramoops_pstore_open(struct pstore_info *psi)
{ {
...@@ -346,17 +345,15 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) ...@@ -346,17 +345,15 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
struct pstore_record *record) struct pstore_record *record)
{ {
char *hdr; char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */
size_t len; size_t len;
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n", len = scnprintf(hdr, sizeof(hdr),
RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
(time64_t)record->time.tv_sec, (time64_t)record->time.tv_sec,
record->time.tv_nsec / 1000, record->time.tv_nsec / 1000,
record->compressed ? 'C' : 'D'); record->compressed ? 'C' : 'D');
WARN_ON_ONCE(!hdr);
len = hdr ? strlen(hdr) : 0;
persistent_ram_write(prz, hdr, len); persistent_ram_write(prz, hdr, len);
kfree(hdr);
return len; return len;
} }
...@@ -424,6 +421,9 @@ static int notrace ramoops_pstore_write(struct pstore_record *record) ...@@ -424,6 +421,9 @@ static int notrace ramoops_pstore_write(struct pstore_record *record)
/* Build header and append record contents. */ /* Build header and append record contents. */
hlen = ramoops_write_kmsg_hdr(prz, record); hlen = ramoops_write_kmsg_hdr(prz, record);
if (!hlen)
return -ENOMEM;
size = record->size; size = record->size;
if (size + hlen > prz->buffer_size) if (size + hlen > prz->buffer_size)
size = prz->buffer_size - hlen; size = prz->buffer_size - hlen;
...@@ -716,15 +716,6 @@ static int ramoops_probe(struct platform_device *pdev) ...@@ -716,15 +716,6 @@ static int ramoops_probe(struct platform_device *pdev)
phys_addr_t paddr; phys_addr_t paddr;
int err = -EINVAL; int err = -EINVAL;
if (dev_of_node(dev) && !pdata) {
pdata = &pdata_local;
memset(pdata, 0, sizeof(*pdata));
err = ramoops_parse_dt(pdev, pdata);
if (err < 0)
goto fail_out;
}
/* /*
* Only a single ramoops area allowed at a time, so fail extra * Only a single ramoops area allowed at a time, so fail extra
* probes. * probes.
...@@ -734,6 +725,15 @@ static int ramoops_probe(struct platform_device *pdev) ...@@ -734,6 +725,15 @@ static int ramoops_probe(struct platform_device *pdev)
goto fail_out; goto fail_out;
} }
if (dev_of_node(dev) && !pdata) {
pdata = &pdata_local;
memset(pdata, 0, sizeof(*pdata));
err = ramoops_parse_dt(pdev, pdata);
if (err < 0)
goto fail_out;
}
/* Make sure we didn't get bogus platform data pointer. */ /* Make sure we didn't get bogus platform data pointer. */
if (!pdata) { if (!pdata) {
pr_err("NULL platform data\n"); pr_err("NULL platform data\n");
...@@ -892,13 +892,12 @@ static inline void ramoops_unregister_dummy(void) ...@@ -892,13 +892,12 @@ static inline void ramoops_unregister_dummy(void)
{ {
platform_device_unregister(dummy); platform_device_unregister(dummy);
dummy = NULL; dummy = NULL;
kfree(dummy_data);
dummy_data = NULL;
} }
static void __init ramoops_register_dummy(void) static void __init ramoops_register_dummy(void)
{ {
struct ramoops_platform_data pdata;
/* /*
* Prepare a dummy platform data structure to carry the module * Prepare a dummy platform data structure to carry the module
* parameters. If mem_size isn't set, then there are no module * parameters. If mem_size isn't set, then there are no module
...@@ -909,30 +908,25 @@ static void __init ramoops_register_dummy(void) ...@@ -909,30 +908,25 @@ static void __init ramoops_register_dummy(void)
pr_info("using module parameters\n"); pr_info("using module parameters\n");
dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL); memset(&pdata, 0, sizeof(pdata));
if (!dummy_data) { pdata.mem_size = mem_size;
pr_info("could not allocate pdata\n"); pdata.mem_address = mem_address;
return; pdata.mem_type = mem_type;
} pdata.record_size = record_size;
pdata.console_size = ramoops_console_size;
dummy_data->mem_size = mem_size; pdata.ftrace_size = ramoops_ftrace_size;
dummy_data->mem_address = mem_address; pdata.pmsg_size = ramoops_pmsg_size;
dummy_data->mem_type = mem_type; pdata.dump_oops = dump_oops;
dummy_data->record_size = record_size; pdata.flags = RAMOOPS_FLAG_FTRACE_PER_CPU;
dummy_data->console_size = ramoops_console_size;
dummy_data->ftrace_size = ramoops_ftrace_size;
dummy_data->pmsg_size = ramoops_pmsg_size;
dummy_data->dump_oops = dump_oops;
dummy_data->flags = RAMOOPS_FLAG_FTRACE_PER_CPU;
/* /*
* For backwards compatibility ramoops.ecc=1 means 16 bytes ECC * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
* (using 1 byte for ECC isn't much of use anyway). * (using 1 byte for ECC isn't much of use anyway).
*/ */
dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; pdata.ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
dummy = platform_device_register_data(NULL, "ramoops", -1, dummy = platform_device_register_data(NULL, "ramoops", -1,
dummy_data, sizeof(struct ramoops_platform_data)); &pdata, sizeof(pdata));
if (IS_ERR(dummy)) { if (IS_ERR(dummy)) {
pr_info("could not create platform device: %ld\n", pr_info("could not create platform device: %ld\n",
PTR_ERR(dummy)); PTR_ERR(dummy));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment