Skip to contentSkip to conversation

dm-cache-target: check for allocation failure

PATCH In review Dan Carpenter 2 participants 2 messages Mar 1, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm-cache-target: check for allocation failure

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.

---
I expect that kbuild will complain about this soon?

drivers/md/dm-cache-target.c +4 -1
index 908d554..40753b4 100644
@@ -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]) {
#1 lore raw
Quoted 3 lines · Dan Carpenter

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