Skip to contentSkip to conversation

pinctrl: sunxi: Testing the wrong variable

PATCH In review Dan Carpenter 3 participants 3 messages Nov 18, 2016 – Nov 22, 2016

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

PATCH 1/1 pinctrl: sunxi: Testing the wrong variable

Smatch complains that we dereference "map" before testing it for NULL which is true. We should be testing "*map" instead. Also on the error path, we should free *map and set it to NULL.

drivers/pinctrl/sunxi/pinctrl-sunxi.c +3 -2
index 2339d47..5b0acba 100644
@@ -398,13 +398,14 @@ static int sunxi_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 	 * map array
 	 */
 	*map = krealloc(*map, i * sizeof(struct pinctrl_map), GFP_KERNEL);
-	if (!map)
+	if (!*map)
 		return -ENOMEM;
 
 	return 0;
 
 err_free_map:
-	kfree(map);
+	kfree(*map);
+	*map = NULL;
 	return ret;
 }
 
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dan Carpenter

Smatch complains that we dereference "map" before testing it for NULL which is true. We should be testing "*map" instead. Also on the error path, we should free *map and set it to NULL.

Thanks!
Maxime

Signature · 3 lines
Maxime Ripard, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com