Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3475015imu; Sun, 11 Nov 2018 15:57:56 -0800 (PST) X-Google-Smtp-Source: AJdET5cLpNNrofFtpq0zOift0cQja5eGcHkdufMBX00/k9ZsvPqAHa1GF1d9J/6yoMsi3peu9+qB X-Received: by 2002:a62:27c4:: with SMTP id n187-v6mr2880895pfn.3.1541980676562; Sun, 11 Nov 2018 15:57:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980676; cv=none; d=google.com; s=arc-20160816; b=opD6bSmHo+vqLgDFfB+XwBl71Apn0gEbSr70ZByMLbY21DoYorgydLsiRzkGyLD8Op qL8z0qZCNv0QlM/rKnKFTc2/s+Tg7oagk/EtKbWcw8hyqpuQkX30ysfejQGmjEwQ1IuO k9voyugyUAskiIFg/0yXQDDQCgORYdjB20+Xa+M5D2SN9F61ifIyS07T/+xORD1arPwH Wxy7JKgjLqc01lJiV85CB+s4IrCGeWlE8WcJMBu50lhmzMfiY/Rdzwsr+WYBQ9GqiSu0 UNXT6kwGiwwIHwaUfcH8leTVgTf+ULSZhgHEhGgVrukrc3wO20bq7tDAIcWBOCvkbde7 gbHQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MC9vCOBxXHrZorTFwi3j9Xbe1jFUwbZtHLWqBDcCEcU=; b=DFuAElpyJvSQE+vs1rvwKcYWMPvQr5Lx99I+DQdSFn/7gcZXp8UmDC7mxNyfzubF44 s7h62kGB+mWQxy5WnMXQxNKACvbLcYB3hgaVe/UF5rqeOvz4RVXuyYFdH0HyAH4HrxVM rS+PfwyXmQPiLN7GRF2yuuz5HHC+0f6af8U8EjtS1tPGSy3J3YYJlICBXasyWm3KIMvX QRglS8DO2+PiuKRVVR9Io4ilT0NO9BgzH1iHrg1k69Ev7cCSICZY+8VoRvCME1N7GTui 597bVjzFIzhvxBb7UTYck09QhThggd6Ou1JW7e6/PICM+ArZf8kZfypnPPqn76jm2yPZ oEbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rg5YZNOb; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g21si5046728pgl.114.2018.11.11.15.57.41; Sun, 11 Nov 2018 15:57:56 -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=Rg5YZNOb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732807AbeKLJqb (ORCPT + 99 others); Mon, 12 Nov 2018 04:46:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:35336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732580AbeKLISP (ORCPT ); Mon, 12 Nov 2018 03:18:15 -0500 Received: from localhost (unknown [206.108.79.134]) (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 901E622360; Sun, 11 Nov 2018 22:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975299; bh=pobf9/BtqgtyJtRjaAvarFKm39tJb0XHJ/67eL9fC4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rg5YZNObBfHXm+n5tSRvm0meM5CDHrzIi4pgF2qTb1IbuVupjYOgjb53Qh9LI5LoX pTpbEVDwwJKaMmoZ2iGRUhLDrVzphcMQPXvJRlYt4x2ti+83vTapGGRS531KEeiY4Z cEZDcm4RKYgkDkOLTVXrBXmhlVkFyO6vRXGSHU3U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 4.19 258/361] iio: ad5064: Fix regulator handling Date: Sun, 11 Nov 2018 14:20:05 -0800 Message-Id: <20181111221653.751949444@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lars-Peter Clausen commit 8911a43bc198877fad9f4b0246a866b26bb547ab upstream. The correct way to handle errors returned by regualtor_get() and friends is to propagate the error since that means that an regulator was specified, but something went wrong when requesting it. For handling optional regulators, e.g. when the device has an internal vref, regulator_get_optional() should be used to avoid getting the dummy regulator that the regulator core otherwise provides. Signed-off-by: Lars-Peter Clausen Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/dac/ad5064.c | 53 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) --- a/drivers/iio/dac/ad5064.c +++ b/drivers/iio/dac/ad5064.c @@ -808,6 +808,40 @@ static int ad5064_set_config(struct ad50 return ad5064_write(st, cmd, 0, val, 0); } +static int ad5064_request_vref(struct ad5064_state *st, struct device *dev) +{ + unsigned int i; + int ret; + + for (i = 0; i < ad5064_num_vref(st); ++i) + st->vref_reg[i].supply = ad5064_vref_name(st, i); + + if (!st->chip_info->internal_vref) + return devm_regulator_bulk_get(dev, ad5064_num_vref(st), + st->vref_reg); + + /* + * This assumes that when the regulator has an internal VREF + * there is only one external VREF connection, which is + * currently the case for all supported devices. + */ + st->vref_reg[0].consumer = devm_regulator_get_optional(dev, "vref"); + if (!IS_ERR(st->vref_reg[0].consumer)) + return 0; + + ret = PTR_ERR(st->vref_reg[0].consumer); + if (ret != -ENODEV) + return ret; + + /* If no external regulator was supplied use the internal VREF */ + st->use_internal_vref = true; + ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE); + if (ret) + dev_err(dev, "Failed to enable internal vref: %d\n", ret); + + return ret; +} + static int ad5064_probe(struct device *dev, enum ad5064_type type, const char *name, ad5064_write_func write) { @@ -828,22 +862,11 @@ static int ad5064_probe(struct device *d st->dev = dev; st->write = write; - for (i = 0; i < ad5064_num_vref(st); ++i) - st->vref_reg[i].supply = ad5064_vref_name(st, i); + ret = ad5064_request_vref(st, dev); + if (ret) + return ret; - ret = devm_regulator_bulk_get(dev, ad5064_num_vref(st), - st->vref_reg); - if (ret) { - if (!st->chip_info->internal_vref) - return ret; - st->use_internal_vref = true; - ret = ad5064_set_config(st, AD5064_CONFIG_INT_VREF_ENABLE); - if (ret) { - dev_err(dev, "Failed to enable internal vref: %d\n", - ret); - return ret; - } - } else { + if (!st->use_internal_vref) { ret = regulator_bulk_enable(ad5064_num_vref(st), st->vref_reg); if (ret) return ret;