Commit 182ca6e0 authored by Yue Hu's avatar Yue Hu Committed by Kees Cook

pstore/ram: Replace dummy_data heap memory with stack memory

In ramoops_register_dummy() dummy_data is allocated via kzalloc()
then it will always occupy the heap space after register platform
device via platform_device_register_data(), but it will not be
used any more. So let's free it for system usage, replace it with
stack memory is better due to small size.
Signed-off-by: default avatarYue Hu <huyue2@yulong.com>
[kees: add required memset and adjust sizeof() argument]
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 49a57857
...@@ -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)
{ {
...@@ -892,13 +891,12 @@ static inline void ramoops_unregister_dummy(void) ...@@ -892,13 +891,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 +907,25 @@ static void __init ramoops_register_dummy(void) ...@@ -909,30 +907,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