Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3305114lfo; Mon, 23 May 2022 01:12:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxh0GUhMivJf6Dd23pKepLlJXteF6b84hbSHPiv3KxqYs37ff+HhLtKlFVQhkw50uVWKAl6 X-Received: by 2002:a17:902:e385:b0:161:823d:5309 with SMTP id g5-20020a170902e38500b00161823d5309mr22020532ple.62.1653293556118; Mon, 23 May 2022 01:12:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653293556; cv=none; d=google.com; s=arc-20160816; b=ZqcTGOrbN9lSlaryfYn1XNLLzU8jyJXfh8Y8qW8772YNueGEGrMoa4QAXSeDsb4zkW 7y9FyBjZ6IDESUT5q9qTovIHrzjGyzXEuRgIYR1A7E4zr3C3l/MD0mwGWiAS0Ox5fC+y s+tSc7kU1T4kdthRjs8BNRTuekRN0Vk8GFi01hkCv56vrE6zS0VNtdyPoxObZNVxubLM 7ptIWvmNG2cWcb6/A3o+1kLAZgFaV6xTM+mbii7Ur2Pyv6KDR+UY/gBRg/dbsz8kd9tY JRnrIyehkHjoQHr19uUs+9HJj4wuLu+nLs89/1xUjQQ4egbzuxhwl0QbmzziQ2+o2Cuf IMww== 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=wzgzdu7AuK5zx/MuP4XOVfBFXxNsi5pQH7m0wAb0gCo=; b=UbvK8ygsOKNqD5tOsJr7Ti5E1UeoVUROIhIfUipnCmmat2nEiVgLp/GSZQRd6fZp4J aehwJeVvRnGtCh1JdQgw3/yKSkWGElanLUifwkgzl2zQ42jfTAqaNbEkagV/TKasLYfV X+7CsUSH4QmdkramJeuG2yq7s9+5LCmWfmN8DXELuNqiuB0WcfeswkjcQSu/x0P+bWjT V4GXZ4ePo4cUcGeIZaWLkiapmdmBt4/H9uE8p6J6g7PIi+w6UpzSIMEFTHv5ndvMHwHP OMssoviOjMr6NJ+wFjQ+MAbMP2ZEcEgZ9hHognuWuf2/6+fsxl11nuL08myGqUZTN6SJ Xn/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@pku.edu.cn header.s=dkim header.b=X5b2XxOO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id on3-20020a17090b1d0300b001dfb7951890si13987140pjb.160.2022.05.23.01.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:12:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@pku.edu.cn header.s=dkim header.b=X5b2XxOO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 148D1544C5; Mon, 23 May 2022 00:07:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240634AbiEUDgD (ORCPT + 99 others); Fri, 20 May 2022 23:36:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346958AbiEUDf6 (ORCPT ); Fri, 20 May 2022 23:35:58 -0400 Received: from zg8tmja5ljk3lje4ms43mwaa.icoremail.net (zg8tmja5ljk3lje4ms43mwaa.icoremail.net [209.97.181.73]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 26452D11F for ; Fri, 20 May 2022 20:35:52 -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=wzgzdu7AuK5zx/MuP4XOVfBFXx Nsi5pQH7m0wAb0gCo=; b=X5b2XxOOCRGY8Jb1B1DBIYP3XP74DSwIK3HUmUZpVV i8vYsFwdMSFLYYqkHEtFHtPVUwV3NYtljq2vyAROP2ptfYr4nqa9xA1ebV65nZ3a 6C74csk6aLBGRgwjFl3RduR2TK+JUQUURq6G7PsYK8LbC2NMjgoiFF6jqdnG8984 A= Received: from localhost (unknown [10.129.21.144]) by front02 (Coremail) with SMTP id 54FpogAHinYKXohiR2PABg--.12714S2; Sat, 21 May 2022 11:35:38 +0800 (CST) From: Yongzhi Liu To: agross@kernel.org, bjorn.andersson@linaro.org, jic23@kernel.org, lars@metafoo.de, svarbanov@mm-sol.com, iivanov@mm-sol.com, jonathan.cameron@huawei.com 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 v3] iio: vadc: Fix potential dereference of NULL pointer Date: Fri, 20 May 2022 20:35:35 -0700 Message-Id: <1653104135-36259-1-git-send-email-lyz_cs@pku.edu.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20220520181323.00002892@huawei.com> References: <20220520181323.00002892@huawei.com> X-CM-TRANSID: 54FpogAHinYKXohiR2PABg--.12714S2 X-Coremail-Antispam: 1UD129KBjvJXoW7urWfuFy5Kry8Jr1xXr4fXwb_yoW5Jr1Upa 98JayrGry7Ka1fJFyfAFWDJF1aqw42qayUCFWxGanIyr1ayrnYyr4ag3WFyrn5CFyxCw43 Ar4jvFnY9F4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FFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 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 and dropping general error prints. Fixes: 0917de94c02f ("iio: vadc: Qualcomm SPMI PMIC voltage ADC driver") Signed-off-by: Yongzhi Liu --- drivers/iio/adc/qcom-spmi-vadc.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c index 34202ba..43a52b1 100644 --- a/drivers/iio/adc/qcom-spmi-vadc.c +++ b/drivers/iio/adc/qcom-spmi-vadc.c @@ -358,22 +358,33 @@ 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; + return ret; + } ret = vadc_do_conversion(vadc, prop, &read_1); if (ret) - goto err; + return ret; /* 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; + return ret; + } + } ret = vadc_do_conversion(vadc, prop, &read_2); if (ret) - goto err; + return ret; if (read_1 == read_2) { ret = -EINVAL; - goto err; + return ret; } vadc->graph[VADC_CALIB_ABSOLUTE].dy = read_1 - read_2; @@ -381,25 +392,32 @@ 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; + return ret; + } ret = vadc_do_conversion(vadc, prop, &read_1); if (ret) - goto err; + return ret; prop = vadc_get_channel(vadc, VADC_GND_REF); + if (!prop) { + dev_err(vadc->dev, "Please define GND channel\n"); + ret = -ENODEV; + return ret; + } ret = vadc_do_conversion(vadc, prop, &read_2); if (ret) - goto err; + return ret; if (read_1 == read_2) { ret = -EINVAL; - goto err; + return ret; } vadc->graph[VADC_CALIB_RATIOMETRIC].dy = read_1 - read_2; vadc->graph[VADC_CALIB_RATIOMETRIC].gnd = read_2; -err: - if (ret) - dev_err(vadc->dev, "measure reference points failed\n"); return ret; } -- 2.7.4