Skip to content

Commit bfaecf4

Browse files
qinyusre
authored andcommitted
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 <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent c142872 commit bfaecf4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/power/supply/power_supply_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,13 +1207,13 @@ __power_supply_register(struct device *parent,
12071207
struct power_supply *psy;
12081208
int rc;
12091209

1210+
if (!desc || !desc->name || !desc->properties || !desc->num_properties)
1211+
return ERR_PTR(-EINVAL);
1212+
12101213
if (!parent)
12111214
pr_warn("%s: Expected proper parent device for '%s'\n",
12121215
__func__, desc->name);
12131216

1214-
if (!desc || !desc->name || !desc->properties || !desc->num_properties)
1215-
return ERR_PTR(-EINVAL);
1216-
12171217
if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) &&
12181218
(!desc->usb_types || !desc->num_usb_types))
12191219
return ERR_PTR(-EINVAL);

0 commit comments

Comments
 (0)