Commit 6d51d255 authored by Dragos Bogdan's avatar Dragos Bogdan Committed by Wenyu Huang
Browse files

hwmon: (axi-fan-control) Fix possible NULL pointer dereference

stable inclusion
from stable-v5.10.201
commit 7d870088db4863c514a7f8751cd593751983029a
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9RL31
CVE: CVE-2023-52863

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=7d870088db4863c514a7f8751cd593751983029a



--------------------------------

[ 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: 8412b410 ("hwmon: Support ADI Fan Control IP")
Signed-off-by: default avatarDragos Bogdan <dragos.bogdan@analog.com>
Signed-off-by: default avatarNuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20231025132100.649499-1-nuno.sa@analog.com


Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarWenyu Huang <huangwenyu5@huawei.com>
parent cf9b4dc3
Loading
Loading
Loading
Loading
+16 −13
Original line number Diff line number Diff line
@@ -423,6 +423,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,
							 NULL);

	if (IS_ERR(ctl->hdev))
		return PTR_ERR(ctl->hdev);

	ctl->irq = platform_get_irq(pdev, 0);
	if (ctl->irq < 0)
		return ctl->irq;
@@ -436,19 +451,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,
							 NULL);

	return PTR_ERR_OR_ZERO(ctl->hdev);
	return 0;
}

static struct platform_driver axi_fan_control_driver = {