Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2654276pxj; Mon, 31 May 2021 07:29:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi0U+xxbNwYlVFsli9Qn7sLMlN5Jun0aDgaKjP2PyzpTO9U1iUHJtO4rG14NfNdUnaN5Wc X-Received: by 2002:a02:b897:: with SMTP id p23mr8845292jam.71.1622471383754; Mon, 31 May 2021 07:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471383; cv=none; d=google.com; s=arc-20160816; b=C4g8eGlU+Q3T5HjCHEkgji4L/45HsGz8KrS4ZvkjGAgX269prBtNWrdezdeqaL3MXX MyQZq6Ty3yH04FG6SY6mrZIScvkpYxxB8GpNXid3RFE1qjdEMs9cGs9/huo/HMVHT8aF BdKzuhjnYM6D4GkbTlla33mukl6b68goOvuyo4p0021PWCceIm6e1QmZ21dzUfYM0PPl 7jokly8KG/qVjxxO9nDLv03uLWaJgYzf8k9tdJfOQiUDGknoYO+LHfpZOBR1pcqFNQiy DVA5MdjHOE10sm1fKegpbaQ8+kfLPmlFZ0Xrg9QbBClmywOmBPYTkGJSKPuzRIMFQw7n 1ODQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FBk9eKS0sEubGjZBGJ8Tq7cyeOYFoj5svb2L3jPUjSk=; b=SI+dWZ0dNKQCtyU72Tquo54rGpUMtls9Hv1+CeYs/4h5F3ef7o3MSjewcTCYmOgR65 xTcSxj6Tg8bd1IBZLCsMTiBl/HFxXT/UAfwL5FqDBrsFMCsxGRYeaSlEp/gxA6K5ien0 VfylXe/j8Dls3I7t/cUnIYLWex1HvtcXLgQIuf2IwFx8jNYMIoLJgsd6asdb+U7VfyUZ YQa3CKbBCG/8bRloJkdSDjhG7WL3pL/2qTO+vDs0B4rZULBqKqsvM2sRHqrhy0bnjh33 tA4yeiFcoCn30nNkbUW2yUuahuSTJ/T7e+mLd82HnRBK3JAKK5hXpEOkvTGC+twuw82f f+1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iAxOknIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si607313iln.106.2021.05.31.07.29.30; Mon, 31 May 2021 07:29:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iAxOknIv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232539AbhEaO2h (ORCPT + 99 others); Mon, 31 May 2021 10:28:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:54768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232805AbhEaNws (ORCPT ); Mon, 31 May 2021 09:52:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6EE4461435; Mon, 31 May 2021 13:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622467975; bh=ynVL04ift/6egESuTKn/Fk2adUED9rKiBWSXS2RVsvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iAxOknIv8cDiIF3xn+JkhwiESqtoXM0+W+xLxmucZSSMse4K8vQ6neawdcyIdjZTs TiR2zG0jwe9jDyj5zwG2v/BPCjjConqYYSahxccOBaxku3WuUhCoZyrflXTeh5LIaR Ur/H5pwsjqjyDCS/wYYSCD1eLjHQ8QVtnvrMxdb4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandru Tachici , Alexandru Ardelean , Jonathan Cameron , Stable@vger.kernel.org Subject: [PATCH 5.10 069/252] iio: adc: ad7192: handle regulator voltage error first Date: Mon, 31 May 2021 15:12:14 +0200 Message-Id: <20210531130700.334230098@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandru Ardelean commit b0f27fca5a6c7652e265aae6a4452ce2f2ed64da upstream. This change fixes a corner-case, where for a zero regulator value, the driver would exit early, initializing the driver only partially. The driver would be in an unknown state. This change reworks the code to check regulator_voltage() return value for negative (error) first, and return early. This is the more common idiom. Also, this change is removing the 'voltage_uv' variable and using the 'ret' value directly. The only place where 'voltage_uv' is being used is to compute the internal reference voltage, and the type of this variable is 'int' (same are for 'ret'). Using only 'ret' avoids having to assign it on the error path. Fixes: ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage") Cc: Alexandru Tachici Signed-off-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ad7192.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -912,7 +912,7 @@ static int ad7192_probe(struct spi_devic { struct ad7192_state *st; struct iio_dev *indio_dev; - int ret, voltage_uv = 0; + int ret; if (!spi->irq) { dev_err(&spi->dev, "no IRQ?\n"); @@ -949,15 +949,12 @@ static int ad7192_probe(struct spi_devic goto error_disable_avdd; } - voltage_uv = regulator_get_voltage(st->avdd); - - if (voltage_uv > 0) { - st->int_vref_mv = voltage_uv / 1000; - } else { - ret = voltage_uv; + ret = regulator_get_voltage(st->avdd); + if (ret < 0) { dev_err(&spi->dev, "Device tree error, reference voltage undefined\n"); goto error_disable_avdd; } + st->int_vref_mv = ret / 1000; spi_set_drvdata(spi, indio_dev); st->chip_info = of_device_get_match_data(&spi->dev);