Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

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@foxmail.com>
Link: https://lore.kernel.org/r/tencent_994DA85912C937E3B5405BA960B31ED90A08@qq.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Zhang Shurong and committed by
Jonathan Cameron
3a23b384 8f6bc87d

+7 -2
+7 -2
drivers/iio/adc/stm32-adc-core.c
··· 708 708 struct stm32_adc_priv *priv; 709 709 struct device *dev = &pdev->dev; 710 710 struct device_node *np = pdev->dev.of_node; 711 + const struct of_device_id *of_id; 712 + 711 713 struct resource *res; 712 714 u32 max_rate; 713 715 int ret; ··· 722 720 return -ENOMEM; 723 721 platform_set_drvdata(pdev, &priv->common); 724 722 725 - priv->cfg = (const struct stm32_adc_priv_cfg *) 726 - of_match_device(dev->driver->of_match_table, dev)->data; 723 + of_id = of_match_device(dev->driver->of_match_table, dev); 724 + if (!of_id) 725 + return -ENODEV; 726 + 727 + priv->cfg = (const struct stm32_adc_priv_cfg *)of_id->data; 727 728 priv->nb_adc_max = priv->cfg->num_adcs; 728 729 spin_lock_init(&priv->common.lock); 729 730