Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1215301iob; Thu, 19 May 2022 01:40:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYffOQKU0JI7Xoz8qN/E6QcPMQwkFb81447Qag9UoLWRNCiVFNj55hpTEpKHblGPPw0sfo X-Received: by 2002:a63:2223:0:b0:3f6:3422:7db1 with SMTP id i35-20020a632223000000b003f634227db1mr2335869pgi.77.1652949632242; Thu, 19 May 2022 01:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652949632; cv=none; d=google.com; s=arc-20160816; b=FtfHiXdfW6TibyqoFg0BqMOijAM6SBWhXZnQ/+J9+8WF5NSVFRgIaOvDz+XzP1LWyH TjOSdueT8y9GpBt2vEUZYJ2YwjowZPam06/r5wF5lsdDmnH1FTMIUyuIzbZDM4S89Qmp lmEdVV+8+qxTcpYec2vVtwIe6Q2VLVikFQ8G08s18Aaswm8gphCBjt8zvrYrwDUF0x16 b3xpt1mAEx9D0UZSB6HwXDzq2JwotpvAHxmIF0Twt3tqbuSveeoD33yqoRT563JgbYAQ TKqzBl0TlW+UCROFZw0srBEOqlZmwgFWyt9CG9azSeUZlO32kGaRjqwx2FMEHyYd1CUX 4v5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=pYmFxl5EX9FT7BHXjR4DHU5ZJgyGAjXjcQaIbNKJXKE=; b=gW/RzdQCgH9e01xW4s8zuwArvFi4iFnlnewu01i6AhWy/6SBgAgCGCfC/K5xihCetr n3TvA2hEFKHsNS+T3kdXlFqDJGC3YRXTwALxsV42WHyySAnL8T6x0dTWMCbKcezE0wW/ IbJ3BzriAp9Aei8Ev7auHmPuKrJq5GYBEvn0UuLt6Mlw6KEhTpPgoulVEYhhKs2RWKDg E1YoCAQ1jFSCgnkIVBddz/gf0AVwSacP/1VNdQbWmeXj8Rw/A42DG0OxNbDOATFg43Kx UI0eW827GgoH6+ZUZSXEclEO/14bA60ScAUvsnKMe0o+zMVqdANRuR53nwVdXkAV+Fih Fj4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@pku.edu.cn header.s=dkim header.b=MCWf5bvh; 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=pku.edu.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c22-20020aa78e16000000b00505bd8d1dc7si5528508pfr.245.2022.05.19.01.40.18; Thu, 19 May 2022 01:40:32 -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 (test mode) header.i=@pku.edu.cn header.s=dkim header.b=MCWf5bvh; 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=pku.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234224AbiESFvU (ORCPT + 99 others); Thu, 19 May 2022 01:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbiESFvP (ORCPT ); Thu, 19 May 2022 01:51:15 -0400 X-Greylist: delayed 83263 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 18 May 2022 22:51:10 PDT Received: from zg8tmtyylji0my4xnjqunzqa.icoremail.net (zg8tmtyylji0my4xnjqunzqa.icoremail.net [162.243.164.74]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 373195DA1A; Wed, 18 May 2022 22:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pku.edu.cn; s=dkim; h=Received:From:To:Cc:Subject:Date: Message-Id:In-Reply-To:References; bh=pYmFxl5EX9FT7BHXjR4DHU5ZJg yGAjXjcQaIbNKJXKE=; b=MCWf5bvh5uU6WiiccZj3Ar5RGbHE3eCBM/nHVmkPqC 2GaaKDPmNkMN9zWQhhU55rhg/OJ6YtaZbj5YJAbtD32HeX5slwP6WBKqWjZSnkHk wgkMm+uUUPmm99L+8u59/g+uMhGwMsPHSzUgilmKF+ok/IXeJQyM+eYdGzcKhV1U w= Received: from localhost (unknown [10.129.21.144]) by front02 (Coremail) with SMTP id 54FpogCnKXbC2oViDtOTBg--.16956S2; Thu, 19 May 2022 13:50:58 +0800 (CST) From: Yongzhi Liu To: agross@kernel.org, bjorn.andersson@linaro.org, jic23@kernel.org, lars@metafoo.de Cc: linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, fuyq@stu.pku.edu.cn, Yongzhi Liu Subject: [PATCH v2] iio: vadc: Fix potential dereference of NULL pointer Date: Wed, 18 May 2022 22:50:55 -0700 Message-Id: <1652939455-123139-1-git-send-email-lyz_cs@pku.edu.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-CM-TRANSID: 54FpogCnKXbC2oViDtOTBg--.16956S2 X-Coremail-Antispam: 1UD129KBjvJXoW7urWfuFyktr18KrWxGryfJFb_yoW8CF43pa yktayrKry2ka1fJ3WftFWDXryaqw42q3yUGFWxJ3W3Ar43trnYyw1aqw1FkFn7uFWxC3ya yr4YyFnYgr4Dur7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkK1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2 z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcV Aq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j 6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVCm-wCF04k20xvY0x0EwIxGrwCF 04k20xvE74AGY7Cv6cx26w4UJr1UMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrV AFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCI c40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267 AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_ Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbXdbU UUUUU== X-CM-SenderInfo: irzqijirqukmo6sn3hxhgxhubq/1tbiAwELBlPy7vJhCwABsZ X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 The return value of vadc_get_channel() needs to be checked to avoid use of NULL pointer. Fix this by adding the null pointer check on prop. Fixes: 0917de94c ("iio: vadc: Qualcomm SPMI PMIC voltage ADC driver") Signed-off-by: Yongzhi Liu --- drivers/iio/adc/qcom-spmi-vadc.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c index 34202ba..9fa61fb 100644 --- a/drivers/iio/adc/qcom-spmi-vadc.c +++ b/drivers/iio/adc/qcom-spmi-vadc.c @@ -358,14 +358,25 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) vadc->graph[VADC_CALIB_ABSOLUTE].dx = VADC_ABSOLUTE_RANGE_UV; prop = vadc_get_channel(vadc, VADC_REF_1250MV); + if (!prop) { + dev_err(vadc->dev, "Please define 1.25V channel\n"); + ret = -ENODEV; + goto err; + } ret = vadc_do_conversion(vadc, prop, &read_1); if (ret) goto err; /* Try with buffered 625mV channel first */ prop = vadc_get_channel(vadc, VADC_SPARE1); - if (!prop) + if (!prop) { prop = vadc_get_channel(vadc, VADC_REF_625MV); + if (!prop) { + dev_err(vadc->dev, "Please define 0.625V channel\n"); + ret = -ENODEV; + goto err; + } + } ret = vadc_do_conversion(vadc, prop, &read_2); if (ret) @@ -381,11 +392,21 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc) /* Ratiometric calibration */ prop = vadc_get_channel(vadc, VADC_VDD_VADC); + if (!prop) { + dev_err(vadc->dev, "Please define VDD channel\n"); + ret = -ENODEV; + goto err; + } ret = vadc_do_conversion(vadc, prop, &read_1); if (ret) goto err; prop = vadc_get_channel(vadc, VADC_GND_REF); + if (!prop) { + dev_err(vadc->dev, "Please define GND channel\n"); + ret = -ENODEV; + goto err; + } ret = vadc_do_conversion(vadc, prop, &read_2); if (ret) goto err; -- 2.7.4