summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorDragos Bogdan <dragos.bogdan@analog.com>2023-10-25 15:21:00 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-11-20 11:59:07 +0100
commitc49f14cc1bb12c625a1c572e8a95b6adefd4d8eb (patch)
treecb39ecacdc47a71aca90a2e9bf365f99883b56d1 /drivers/hwmon
parentd51b96c90d5dcbd64803180e28f601ae4002a989 (diff)
downloadlinux-stable-c49f14cc1bb12c625a1c572e8a95b6adefd4d8eb.tar.gz
linux-stable-c49f14cc1bb12c625a1c572e8a95b6adefd4d8eb.tar.bz2
linux-stable-c49f14cc1bb12c625a1c572e8a95b6adefd4d8eb.zip
hwmon: (axi-fan-control) Fix possible NULL pointer dereference
[ Upstream commit 2a5b3370a1d9750eca325292e291c8c7cb8cf2e0 ] axi_fan_control_irq_handler(), dependent on the private axi_fan_control_data structure, might be called before the hwmon device is registered. That will cause an "Unable to handle kernel NULL pointer dereference" error. Fixes: 8412b410fa5e ("hwmon: Support ADI Fan Control IP") Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com> Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20231025132100.649499-1-nuno.sa@analog.com Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/axi-fan-control.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/drivers/hwmon/axi-fan-control.c b/drivers/hwmon/axi-fan-control.c
index 5fd136baf1cd..19b9bf3d75ef 100644
--- a/drivers/hwmon/axi-fan-control.c
+++ b/drivers/hwmon/axi-fan-control.c
@@ -496,6 +496,21 @@ static int axi_fan_control_probe(struct platform_device *pdev)
return -ENODEV;
}
+ ret = axi_fan_control_init(ctl, pdev->dev.of_node);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to initialize device\n");
+ return ret;
+ }
+
+ ctl->hdev = devm_hwmon_device_register_with_info(&pdev->dev,
+ name,
+ ctl,
+ &axi_chip_info,
+ axi_fan_control_groups);
+
+ if (IS_ERR(ctl->hdev))
+ return PTR_ERR(ctl->hdev);
+
ctl->irq = platform_get_irq(pdev, 0);
if (ctl->irq < 0)
return ctl->irq;
@@ -509,19 +524,7 @@ static int axi_fan_control_probe(struct platform_device *pdev)
return ret;
}
- ret = axi_fan_control_init(ctl, pdev->dev.of_node);
- if (ret) {
- dev_err(&pdev->dev, "Failed to initialize device\n");
- return ret;
- }
-
- ctl->hdev = devm_hwmon_device_register_with_info(&pdev->dev,
- name,
- ctl,
- &axi_chip_info,
- axi_fan_control_groups);
-
- return PTR_ERR_OR_ZERO(ctl->hdev);
+ return 0;
}
static struct platform_driver axi_fan_control_driver = {