Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp608511pxj; Thu, 13 May 2021 12:27:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlKOFQuR2bFONyqR+gzgk32iu1nPXfzdFfGX2PYxyln9EopbI/Eaj/XeuRMDtUELvfWg+q X-Received: by 2002:a5d:814d:: with SMTP id f13mr9226010ioo.203.1620934056495; Thu, 13 May 2021 12:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620934056; cv=none; d=google.com; s=arc-20160816; b=HoVk2rCfm075e8e7O7aTfL1ZfX/7StgfDxliWF8eGLKJCHlaXc6yEfx93l3Sqoo7mz JThx90yvr+gBs45xLgb8CtYlZm9bSgwQPmFVmDHVRTFXM3iQ2Pas460/m1r6TeRc75d6 EIjPvokx7Zn9Iq1iUW9XUdDYhVizA2ovslBG74qr8Jc6uyUUKuHbd3tZzPZ8L8JwlRWW 1rvXubR1dc3lwuqhpHRm/gFeuEIbXhkxw54HudnQuPR4X6gW2KHHpVK+7BRUazW7OA+0 plolabjCiSduLYsNFJDmWctg6XxMOqCmySiCUbFgnyZCXI/sNKrAGTcx9VcNFANJ8tZ0 D1iw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AYfwt0+BPoPpQia/fg8ETgJym9nebkYzxG2me6iZXys=; b=gphhMbgwPfZRc7foSznpOGLYDJMsoBOA9hivSHHFfUR4K7qqNCjMywbqMQjQsSSOhu yeXpUcQGo3MdpQeB5NCC+/Ed/pvEgv+j/ornYhp3V8OREAt7qSP77PqxwXy2YecEg+g9 gibyvKwnNAsikhISiVl5gAkagcTzsf8t4cYexW7eCbSZWYIsQKoFo7gU7hsPCIl7vL37 oGNGvsgWBcEvvycDSUiDXYmdfA9kAo50R7/qzBBYYzBVXe+CCwxgLDTATDy1htjiAabE oUttkF+X6GSc50VOL7OtqamxzcOReMq7wEwdhia3CNb4ti0AozlZmatntY1Gz7iySDyg sHUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deviqon.com header.s=google header.b=akAB22Kn; 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=deviqon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si4906016jao.90.2021.05.13.12.27.23; Thu, 13 May 2021 12:27:36 -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=@deviqon.com header.s=google header.b=akAB22Kn; 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=deviqon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233756AbhEMMKy (ORCPT + 99 others); Thu, 13 May 2021 08:10:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233687AbhEMMJQ (ORCPT ); Thu, 13 May 2021 08:09:16 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33234C061760 for ; Thu, 13 May 2021 05:08:04 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id v5so19614928edc.8 for ; Thu, 13 May 2021 05:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deviqon.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AYfwt0+BPoPpQia/fg8ETgJym9nebkYzxG2me6iZXys=; b=akAB22KnxxmRLi7sNZWOmYFGksvK4Box/xAKQoVwEKqVEl3YoHISkwbj41FLsXWvtk olpX+WNiH9kUG7gNnhH5kDsulv1F/CjvNGmbQiF5iMZNX7wMspmZblouYH3mIkbkXn9X s9Kh6flgP/6QQa4AxdOY+xXz5MNIlw+YQkXlAu0lWZLrJTHQuzpGzYqVAIDYFw0qpiC3 iLdLQHuYm5u+VbIBFyGma8cigT6+VkHFU/I3ZTWsHj2vNS9won7Um1fGSJqQaqTTfS4t 1ktzGjGNJS8M0mitYt+P2uVtRKGwUmDBDYbsBd+3ToVhyMIGuOhXPETYdWIPaNTGo0Jq /42Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AYfwt0+BPoPpQia/fg8ETgJym9nebkYzxG2me6iZXys=; b=bT2RgYcJRq1pDpgt5fjCMjvuv4SDseOl54a3oiadhubjAdHClLKVFj+np8PPaZ4aOJ zzkXjq0OvCVZ9OyQw22qcmISIVOlOZo4dze9wgaQLStL52cbvrLgpexc//iLyD6zLdAA iBEvhlcIdfSOqnX3fxiG4srbl8Dm+kWaGQRtjkPlGYBhAYpkJCiNQ6bLxHvZHgnp7KkY Ac4sF48h4HRDMSqcZhiVNvec9g1l48XjEkx6j3PwsBjuCs5VrxCUZIZrFxVLzr3RJrkF 932W0urpq9WEDxXAvjNwknmOKmsaSM9TWZ4R3U0+rKW587u21WKmcUX0ydTMgxgkVbUB FnKw== X-Gm-Message-State: AOAM5308oeifcUppOZ+NHZ3UEGIwwnTcTvqg63iRpvSKpz59tCGzZJBU onzyQpuvrXLiY7JYkXIUz2Obag== X-Received: by 2002:a05:6402:3548:: with SMTP id f8mr49327140edd.251.1620907683002; Thu, 13 May 2021 05:08:03 -0700 (PDT) Received: from neptune.. ([5.2.193.191]) by smtp.gmail.com with ESMTPSA id ga28sm1717809ejc.20.2021.05.13.05.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 05:08:02 -0700 (PDT) From: Alexandru Ardelean To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jic23@kernel.org, Jonathan.Cameron@huawei.com, alexandru.tachici@analog.com, linux@deviqon.com, Alexandru Ardelean Subject: [PATCH v4 04/12] iio: adc: ad7192: handle regulator voltage error first Date: Thu, 13 May 2021 15:07:44 +0300 Message-Id: <20210513120752.90074-5-aardelean@deviqon.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210513120752.90074-1-aardelean@deviqon.com> References: <20210513120752.90074-1-aardelean@deviqon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/iio/adc/ad7192.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c index d3be67aa0522..1141cc13a124 100644 --- a/drivers/iio/adc/ad7192.c +++ b/drivers/iio/adc/ad7192.c @@ -912,7 +912,7 @@ static int ad7192_probe(struct spi_device *spi) { 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_device *spi) 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); -- 2.31.1