Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965247Ab3HHLZh (ORCPT ); Thu, 8 Aug 2013 07:25:37 -0400 Received: from mail.active-venture.com ([67.228.131.205]:53078 "EHLO mail.active-venture.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757767Ab3HHLZf (ORCPT ); Thu, 8 Aug 2013 07:25:35 -0400 X-Originating-IP: 108.223.40.66 Message-ID: <52038035.7030803@roeck-us.net> Date: Thu, 08 Aug 2013 04:25:41 -0700 From: Guenter Roeck User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: Mark Brown CC: Wei Ni , khali@linux-fr.org, swarren@wwwdotorg.org, linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org, MLongnecker@nvidia.com, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 1/3] hwmon: (lm90) Add power control References: <1375944991-29182-1-git-send-email-wni@nvidia.com> <1375944991-29182-2-git-send-email-wni@nvidia.com> <20130808110136.GA6427@sirena.org.uk> In-Reply-To: <20130808110136.GA6427@sirena.org.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2375 Lines: 61 On 08/08/2013 04:01 AM, Mark Brown wrote: > On Thu, Aug 08, 2013 at 02:56:29PM +0800, Wei Ni wrote: > >> + mutex_lock(&data->update_lock); >> + >> + if (is_enable) >> + ret = regulator_enable(data->lm90_reg); >> + else >> + ret = regulator_disable(data->lm90_reg); >> + >> + if (ret < 0) >> + dev_err(&client->dev, >> + "Error in %s rail vdd, error %d\n", >> + (is_enable) ? "enabling" : "disabling", ret); >> + else >> + dev_info(&client->dev, "success in %s rail vdd\n", >> + (is_enable) ? "enabling" : "disabling"); >> + >> + mutex_unlock(&data->update_lock); > > Two things here. One is that it's not clear what this lokc is > protecting since the only thing in the locked region is the regulator > operation and that is thread safe. The other thing is that I'm not > seeing anthing that ensures that enables and disables are matched - > regulators are reference counted so two enables need two disables. > >> + data->lm90_reg = regulator_get(&client->dev, "vdd"); >> + if (IS_ERR_OR_NULL(data->lm90_reg)) { > > NULL is a valid regulator, use IS_ERR(). > >> + if (PTR_ERR(data->lm90_reg) == -ENODEV) >> + dev_info(&client->dev, >> + "No regulator found for vdd. Assuming vdd is always powered."); >> + else >> + dev_warn(&client->dev, >> + "Error [%ld] in getting the regulator handle for vdd.\n", >> + PTR_ERR(data->lm90_reg)); > > You shouldn't just be ignoring errors here, though there are deployment > difficulties with making sure a stub regulator is provided. These > should be getting easier after the next merge window, the stubs will be > being tweaked slightly to have an "assume it's there" option even when > regulators are used. Especially in cases with device tree you should be > paying attention to -EPROBE_DEFER, that will accurately reflect if a > regulator is present but not loaded yet. > > That said if you *are* going to do this you should request the > regulator using devm_regulator_get_optional(), this is intended to > support things that don't need regulators (though that's not the case > here). > The lm90 driver works perfectly fine without regulator. Guenter -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/