[patch] dm-cache-target: check for allocation failure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
I expect that kbuild will complain about this soon?

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]) {
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux