Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1679134ioo; Mon, 23 May 2022 00:03:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9PkrSx2WEIHloyPKiw7u91GPtlMz4OA49ibQaoaCAalaQOZaUWT0GOruKPi+eYsnmZ883 X-Received: by 2002:a17:90b:38c2:b0:1e0:3144:380e with SMTP id nn2-20020a17090b38c200b001e03144380emr8720722pjb.168.1653289396446; Mon, 23 May 2022 00:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653289396; cv=none; d=google.com; s=arc-20160816; b=jIu002iw1LbsmvhBKI9gN+hxisdGyT3/0oGa1bsJ8CNOAP3JpoIOaUkTfd4+f2cqI4 Dt7yY0zdMwvO+Tzg2GfzLyu+9Fhvi8CfjMGaE/czqAbqwNKzfxm7Zro1qOG7hcKcVvWs fP4DGy8VagxSTsc4RLIFXwnJ1NLMKO5tN+I3s/extMD+BP5qM80WoMxYjFoVxnKRE6La llviwe54shsZYrocKmI/8TN5BVXlqhmyugXla53N6HF5TqUXkN8Gfn9XGJY+UxIdxupN gBOF3PVdsLVWCSb9MS3O9VGUNo9Rc4r0/lsNZgDWWKVE+0xygQEiaaol+gc6CoVZ3/ph zoSg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=fsDvDilthoT12BtzbkwqlUA4juwEkPtliZoySrVSwLs=; b=KZrGX+dNaYHhHs2g2rGsFpn/YNGkXzHgVDKm0VRZ8tKm/YkV1BVrgbKc2ndAKfucuz 4/LW7ixz/jBopnNt08b+4WZRe7VzaJewyIwyENVx3HkQdCXEZMvq470NztqCD6rpPyjP Y/alUy11bGg4m5841i/G8vm67VFWTDGsc1bB8NpstC664HtzlIxWW3f27XCyoVRMi7Rk 0/lUbe1CIVtf+7zxAJfJcyks/tcHs+YHSzJREZe4AhOLEovigg2TUZq3gwhN7k+ZCL3k AHkNFB7CwqOeLex9I5YtypA6Avy0ujJY8KbbAjfsaazajZoeAgiWTA36bu4/vrwVnLmR OT8A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c20-20020a170902b69400b00161a06e7f53si8799575pls.292.2022.05.23.00.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:03:16 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF12063EA; Sun, 22 May 2022 23:25:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352073AbiETRNa (ORCPT + 99 others); Fri, 20 May 2022 13:13:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238817AbiETRN2 (ORCPT ); Fri, 20 May 2022 13:13:28 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A809AAFAFD; Fri, 20 May 2022 10:13:27 -0700 (PDT) Received: from fraeml713-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4L4YFx32Hbz6H6mq; Sat, 21 May 2022 01:13:09 +0800 (CST) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by fraeml713-chm.china.huawei.com (10.206.15.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 20 May 2022 19:13:25 +0200 Received: from localhost (10.122.247.231) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 20 May 2022 18:13:24 +0100 Date: Fri, 20 May 2022 18:13:23 +0100 From: Jonathan Cameron To: Yongzhi Liu CC: , , , , , , , Subject: Re: [PATCH v2] iio: vadc: Fix potential dereference of NULL pointer Message-ID: <20220520181323.00002892@huawei.com> In-Reply-To: <1652939455-123139-1-git-send-email-lyz_cs@pku.edu.cn> References: <1652939455-123139-1-git-send-email-lyz_cs@pku.edu.cn> Organization: Huawei Technologies R&D (UK) Ltd. X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.29; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhreml737-chm.china.huawei.com (10.201.108.187) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_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 On Wed, 18 May 2022 22:50:55 -0700 Yongzhi Liu wrote: > 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 This function has a lot of goto err; where err just results in a print. My suggestion is to just drop that print and use error specific prints as you have done here, then use direct returns. > --- > 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;