Skip to content

Commit

Permalink
Merge tag 'pstore-v4.19-rc7' of https://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/kees/linux

Kees writes:
  "Pstore fixes for v4.19-rc7

   - Fix failure-path memory leak in ramoops_init (nixiaoming)"

* tag 'pstore-v4.19-rc7' of https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  pstore/ram: Fix failure-path memory leak in ramoops_init
  • Loading branch information
Greg Kroah-Hartman committed Oct 2, 2018
2 parents 17b57b1 + bac6f6c commit ef0f258
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions fs/pstore/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,22 @@ static struct platform_driver ramoops_driver = {
},
};

static void ramoops_register_dummy(void)
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)
{
/*
* Prepare a dummy platform data structure to carry the module
* parameters. If mem_size isn't set, then there are no module
* parameters, and we can skip this.
*/
if (!mem_size)
return;

Expand Down Expand Up @@ -932,21 +946,28 @@ static void ramoops_register_dummy(void)
if (IS_ERR(dummy)) {
pr_info("could not create platform device: %ld\n",
PTR_ERR(dummy));
dummy = NULL;
ramoops_unregister_dummy();
}
}

static int __init ramoops_init(void)
{
int ret;

ramoops_register_dummy();
return platform_driver_register(&ramoops_driver);
ret = platform_driver_register(&ramoops_driver);
if (ret != 0)
ramoops_unregister_dummy();

return ret;
}
late_initcall(ramoops_init);

static void __exit ramoops_exit(void)
{
platform_driver_unregister(&ramoops_driver);
platform_device_unregister(dummy);
kfree(dummy_data);
ramoops_unregister_dummy();
}
module_exit(ramoops_exit);

Expand Down

0 comments on commit ef0f258

Please sign in to comment.