From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH] devres: zero the memory in devm_krealloc() if needed
Date: Mon, 26 Oct 2020 13:27:28 +0100 [thread overview]
Message-ID: <20201026122728.8522-1-brgl@bgdev.pl> (raw)
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
If we're returning the same pointer (when new size is smaller or equal
to the old size) we need to check if the user wants the memory zeroed
and memset() it manually if so.
Fixes: f82485722e5d devres: provide devm_krealloc()
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
drivers/base/devres.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 586e9a75c840..e522ad5f8342 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -895,8 +895,12 @@ void *devm_krealloc(struct device *dev, void *ptr, size_t new_size, gfp_t gfp)
* If new size is smaller or equal to the actual number of bytes
* allocated previously - just return the same pointer.
*/
- if (total_new_size <= total_old_size)
+ if (total_new_size <= total_old_size) {
+ if (gfp & __GFP_ZERO)
+ memset(ptr, 0, new_size);
+
return ptr;
+ }
/*
* Otherwise: allocate new, larger chunk. We need to allocate before
--
2.29.1
next reply other threads:[~2020-10-26 12:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 12:27 Bartosz Golaszewski [this message]
2020-10-26 13:14 ` [PATCH] devres: zero the memory in devm_krealloc() if needed Andy Shevchenko
2020-10-30 9:03 ` Bartosz Golaszewski
2020-10-30 10:57 ` Andy Shevchenko
2020-10-30 10:58 ` Andy Shevchenko
2020-10-30 11:03 ` Bartosz Golaszewski
2020-10-30 12:21 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201026122728.8522-1-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox