From patchwork Tue Jul 19 09:03:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 72276 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp562809qga; Tue, 19 Jul 2016 02:02:43 -0700 (PDT) X-Received: by 10.66.160.199 with SMTP id xm7mr63244171pab.78.1468918963761; Tue, 19 Jul 2016 02:02:43 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oq1si31755826pac.235.2016.07.19.02.02.43; Tue, 19 Jul 2016 02:02:43 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com; 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 S1753102AbcGSJCl (ORCPT + 29 others); Tue, 19 Jul 2016 05:02:41 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:53145 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752174AbcGSJCi (ORCPT ); Tue, 19 Jul 2016 05:02:38 -0400 Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id u6J92Cqg022087; Tue, 19 Jul 2016 18:02:12 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com u6J92Cqg022087 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1468918933; bh=1T9M41sRcu3Ue6GSM6VBYvM8hmDQFLMegjq0gQ6PoOU=; h=From:To:Cc:Subject:Date:From; b=FTyTLRcnVck0JWaK+FKw1fy0JzvZn7fYXb0/bVl32BULLgZUc5afTxc63t85RVP/c 2BAnzzhdmz0F7bT/rhQktmO+UJhZ2b1vdehIWlbYAduO9yUiiJ34PLJwOd5lcRXUwt ORRMcS6hDJjQwqQNznxgLRZF1Wt94/7eEDgWMClgBi4jtd+1d3hS+OonKgpKayubkk Su33ZplTvJLdu2KGAdFhxfuLpGyxiII3N2DcIPYBz3FBdtMwmDmWeCGe2bf/AS8or1 DxfE4bCCJ36GrYsPbOTTp+ujd3mDM+QarW9Xim/mF1jc4vgt3yRSws+ZuHzZNiCjFg IT1QBha9PBW9Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-clk@vger.kernel.org Cc: Masahiro Yamada , Stephen Boyd , Michael Turquette , linux-kernel@vger.kernel.org Subject: [PATCH] clk: prevent __of_clk_get_hw_from_provider() from returning NULL Date: Tue, 19 Jul 2016 18:03:58 +0900 Message-Id: <1468919039-23004-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The .get(_hw) callback of an OF clock provider can return a NULL pointer in some cases. For example, of_clk_src_onecell_get() returns NULL for index 1 of a sparse array of clocks like follows: clk_num == 3 idx 0: UART clk idx 1: NULL (no clk is allocated) idx 2: I2C clk In such cases, clk_get() successfully returns NULL. A problem is that most drivers only check IS_ERR(), like follows: clk = devm_clk_get(dev, NULL); if (IS_ERR(clk)) return PTR_ERR(clk); It carries on moving forward and will probably be hit by a different error check with a different error message. Let's make __of_clk_get_hw_from_provider() return ERR_PTR(-ENOENT) if the .get(_hw) returns NULL. Signed-off-by: Masahiro Yamada --- drivers/clk/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 1.9.1 diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 953643f..484acc2 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3117,7 +3117,7 @@ __of_clk_get_hw_from_provider(struct of_clk_provider *provider, hw = ERR_CAST(clk); } - return hw; + return hw ?: ERR_PTR(-ENOENT); } struct clk *__of_clk_get_from_provider(struct of_phandle_args *clkspec,