Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp3765180rwp; Sat, 15 Jul 2023 09:00:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHfWb7WeyaFKZe5fOcOdrjFHlj37PVtgAfKSupWzf8QxochW9nPxjow2p67W7DSd09zo+tV X-Received: by 2002:a17:906:220b:b0:993:d54b:3e4b with SMTP id s11-20020a170906220b00b00993d54b3e4bmr2279584ejs.0.1689436818840; Sat, 15 Jul 2023 09:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689436818; cv=none; d=google.com; s=arc-20160816; b=yQnanc6WLm3up+D34EA0qV2Cr4RqhOHlZlfAsSb4CXIA2/ynbC4e2tMNU4MiIzT7JF Wy2XxuaJGpv5ttH5Ge371NYqtwqlPgv9dTYJTKoqLb96ZH72qK231XYeDfUTeg5UFG+u mUmGAos3RikXszyqrXWxplwRGrRafL/wH34mBqIJsTsZRldsBMgIHVg6vBHvEXsgtlTs 6Zz/GIlyZynbGWBu3OziQcywE8E0wN4xfCafnW+/yW3oKZ/FurxLs1088c3A7GP17eyG 0PVKe76ZAYuFMbbI6dmdyIHz3NU4q03IUMt0lHzgyas7VaOfkZ5wc0LkdNxFP9OTzy5O 4hOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:cc:to:from:message-id:dkim-signature; bh=Q4AIE3ORkFkez9a9uTEasaw5aPDPog8DGCyhlYhijtQ=; fh=K//VruTBwGGOkNVjGS5JVWK5WevEvDrk5WtpgCuyR/g=; b=uF8xTGfPHcndR5axeFz9koTT28lOS8jncjFzJ+78WKLydw6FsEs5vuvlUaRStQcuKB /2frDXDCSfJAjkMN4p0UN+1zVP+vWh5EFV8ANpk00s7m6bYrVIei3yKe33j+MyMzXh5z NkLB/SUK2/pRf0QL3iGKn6ihiucHjgvrSp3JYhmfXlo8KxlXRNhmV9ZCG8vCdYuAw14F vpVt5WGeSvHF7k3LD9F/ILIQFUTJf2VMZDV0YcSOZ4aWyYN2kFux0rDGn9+MxFBGLdH+ Dhc3w0sE76o9OX0ewDMMimJDcDiEbnVHfs3YT1VJofAly0oMza4uD9UjcOXcHiOqB5gb SVqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=GMWOWCEd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v12-20020a1709064e8c00b00992e14a3655si3476509eju.354.2023.07.15.08.59.54; Sat, 15 Jul 2023 09:00:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=GMWOWCEd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230168AbjGOP4E (ORCPT + 99 others); Sat, 15 Jul 2023 11:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbjGOP4D (ORCPT ); Sat, 15 Jul 2023 11:56:03 -0400 Received: from out203-205-251-66.mail.qq.com (out203-205-251-66.mail.qq.com [203.205.251.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA56030E4 for ; Sat, 15 Jul 2023 08:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1689436554; bh=Q4AIE3ORkFkez9a9uTEasaw5aPDPog8DGCyhlYhijtQ=; h=From:To:Cc:Subject:Date; b=GMWOWCEdxyejehSeGxTCRvzUMZwIhu9T9aiQ1nVL+8sqyLNglqhdWuEAt3pVdNLcm pAFEtt97vhItDuKe7KToiipwerj1PxkMVxUqSsjTkE7A4LNPQWbj/BEwBUZ08+ZD/2 XiyZ5bdHyQWCkZ2KrPXsH2RxDEXdE2buIxQ7uD2E= Received: from KernelDevBox.byted.org ([180.184.49.4]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id DF305C36; Sat, 15 Jul 2023 23:55:51 +0800 X-QQ-mid: xmsmtpt1689436551toyuslagu Message-ID: X-QQ-XMAILINFO: Mh1dUllL/+A2vhqHkhb7/gbp7caHWu3yMPEaqAyj5XA8papyHBSXtvAfD/ZjW3 C4kT0qRyiZZKbdkqCYuxPuM9KQO8fzJ/ju1Ab8Pds4sdFaTl3RnLpBWT7mFN3HJaq9Bo/MPvh31B VfUEXkWQR6WzB2VrYboWIhWpWuwmnZSIIpn0ZFVQqcxixa3Iam3ai8+k1ZrCM/tZwAQF328cdCNi zM6z6E0JnfFqyAPER780NcHNyGGxIbhabC4r674y17MelD9RJRL74b2TFr60cvR1ZthrcGfn1GFP UGkGu++cyhOF37to76jS4umSneMTn4JmLH33y7G1yO6x1HpynmCNj+G8Oc3dRXQux2/kcP8MXKRx 15jmN5YKDvnjstk4WGF6GJCcGT0oZ9VnyQOdt6ikh+RzjPMM/L8C8JcEM+FbeMIUba2giTmurVj+ REJnfM3DiZH5YrTNUvIR0zeZVjwJGNjkGRlMZkY6aQnzXsb8wthhjdBlHYMxHNDS5FPElAESdN5+ /tp0YWENXjW/F1vn7FhBxor7suyS6+UdXy8+gYu8wA8NpEXjoIfRBhQDpX1ZoQc3b537VxBR5IUu uF+Ke1KSmyuMSYY/KnCzLPCBmOAXvJb8IOUH5CScml1b7Xh9BujIqIGK792Q6lgH7A9UddFC9AzB TAEXPefm+fLuN6Y3mC/ek0jjWgpgVN30AZgR3BW9WB5Gq/PfOggAgzcVLRpqthSzqUaY0GAkXMho zxMQTeuGFc9aX3I3cFmTWODlrX69jiO5+eap74ZB2NeMnH93qKhK79o267XTzhnK8z7S/+xzz1VT oUxa1pYgGLmT5l/4FHiBTIrrFlRFNOQrf4fo78r+Cha5Zy3km/qSULIqXl8LsLGu8MTr8j+hzChM tKUuUcUe/xhWmPv3Hy7YVfnwa/vWSowwY+gR1CeYGoAL/CwIqEugA3m5945C883OYJ/fON0b3L3t 0zTxRDb/JE+35a3SbEPet/LUVTXHPsr5U187AvQTrktEn0jD01flhEtxGgcXnPdJzfCgV+/gqlLz pL2Cqzuw== X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= From: Zhang Shurong To: jic23@kernel.org Cc: lars@metafoo.de, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, lgirdwood@gmail.com, broonie@kernel.org, linux-iio@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Zhang Shurong Subject: [PATCH] io: adc: stm32-adc: fix potential NULL pointer dereference in stm32_adc_probe() Date: Sat, 15 Jul 2023 23:55:50 +0800 X-OQ-MSGID: <20230715155550.2306245-1-zhang_shurong@foxmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_BLOCKED,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org of_match_device() may fail and returns a NULL pointer. Fix this by checking the return value of of_match_device(). Fixes: 64ad7f6438f3 ("iio: adc: stm32: introduce compatible data cfg") Signed-off-by: Zhang Shurong --- drivers/iio/adc/stm32-adc-core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c index 48f02dcc81c1..70011fdbf5f6 100644 --- a/drivers/iio/adc/stm32-adc-core.c +++ b/drivers/iio/adc/stm32-adc-core.c @@ -706,6 +706,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; @@ -718,8 +720,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); -- 2.30.2