diff mbox

dm-cache-target: check for allocation failure

Message ID 20130301202641.GA22066@longonot.mountain (mailing list archive)
State Deferred, archived
Headers show

Commit Message

Dan Carpenter March 1, 2013, 8:26 p.m. UTC
The allocation here isn't checked.  I changed it to using kcalloc()
as a cleanup.  It adds integer overflow checking as well which makes
the code easier to audit.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
I expect that kbuild will complain about this soon?


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel

Comments

Alasdair G Kergon March 1, 2013, 9:36 p.m. UTC | #1
On Fri, Mar 01, 2013 at 11:26:41PM +0300, Dan Carpenter wrote:
> The allocation here isn't checked.  I changed it to using kcalloc()
> as a cleanup.  It adds integer overflow checking as well which makes
> the code easier to audit.
 
Folded it in - thanks.

Alasdair

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 908d554..40753b4 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -1957,8 +1957,11 @@  bad:
 static int copy_ctr_args(struct cache *cache, int argc, const char **argv)
 {
 	unsigned i;
-	const char **copy = kzalloc(sizeof(*copy) * argc, GFP_KERNEL);
+	const char **copy;
 
+	copy = kcalloc(argc, sizeof(*copy), GFP_KERNEL);
+	if (!copy)
+		return -ENOMEM;
 	for (i = 0; i < argc; i++) {
 		copy[i] = kstrdup(argv[i], GFP_KERNEL);
 		if (!copy[i]) {