summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqinyu <qinyu32@huawei.com>2023-02-23 16:10:47 +0800
committerSebastian Reichel <sebastian.reichel@collabora.com>2023-02-25 01:15:03 +0100
commitbfaecf465a058b167abc7c0dfad985f167ff3af1 (patch)
tree32a246972c50af20ef073ad4ad056a42adf2e538
parentc142872ea40a99258e2a86bf5c471bcc81752f56 (diff)
power: supply: fix null pointer check order in __power_supply_register
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>
-rw-r--r--drivers/power/supply/power_supply_core.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index cc5b2e22b42a..f3d7c1da299f 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -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);