805-v5.15-0003-nvmem-core-fix-error-handling-while-validating-keepo.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. From de0534df93474f268486c486ea7e01b44a478026 Mon Sep 17 00:00:00 2001
  2. From: Srinivas Kandagatla <[email protected]>
  3. Date: Fri, 6 Aug 2021 09:59:47 +0100
  4. Subject: [PATCH] nvmem: core: fix error handling while validating keepout
  5. regions
  6. Current error path on failure of validating keepout regions is calling
  7. put_device, eventhough the device is not even registered at that point.
  8. Fix this by adding proper error handling of freeing ida and nvmem.
  9. Fixes: fd3bb8f54a88 ("nvmem: core: Add support for keepout regions")
  10. Cc: <[email protected]>
  11. Signed-off-by: Srinivas Kandagatla <[email protected]>
  12. Link: https://lore.kernel.org/r/[email protected]
  13. Signed-off-by: Greg Kroah-Hartman <[email protected]>
  14. ---
  15. drivers/nvmem/core.c | 7 +++++--
  16. 1 file changed, 5 insertions(+), 2 deletions(-)
  17. --- a/drivers/nvmem/core.c
  18. +++ b/drivers/nvmem/core.c
  19. @@ -827,8 +827,11 @@ struct nvmem_device *nvmem_register(cons
  20. if (nvmem->nkeepout) {
  21. rval = nvmem_validate_keepouts(nvmem);
  22. - if (rval)
  23. - goto err_put_device;
  24. + if (rval) {
  25. + ida_free(&nvmem_ida, nvmem->id);
  26. + kfree(nvmem);
  27. + return ERR_PTR(rval);
  28. + }
  29. }
  30. dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);