diff mbox series

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

Message ID 20231025132100.649499-1-nuno.sa@analog.com (mailing list archive)
State Accepted
Headers show
Series hwmon: (axi-fan-control) Fix possible NULL pointer dereference | expand

Commit Message

Nuno Sa Oct. 25, 2023, 1:21 p.m. UTC
From: Dragos Bogdan <dragos.bogdan@analog.com>

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: 8412b41 ("hwmon: Support ADI Fan Control IP")
Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/hwmon/axi-fan-control.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

Comments

Guenter Roeck Oct. 25, 2023, 6:57 p.m. UTC | #1
On Wed, Oct 25, 2023 at 03:21:00PM +0200, Nuno Sa wrote:
> From: Dragos Bogdan <dragos.bogdan@analog.com>
> 
> 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.
> 

Applied, but, please,

> Fixes: 8412b41 ("hwmon: Support ADI Fan Control IP")

WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: 8412b410fa5e ("hwmon: Support ADI Fan Control IP")'
#88:
Fixes: 8412b41 ("hwmon: Support ADI Fan Control IP")

consider running checkpatch on your patches in the future.

Guenter
Nuno Sá Oct. 26, 2023, 5:24 a.m. UTC | #2
On Wed, 2023-10-25 at 11:57 -0700, Guenter Roeck wrote:
> On Wed, Oct 25, 2023 at 03:21:00PM +0200, Nuno Sa wrote:
> > From: Dragos Bogdan <dragos.bogdan@analog.com>
> > 
> > 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.
> > 
> 
> Applied, but, please,
> 
> > Fixes: 8412b41 ("hwmon: Support ADI Fan Control IP")
> 
> WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title
> line>")' - ie: 'Fixes: 8412b410fa5e ("hwmon: Support ADI Fan Control IP")'
> #88:
> Fixes: 8412b41 ("hwmon: Support ADI Fan Control IP")
> 
> consider running checkpatch on your patches in the future.
> 

Oh, sorry for that. As you figured I just cherry-picked the patch from a colleague. I
think it's time to have some kind of hook running some basic checks before git send-
mail.

- Nuno Sá
Guenter Roeck Oct. 26, 2023, 2:32 p.m. UTC | #3
On 10/25/23 22:24, Nuno Sá wrote:
> On Wed, 2023-10-25 at 11:57 -0700, Guenter Roeck wrote:
>> On Wed, Oct 25, 2023 at 03:21:00PM +0200, Nuno Sa wrote:
>>> From: Dragos Bogdan <dragos.bogdan@analog.com>
>>>
>>> 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.
>>>
>>
>> Applied, but, please,
>>
>>> Fixes: 8412b41 ("hwmon: Support ADI Fan Control IP")
>>
>> WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title
>> line>")' - ie: 'Fixes: 8412b410fa5e ("hwmon: Support ADI Fan Control IP")'
>> #88:
>> Fixes: 8412b41 ("hwmon: Support ADI Fan Control IP")
>>
>> consider running checkpatch on your patches in the future.
>>
> 
> Oh, sorry for that. As you figured I just cherry-picked the patch from a colleague. I
> think it's time to have some kind of hook running some basic checks before git send-
> mail.
> 

No worries. Happens. Fortunately problems like this are easy to fix.
I have a little script which downloads a patch, runs checkpatch on it,
and applies it if checkpatch reports no issues.

Thanks,
Guenter
diff mbox series

Patch

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 = {