Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: vexpress: fix error handling vexpress_syscfg_regmap_init()

This function should be returning an ERR_PTR() on failure instead of
NULL. Also there is a use after free bug if regmap_init() fails because
we free "func" and then dereference doing the return.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dan Carpenter and committed by
Greg Kroah-Hartman
b86e1926 8a26af30

+8 -4
+8 -4
drivers/misc/vexpress-syscfg.c
··· 199 199 func = kzalloc(sizeof(*func) + sizeof(*func->template) * num, 200 200 GFP_KERNEL); 201 201 if (!func) 202 - return NULL; 202 + return ERR_PTR(-ENOMEM); 203 203 204 204 func->syscfg = syscfg; 205 205 func->num_templates = num; ··· 231 231 func->regmap = regmap_init(dev, NULL, func, 232 232 &vexpress_syscfg_regmap_config); 233 233 234 - if (IS_ERR(func->regmap)) 234 + if (IS_ERR(func->regmap)) { 235 + void *err = func->regmap; 236 + 235 237 kfree(func); 236 - else 237 - list_add(&func->list, &syscfg->funcs); 238 + return err; 239 + } 240 + 241 + list_add(&func->list, &syscfg->funcs); 238 242 239 243 return func->regmap; 240 244 }