Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3430903imu; Sun, 11 Nov 2018 14:57:35 -0800 (PST) X-Google-Smtp-Source: AJdET5exqUhJ87Pgvkuu8eZ7CallDuaCKOQlYdd/Pm2Ti1iB43QCSL0dQ4jVTbqJXWAdbRA8KKMP X-Received: by 2002:a17:902:50e3:: with SMTP id c32-v6mr17526142plj.39.1541977055355; Sun, 11 Nov 2018 14:57:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977055; cv=none; d=google.com; s=arc-20160816; b=bVsWvmnrUSr1DQRdxKFG6fDa/TyknuhWhVQUoykDi23SfkkEzJFDc008/HbAOR46DY b7U9292jrgvXDREuQ5FBbaix5Mpfu8mZFuGB9n3xjYARznJ75Z/rOT10AIBRjGDvd+zD bncFOf939ntgE79NsnUi+a7tIuN7v/K/dKUOjyN2eRfA9GF3jWttdPnHxl7jZCsL8ua8 pLXaycxvyzWeW9gJJjuZH76qR/9iGZpbKObeqbEgiUD418WlaVsW49m9rBXPcs+IIglm G8wCv4GYuQA9ZfgFNxgxQ9eMgfCN3Kfm6t1lp8R3mpbBJQs/gczaTyWGmny4xX8iyCzZ lkCw== 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=L1bu7uWtbMJSVEi9bVUjTueRVFCQuMc5pGPlv6txmUA=; b=AO1Ql4QXdaEBEPwcwCZKfUhHJD0uopgSk6pW9UibQzXGVhkDhAF7tpUxX5q1inK2Nu YwSvYIEain0XZYclPfTeRnXGFno6fkTVyG7sYtUt+zHOogOTPrgcIhNTwR4OY3If2Lpv y8Y5NHzv2/vjy6a0QG0q/A2mWYqugSK0lwdGrQJ1CUerpZ0Sa1CZFH9Ru6MTLCO09YOK Y/Wc5P5Vro1k1Nfa3Hw5rLRTTLqIsp86NISraNY55wnLE4q7Wi3PXMinFen8OAQL+5BD qDejHVA/w9cRPa1sujZMqE+cDdPhYTURsnfFnuvSxRm0So7MD5iE6aF93LhWkpzgktdk /glA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pA6E4JE6; 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 f10si14801955pgl.528.2018.11.11.14.57.20; Sun, 11 Nov 2018 14:57:35 -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=pA6E4JE6; 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 S2404026AbeKLIpv (ORCPT + 99 others); Mon, 12 Nov 2018 03:45:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:54642 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403867AbeKLIWy (ORCPT ); Mon, 12 Nov 2018 03:22:54 -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 8B09622419; Sun, 11 Nov 2018 22:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975576; bh=g0/YgQDSvhy4z9Tt4YNoAPmR0i9xIzc5x2fg9AqhYQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pA6E4JE6yG3nELQSiWcmeABJDZX7fISMkUS0voH9foPTg1lDJhKgeObHV7jpjXBpH An7wTYO5JhJ1z5Nty8u8NdxTRRaK9c1/8ILAiJ6XxceW4a0OCiMj5DXcJSnQqeosNg wODuJ9/JdJk1HktygW32ccL/bprJFTCQl0kdLoPg= 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.14 159/222] iio: ad5064: Fix regulator handling Date: Sun, 11 Nov 2018 14:24:16 -0800 Message-Id: <20181111221701.532553252@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -809,6 +809,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) { @@ -829,22 +863,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;