From: Adam Thomson Date: Mon, 23 Apr 2018 14:10:58 +0000 (+0100) Subject: power: supply: Add error checking of psy desc during registration X-Git-Tag: v5.15~8714^2~108 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1ac3eef74a61f40639d0fa835fd968f825b09135;p=platform%2Fkernel%2Flinux-starfive.git power: supply: Add error checking of psy desc during registration Currently there's no error checking of this parameter in the registration function and it's blindly added to psy class and subsequently used as is. For example if this is NULL the call to psy_register_thermal() will try to dereference the pointer thus causing a kernel dump. This commit updates the registration code to add some basic checks on the desc pointer validity, name, and presence of properties. Signed-off-by: Adam Thomson Reviewed-by: Heikki Krogerus Reviewed-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index feac7b0..a7984af 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -849,6 +849,9 @@ __power_supply_register(struct device *parent, pr_warn("%s: Expected proper parent device for '%s'\n", __func__, desc->name); + if (!desc || !desc->name || !desc->properties || !desc->num_properties) + return ERR_PTR(-EINVAL); + psy = kzalloc(sizeof(*psy), GFP_KERNEL); if (!psy) return ERR_PTR(-ENOMEM);