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: 9236499 X-Patchwork-Delegate: sboyd@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D3CEB602F0 for ; Tue, 19 Jul 2016 09:02:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C263020009 for ; Tue, 19 Jul 2016 09:02:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6CB72624C; Tue, 19 Jul 2016 09:02:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA09920009 for ; Tue, 19 Jul 2016 09:02:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752897AbcGSJCk (ORCPT ); Tue, 19 Jul 2016 05:02:40 -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-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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,