Skip to content

Commit

Permalink
power: supply: Fix null pointer dereference in smb2_probe
Browse files Browse the repository at this point in the history
devm_kasprintf and devm_kzalloc return a pointer to dynamically
allocated memory which can be NULL upon failure.

Fixes: 8648aeb ("power: supply: add Qualcomm PMI8998 SMB2 Charger driver")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Link: https://lore.kernel.org/r/20231124075021.1335289-1-chentao@kylinos.cn
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  • Loading branch information
Kunwu Chan authored and Sebastian Reichel committed Dec 24, 2023
1 parent 195c316 commit 88f04bc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/power/supply/qcom_pmi8998_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,14 @@ static int smb2_probe(struct platform_device *pdev)
supply_config.of_node = pdev->dev.of_node;

desc = devm_kzalloc(chip->dev, sizeof(smb2_psy_desc), GFP_KERNEL);
if (!desc)
return -ENOMEM;
memcpy(desc, &smb2_psy_desc, sizeof(smb2_psy_desc));
desc->name =
devm_kasprintf(chip->dev, GFP_KERNEL, "%s-charger",
(const char *)device_get_match_data(chip->dev));
if (!desc->name)
return -ENOMEM;

chip->chg_psy =
devm_power_supply_register(chip->dev, desc, &supply_config);
Expand Down

0 comments on commit 88f04bc

Please sign in to comment.