Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp768078ybc; Sat, 16 Nov 2019 08:20:49 -0800 (PST) X-Google-Smtp-Source: APXvYqxwmt6WrC3hqgxwByPJHRcm+YBbJ5Bo13nMraxFtVkh6iomeDSfKy6IBmN5SY8wL2/ljvqo X-Received: by 2002:a17:906:c45:: with SMTP id t5mr10562762ejf.296.1573921249796; Sat, 16 Nov 2019 08:20:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921249; cv=none; d=google.com; s=arc-20160816; b=VXGRNmzPRerNiXhewYfbZeSyrqmXDxTDzKUn87pqmV4DxixpnsTayZrEy9lDpaZbVA FjmPuK6riThWBQziaB6Wf3OGUIYRnceoVBKddfWbmaJs5aGEJmgVVtkJDEckFtUdzOgI sSihI1k3Q3ExjwlOCW3gzzVV2hQ3KrGC8a3lGhyhJ8XKDer0rALdxTZc0+/9ztGkQxzM w3mV4h5xTN+ob2Sq2g0UMIwl8I2O6hoC8xBHUk8vuEPLR6lk74wrwiGEcbQy2ffY8mBo 7vAF2LWhSKUGd+/bUmu9xGL7rAlAsAkj6dV5lfLR2RMAtTI8I+SYP2QuZG9l+Y65xEv3 gNtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=ZiKX0dRqytl+M4Lrec/e6PcNRfgbzVtU17fmZQWPQzs=; b=BV1Fw2pWdoSEbT6QrwwR2UdobF3RjXjOY74rPXAZm8Qq3BD66G89UJheMykQPPgYxd +DLC/+a9TagiVKsIf++KN/S8V1T8G2cjEmadnMUh1w1w80yKqg7Sw1ifj1g2NywSU/tp LPNC5yhx0dXoap7t1VQSmSLFBxDA7EN9aJbNrLj4+6+kB2shQzyFFMy7Cpc+TVrRjL+g ah4AWAmbMAe+goqotRhaiF98xXHFQKruEYsNAmMy54Z9y6quJqbP0d4PD1R9MYiEmcEb IIjMSWadiLbos877ZkkNIi99Sh60eNc6UepPKq8p61R7ewehJxp5LGNIRXWyorOT3WlW 31mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NiwuN3cA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si9346575eda.375.2019.11.16.08.20.25; Sat, 16 Nov 2019 08:20:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NiwuN3cA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731457AbfKPQSG (ORCPT + 99 others); Sat, 16 Nov 2019 11:18:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:35438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729820AbfKPQR6 (ORCPT ); Sat, 16 Nov 2019 11:17:58 -0500 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2AE0021844; Sat, 16 Nov 2019 16:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573921078; bh=PoAjATiyMw59a4B+QqOkZq9Qem/RNBGHAwCV08vIXVA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NiwuN3cA5wNzoy+x+tLZQfyxvfyWNPzhLN6tZr4PAOrsYM5JegUavQuoUHPsTD8xk W7IrhDvv90baPuGBVxR33GKjGPY8OXFsepKcSuvuzXQLvaYJLs80YkOCVDbTnX6Z8u dH145/up7L911obt7v5ID9W3H/3IcMgPi51jqtx0= Date: Sat, 16 Nov 2019 16:17:53 +0000 From: Jonathan Cameron To: Alexandru Tachici Cc: , , Subject: Re: [PATCH] iio: dac: ad7303: use regulator get optional to check for ext supply Message-ID: <20191116161753.24d620df@archlinux> In-Reply-To: <20191113083303.2229-1-alexandru.tachici@analog.com> References: <20191113083303.2229-1-alexandru.tachici@analog.com> X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 13 Nov 2019 10:33:03 +0200 Alexandru Tachici wrote: > Previously, the code was using the of_read_property_bool() to check if > an external regulator was provided. However, this is redundant, as it's > more simple/direct to just ask the regulator is provided, via a > `devm_regulator_get_optional()` call. > > Signed-off-by: Alexandru Tachici Hi. I agree in principle but I don't think devm_regulator_get_optional returns NULL when a regulator isn't supplied. Thanks, Jonathan > --- > drivers/iio/dac/ad7303.c | 23 +++++------------------ > 1 file changed, 5 insertions(+), 18 deletions(-) > > diff --git a/drivers/iio/dac/ad7303.c b/drivers/iio/dac/ad7303.c > index 14bbac6bee98..e0c5fed4475c 100644 > --- a/drivers/iio/dac/ad7303.c > +++ b/drivers/iio/dac/ad7303.c > @@ -12,7 +12,6 @@ > #include > #include > #include > -#include > > #include > #include > @@ -202,7 +201,6 @@ static int ad7303_probe(struct spi_device *spi) > const struct spi_device_id *id = spi_get_device_id(spi); > struct iio_dev *indio_dev; > struct ad7303_state *st; > - bool ext_ref; > int ret; > > indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); > @@ -224,24 +222,13 @@ static int ad7303_probe(struct spi_device *spi) > if (ret) > return ret; > > - if (spi->dev.of_node) { > - ext_ref = of_property_read_bool(spi->dev.of_node, > - "REF-supply"); > - } else { > - struct ad7303_platform_data *pdata = spi->dev.platform_data; > - if (pdata && pdata->use_external_ref) > - ext_ref = true; > - else > - ext_ref = false; > + st->vref_reg = devm_regulator_get_optional(&spi->dev, "REF"); > + if (IS_ERR(st->vref_reg)) { > + ret = PTR_ERR(st->vref_reg); devm_regulator_get_optional returns a ptr encoding -ENODEV if the regulator is not supplied. That isn't an error here so needs to be handled differently from other error codes. > + goto err_disable_vdd_reg; > } > > - if (ext_ref) { > - st->vref_reg = devm_regulator_get(&spi->dev, "REF"); > - if (IS_ERR(st->vref_reg)) { > - ret = PTR_ERR(st->vref_reg); > - goto err_disable_vdd_reg; > - } > - > + if (st->vref_reg) { > ret = regulator_enable(st->vref_reg); > if (ret) > goto err_disable_vdd_reg;