pstore cleanups
- Remove some needless memory allocations (Yue Hu, Kees Cook) - Add zero-length checks to avoid no-op calls (Yue Hu) -----BEGIN PGP SIGNATURE----- Comment: Kees Cook <kees@outflux.net> iQJKBAABCgA0FiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAlx9X2MWHGtlZXNjb29r QGNocm9taXVtLm9yZwAKCRCJcvTf3G3AJla9EACEG5bBU++0KiqJsXqddOZ4cmcE j1oHyBHgBuXkkuZoLz5hrG45D1jBCEjZNoVdrDZEBUpql6rED+4d7RGls2zV5cku LMwEpYV4/+GxeJCE5i+uFHdAsnMGEtmRFgo2J7l7gnWbldhq0O4AsM8OUU/MLetP QPfQ5qXlQVVc1R+msXGJ0+zmzZwpk5iahEzYAWXh2oQI/x9yb5bcQxh9J5Xzek1u nByzqa23fXjHYP8hxkx4u07RzmpALPW4kdHYtZokiTWPAiYFMehRORoZwQvqXNUX /mHq33f2z3FZf1R0MkY7ZgcV+HkD4IjcTBMjPRqUPUKRy6UOrJp2oIzSpw9HEm7z yG6JFgYBXLg9huWsAPKjBoH8TUPlBL8QybktEMgz0HRWVqw9U8/KPZAtFsFg2RVA pKbkLTSGCO5xLrtOsBvZx3O8WY2p5sUW+R1LdLdE3Maib9bm/3OiFx3UpKH/N25O p9P4TuB2FF2v57XdIRVlp1RzPCEr+qMvP5GWiZVeNoj4K6JhlAfVJWuvjis9MAvj MfmodgVF5C2cRk4u94uaidgTCX9nYTooYxA6sxgMEKb0Qjl6cGJ8ByxmJLdeuui8 CXuJewOxmZ42OwNXh6ClDd/PnzAWf1Fq+5h7p4vmItxZdo+dzuwxqrOlN7wcTrlC ldVCn3h83TwbGy0WpQ== =4Rey -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
a39f009ace
|
@ -501,6 +501,9 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
|
|||
{
|
||||
struct pstore_record record;
|
||||
|
||||
if (!c)
|
||||
return;
|
||||
|
||||
pstore_record_init(&record, psinfo);
|
||||
record.type = PSTORE_TYPE_CONSOLE;
|
||||
|
||||
|
|
|
@ -110,7 +110,6 @@ struct ramoops_context {
|
|||
};
|
||||
|
||||
static struct platform_device *dummy;
|
||||
static struct ramoops_platform_data *dummy_data;
|
||||
|
||||
static int ramoops_pstore_open(struct pstore_info *psi)
|
||||
{
|
||||
|
@ -346,17 +345,15 @@ out:
|
|||
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
|
||||
struct pstore_record *record)
|
||||
{
|
||||
char *hdr;
|
||||
char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */
|
||||
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,
|
||||
record->time.tv_nsec / 1000,
|
||||
record->compressed ? 'C' : 'D');
|
||||
WARN_ON_ONCE(!hdr);
|
||||
len = hdr ? strlen(hdr) : 0;
|
||||
persistent_ram_write(prz, hdr, len);
|
||||
kfree(hdr);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
@ -424,6 +421,9 @@ static int notrace ramoops_pstore_write(struct pstore_record *record)
|
|||
|
||||
/* Build header and append record contents. */
|
||||
hlen = ramoops_write_kmsg_hdr(prz, record);
|
||||
if (!hlen)
|
||||
return -ENOMEM;
|
||||
|
||||
size = record->size;
|
||||
if (size + hlen > prz->buffer_size)
|
||||
size = prz->buffer_size - hlen;
|
||||
|
@ -716,15 +716,6 @@ static int ramoops_probe(struct platform_device *pdev)
|
|||
phys_addr_t paddr;
|
||||
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
|
||||
* probes.
|
||||
|
@ -734,6 +725,15 @@ static int ramoops_probe(struct platform_device *pdev)
|
|||
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. */
|
||||
if (!pdata) {
|
||||
pr_err("NULL platform data\n");
|
||||
|
@ -892,13 +892,12 @@ static inline void ramoops_unregister_dummy(void)
|
|||
{
|
||||
platform_device_unregister(dummy);
|
||||
dummy = NULL;
|
||||
|
||||
kfree(dummy_data);
|
||||
dummy_data = NULL;
|
||||
}
|
||||
|
||||
static void __init ramoops_register_dummy(void)
|
||||
{
|
||||
struct ramoops_platform_data pdata;
|
||||
|
||||
/*
|
||||
* Prepare a dummy platform data structure to carry the module
|
||||
* parameters. If mem_size isn't set, then there are no module
|
||||
|
@ -909,30 +908,25 @@ static void __init ramoops_register_dummy(void)
|
|||
|
||||
pr_info("using module parameters\n");
|
||||
|
||||
dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL);
|
||||
if (!dummy_data) {
|
||||
pr_info("could not allocate pdata\n");
|
||||
return;
|
||||
}
|
||||
|
||||
dummy_data->mem_size = mem_size;
|
||||
dummy_data->mem_address = mem_address;
|
||||
dummy_data->mem_type = mem_type;
|
||||
dummy_data->record_size = record_size;
|
||||
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;
|
||||
memset(&pdata, 0, sizeof(pdata));
|
||||
pdata.mem_size = mem_size;
|
||||
pdata.mem_address = mem_address;
|
||||
pdata.mem_type = mem_type;
|
||||
pdata.record_size = record_size;
|
||||
pdata.console_size = ramoops_console_size;
|
||||
pdata.ftrace_size = ramoops_ftrace_size;
|
||||
pdata.pmsg_size = ramoops_pmsg_size;
|
||||
pdata.dump_oops = dump_oops;
|
||||
pdata.flags = RAMOOPS_FLAG_FTRACE_PER_CPU;
|
||||
|
||||
/*
|
||||
* For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
|
||||
* (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_data, sizeof(struct ramoops_platform_data));
|
||||
&pdata, sizeof(pdata));
|
||||
if (IS_ERR(dummy)) {
|
||||
pr_info("could not create platform device: %ld\n",
|
||||
PTR_ERR(dummy));
|
||||
|
|
Loading…
Reference in New Issue