From patchwork Thu Apr 17 18:55:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Kryger X-Patchwork-Id: 28588 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 78AC22188F for ; Thu, 17 Apr 2014 18:55:50 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rp16sf2870486pbb.9 for ; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type; bh=51fkSc/blXeL+ZmKEICoxRmAZw3DOuPMlkLW0TjwyLg=; b=TXyCF3SyxhuuecRfqD2ArNOJZViPQlc6EgHY5YZcyz2XzcDd4vq1CLY2KrzjIaakni oEnLDMuOAEHMhPgn1L3XHq7AsoWp8CK5oAmGUaoTQpPeobeciuwxScX3cj8E1OS1SGZS MkDPZMVtEZY+TS16qC7Cf9lUSVbzCC0Ca/nickuaiZY53pU7Lv25mLFlaT1sDUimJtHP Zi5sQs13Yp0oycsP2smPU7ITkkj+yZ9H9cqCaWXScblsHbvH+QURNANnG0ZDRpLzAimv GgL2iTHl0hxk3Yw5weZ4S1VTkKQSgIeD9v719mTOX+OSFxzCKG+8oZm6e5sgKisuhawK 2IVA== X-Gm-Message-State: ALoCoQkKjKWMsU+FvrGc3UCLN5RC6+ZiFR7RKSDuvL7mW3Gf/NieL14oTUsgRrYa/HtL2LEPjeqk X-Received: by 10.66.173.75 with SMTP id bi11mr8472490pac.4.1397760949772; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.82.231 with SMTP id h94ls1230878qgd.61.gmail; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) X-Received: by 10.58.122.164 with SMTP id lt4mr13003505veb.2.1397760949590; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id cb3si4594662vdc.41.2014.04.17.11.55.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 17 Apr 2014 11:55:49 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so1000495veb.0 for ; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr8971604veb.21.1397760949489; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp58037vcb; Thu, 17 Apr 2014 11:55:49 -0700 (PDT) X-Received: by 10.66.180.141 with SMTP id do13mr17377529pac.93.1397760948792; Thu, 17 Apr 2014 11:55:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ev1si9851270pbb.251.2014.04.17.11.55.47; Thu, 17 Apr 2014 11:55:48 -0700 (PDT) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751997AbaDQSzk (ORCPT + 26 others); Thu, 17 Apr 2014 14:55:40 -0400 Received: from mail-gw1-out.broadcom.com ([216.31.210.62]:15928 "EHLO mail-gw1-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751337AbaDQSz3 (ORCPT ); Thu, 17 Apr 2014 14:55:29 -0400 X-IronPort-AV: E=Sophos;i="4.97,880,1389772800"; d="scan'208";a="25331368" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw1-out.broadcom.com with ESMTP; 17 Apr 2014 12:59:38 -0700 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 17 Apr 2014 11:55:28 -0700 Received: from mail-sj1-12.sj.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.174.1; Thu, 17 Apr 2014 11:55:28 -0700 Received: from dhcp-sv1-10-19-114-209.sj.broadcom.com (mps-infra-lab3.sj.broadcom.com [10.19.114.109]) by mail-sj1-12.sj.broadcom.com (Postfix) with ESMTP id 2D62F27A81; Thu, 17 Apr 2014 11:55:28 -0700 (PDT) Received: by dhcp-sv1-10-19-114-209.sj.broadcom.com (Postfix, from userid 1004) id E7F822520E7E; Thu, 17 Apr 2014 11:55:27 -0700 (PDT) From: Tim Kryger To: Liam Girdwood , Mark Brown CC: Tim Kryger , Linux Kernel Mailing List Subject: [PATCH] regulator: core: Return error in get optional stub Date: Thu, 17 Apr 2014 11:55:24 -0700 Message-ID: <1397760924-7423-1-git-send-email-tim.kryger@linaro.org> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: tim.kryger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Drivers that call regulator_get_optional are tolerant to the absence of that regulator. By modifying the value returned from the stub function to match that seen when a regulator isn't present, callers can wrap the regulator logic with an IS_ERR based conditional even if they happen to call regulator_is_supported_voltage. This improves efficiency as well as eliminates the possibility for a very subtle bug. Signed-off-by: Tim Kryger Reviewed-by: Alex Elder --- This change was proposed here: https://lkml.org/lkml/2014/4/16/627 include/linux/regulator/consumer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index e530681..1a4a8c1 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -258,14 +258,14 @@ regulator_get_exclusive(struct device *dev, const char *id) static inline struct regulator *__must_check regulator_get_optional(struct device *dev, const char *id) { - return NULL; + return ERR_PTR(-ENODEV); } static inline struct regulator *__must_check devm_regulator_get_optional(struct device *dev, const char *id) { - return NULL; + return ERR_PTR(-ENODEV); } static inline void regulator_put(struct regulator *regulator)