Patch "iio: adc: stm32-adc: harden against NULL pointer deref in stm32_adc_probe()" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    iio: adc: stm32-adc: harden against NULL pointer deref in stm32_adc_probe()

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     iio-adc-stm32-adc-harden-against-null-pointer-deref-.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 76e5cd5071337b23327e5d5a00fa4c2357848a39
Author: Zhang Shurong <zhang_shurong@xxxxxxxxxxx>
Date:   Sat Jul 15 23:55:50 2023 +0800

    iio: adc: stm32-adc: harden against NULL pointer deref in stm32_adc_probe()
    
    [ Upstream commit 3a23b384e7e3d64d5587ad10729a34d4f761517e ]
    
    of_match_device() may fail and returns a NULL pointer.
    
    In practice there is no known reasonable way to trigger this, but
    in case one is added in future, harden the code by adding the check
    
    Signed-off-by: Zhang Shurong <zhang_shurong@xxxxxxxxxxx>
    Link: https://lore.kernel.org/r/tencent_994DA85912C937E3B5405BA960B31ED90A08@xxxxxx
    Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 81d5db91c67bf..dee47b899e5df 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -695,6 +695,8 @@ static int stm32_adc_probe(struct platform_device *pdev)
 	struct stm32_adc_priv *priv;
 	struct device *dev = &pdev->dev;
 	struct device_node *np = pdev->dev.of_node;
+	const struct of_device_id *of_id;
+
 	struct resource *res;
 	u32 max_rate;
 	int ret;
@@ -707,8 +709,11 @@ static int stm32_adc_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	platform_set_drvdata(pdev, &priv->common);
 
-	priv->cfg = (const struct stm32_adc_priv_cfg *)
-		of_match_device(dev->driver->of_match_table, dev)->data;
+	of_id = of_match_device(dev->driver->of_match_table, dev);
+	if (!of_id)
+		return -ENODEV;
+
+	priv->cfg = (const struct stm32_adc_priv_cfg *)of_id->data;
 	priv->nb_adc_max = priv->cfg->num_adcs;
 	spin_lock_init(&priv->common.lock);
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux