Skip to content

Commit

Permalink
power: supply: fix null pointer check order in __power_supply_register
Browse files Browse the repository at this point in the history
There is an null pointer check order issue here: if we have to
check !desc and !desc->name anyway, check it before dereferencing it in
pr_warn().

Signed-off-by: qinyu <qinyu32@huawei.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  • Loading branch information
qinyu authored and Sebastian Reichel committed Feb 25, 2023
1 parent c142872 commit bfaecf4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/power/supply/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,13 +1207,13 @@ __power_supply_register(struct device *parent,
struct power_supply *psy;
int rc;

if (!desc || !desc->name || !desc->properties || !desc->num_properties)
return ERR_PTR(-EINVAL);

if (!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);

if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) &&
(!desc->usb_types || !desc->num_usb_types))
return ERR_PTR(-EINVAL);
Expand Down

0 comments on commit bfaecf4

Please sign in to comment.