From patchwork Tue Oct 5 22:09:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 234031 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o95M9hFt030401 for ; Tue, 5 Oct 2010 22:09:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757227Ab0JEWJm (ORCPT ); Tue, 5 Oct 2010 18:09:42 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:45826 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755052Ab0JEWJm (ORCPT ); Tue, 5 Oct 2010 18:09:42 -0400 Received: by fxm4 with SMTP id 4so813776fxm.19 for ; Tue, 05 Oct 2010 15:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=rJ1wm0IMfoawtec93EQQhpszMWDYpfolBsyShP+5O6E=; b=dsyXTbNMkDK7Ihf1i6s8ld2ZaifKMWrcfJwkUNp9R2OTE+skzV2QnlE6pRkBp+GLQi OtQxCBLEXLcKnyhdmifbzTn9vzLsLHsvwsW0/mV8vClzImhhvuYYfkxcQ/VUeX9iDAqz +BlGP5OkfDOvEJY8vzc+aG4SaFSYSsnOZOezI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=rUoTI3pmVpgG248ci8W/q7Ff5Mcc+Y/GtVPfLyEpZb61GBIJ6clxoxSXHfHvzPTTwa XO9qSdIk2Pwj0sIzsebIPZ+Bmh8PUpB0bc/VnmLSg6xonbBeBWEKy8XD4GQz4Xw7RZtH QD0tCG5r746/0V4hX8OCq+w5YRY8oIrXeY0gU= MIME-Version: 1.0 Received: by 10.103.2.5 with SMTP id e5mr3939809mui.103.1286316580423; Tue, 05 Oct 2010 15:09:40 -0700 (PDT) Received: by 10.103.173.18 with HTTP; Tue, 5 Oct 2010 15:09:39 -0700 (PDT) In-Reply-To: <20101005203508.7df590db@lxorguk.ukuu.org.uk> References: <1280560182-7071-1-git-send-email-marek.vasut@gmail.com> <4C862EB3.4080006@compulab.co.il> <20100907125335.GD25830@sirena.org.uk> <201009091027.18176.marek.vasut@gmail.com> <20100909094120.GB1988@rakim.wolfsonmicro.main> <4CAACA63.6090202@compulab.co.il> <20101005161608.GD19730@core.coreip.homeip.net> <20101005164037.GA20555@opensource.wolfsonmicro.com> <20101005180703.GD21399@core.coreip.homeip.net> <20101005185942.GA22808@opensource.wolfsonmicro.com> <20101005203508.7df590db@lxorguk.ukuu.org.uk> Date: Wed, 6 Oct 2010 00:09:39 +0200 Message-ID: Subject: Re: [PATCH v2] Input: Make ADS7846 independent on regulator From: Linus Walleij To: Alan Cox Cc: Mark Brown , Dmitry Torokhov , Igor Grinberg , Marek Vasut , linux-arm-kernel@lists.infradead.org, vapier@gentoo.org, khilman@deeprootsystems.com, linux-kernel@vger.kernel.org, pavel@ucw.cz, linux-input@vger.kernel.org, eric.y.miao@gmail.com, akpm@linux-foundation.org Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 05 Oct 2010 22:09:44 +0000 (UTC) diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index ebd7472..6ee7fdc 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -36,6 +36,7 @@ #define __LINUX_REGULATOR_CONSUMER_H_ #include +#include /* * Regulator operating modes. @@ -297,4 +298,23 @@ static inline void regulator_set_drvdata(struct regulator *regulator, #endif +/* + * Try to get a regulator, if it fails, no big deal. + * This wrapper function is intended to be used for code + * where regulator control is optional for the particular + * consumer, but still the regulator framework may be in + * use for other things in the platform. + */ +static inline struct regulator *regulator_try_get(struct device *dev, + const char *id) +{ + struct regulator *reg = regulator_get(dev, id); + + /* It's just that this regulator is not (yet) defined */ + if (IS_ERR(reg) && PTR_ERR(reg) == -ENODEV) + return NULL; + + return reg; +} + #endif -- 1.7.2.3 From: Linus Walleij Date: Wed, 6 Oct 2010 00:04:25 +0200 Subject: [PATCH 2/2] regulator: handle NULL regulators in core If the user has selected to use regulator_try_get() to fetch regulators, we bail out of consumer operations if the regulator happens to be NULL. Signed-off-by: Linus Walleij --- drivers/regulator/core.c | 64 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 55 insertions(+), 9 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index cc8b337..989e4e4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1337,9 +1337,12 @@ static int _regulator_enable(struct regulator_dev *rdev) */ int regulator_enable(struct regulator *regulator) { - struct regulator_dev *rdev = regulator->rdev; + struct regulator_dev *rdev; int ret = 0; + if (regulator == NULL) + return 0; + rdev = regulator->rdev; mutex_lock(&rdev->mutex); ret = _regulator_enable(rdev); mutex_unlock(&rdev->mutex); @@ -1406,9 +1409,12 @@ static int _regulator_disable(struct regulator_dev *rdev) */ int regulator_disable(struct regulator *regulator) { - struct regulator_dev *rdev = regulator->rdev; + struct regulator_dev *rdev; int ret = 0; + if (regulator == NULL) + return 0; + rdev = regulator->rdev; mutex_lock(&rdev->mutex); ret = _regulator_disable(rdev); mutex_unlock(&rdev->mutex); @@ -1456,6 +1462,8 @@ int regulator_force_disable(struct regulator *regulator) { int ret; + if (regulator == NULL) + return 0; mutex_lock(®ulator->rdev->mutex); regulator->uA_load = 0; ret = _regulator_force_disable(regulator->rdev); @@ -1489,6 +1497,8 @@ int regulator_is_enabled(struct regulator *regulator) { int ret; + if (regulator == NULL) + return 1; mutex_lock(®ulator->rdev->mutex); ret = _regulator_is_enabled(regulator->rdev); mutex_unlock(®ulator->rdev->mutex); @@ -1507,8 +1517,11 @@ EXPORT_SYMBOL_GPL(regulator_is_enabled); */ int regulator_count_voltages(struct regulator *regulator) { - struct regulator_dev *rdev = regulator->rdev; + struct regulator_dev *rdev; + if (regulator == NULL) + return 0; + rdev = regulator->rdev; return rdev->desc->n_voltages ? : -EINVAL; } EXPORT_SYMBOL_GPL(regulator_count_voltages); @@ -1525,10 +1538,15 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages); */ int regulator_list_voltage(struct regulator *regulator, unsigned selector) { - struct regulator_dev *rdev = regulator->rdev; - struct regulator_ops *ops = rdev->desc->ops; + struct regulator_dev *rdev; + struct regulator_ops *ops; int ret; + if (regulator == NULL) + return 0; + rdev = regulator->rdev; + ops = rdev->desc->ops; + if (!ops->list_voltage || selector >= rdev->desc->n_voltages) return -EINVAL; @@ -1561,6 +1579,8 @@ int regulator_is_supported_voltage(struct regulator *regulator, { int i, voltages, ret; + if (regulator == NULL) + return 0; ret = regulator_count_voltages(regulator); if (ret < 0)