Skip to contentSkip to conversation

regmap: fix a potential leak in regmap_bulk_write()

PATCH In review Dan Carpenter 2 participants 2 messages Jan 9, 2014

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

PATCH 1/1 regmap: fix a potential leak in regmap_bulk_write()

Static checkers complain that there is an error path where _regmap_raw_write() fails and we goto out without freeing the "wval" buffer.

drivers/base/regmap/regmap.c +3 -3
index 062f59860091..939f9b26d5ee 100644
@@ -1514,7 +1514,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 {
 	int ret = 0, i;
 	size_t val_bytes = map->format.val_bytes;
-	void *wval;
+	void *wval = NULL;
 
 	if (!map->bus)
 		return -EINVAL;
@@ -1555,10 +1555,10 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
 		ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count);
 	}
 
-	if (val_bytes != 1)
-		kfree(wval);
 
 out:
+	if (val_bytes != 1)
+		kfree(wval);
 	map->unlock(map->lock_arg);
 	return ret;
 }
maintainer
#1 lore raw
Quoted 3 lines · Dan Carpenter

Static checkers complain that there is an error path where _regmap_raw_write() fails and we goto out without freeing the "wval" buffer.

This doesn't apply against current code (these functions got rewritten), can you please check?