From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753972AbdBAWXg (ORCPT ); Wed, 1 Feb 2017 17:23:36 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33631 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752974AbdBAWXf (ORCPT ); Wed, 1 Feb 2017 17:23:35 -0500 Date: Wed, 1 Feb 2017 14:23:31 -0800 From: Dmitry Torokhov To: Mark Brown Cc: Thierry Reding , Jelle van der Waa , Linus Walleij , linux-kernel@vger.kernel.org Subject: regulator_get_optional() no longer returning NULL? Message-ID: <20170201222331.GE40720@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mark, It appears that [devm_]regulator_get_optional() and [devm_]gpiod_get_optional() behave irritatingly differently. While the latter returns NULL for non-existing GPIOs, the former started returning -ENODEV instead of NULL, starting with commit below. Why did we do that? It is much more convenient to write: data->vcc = devm_regulator_get_optional(dev. "vcc"); if (IS_ERR(data->vcc)) return ERR_PTR(data->vcc); ... if (data->vcc) do_stuff(); vs. data->vcc = devm_regulator_get_optional(dev. "vcc"); if (IS_ERR(data->vcc)) { error = ERR_PTR(data->vcc); if (error != -ENODEV && error != ) return error; data->vcc = NULL; } I.e. it is nice to treat *all* codes returned by devm_regulator_get_optional() as fatal and NULL as special instead of vetting by hand (and having chance that list of vetted codes will bit rot). Can we please revert this patch? Thanks! -- Dmitry commit ef60abbb6b406389245225ab4acfe73f66e7d92c Author: Mark Brown Date: Mon Sep 23 16:12:52 2013 +0100 regulator: core: Always use return value when regulator_dev_lookup() fails Ensure that the return value is always set when we return now that the logic has changed for regulator_get_optional() so we don't get missing codes leaking out. Reported-by: Thierry Reding Tested-by: Thierry Reding Signed-off-by: Mark Brown diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 088b41ac9506..a40055edaae4 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1263,12 +1263,13 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, if (rdev) goto found; + regulator = ERR_PTR(ret); + /* * If we have return value from dev_lookup fail, we do not * expect to * succeed, so, quit with appropriate error value */ if (ret && ret != -ENODEV) { - regulator = ERR_PTR(ret); goto out; }