Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp400891ybl; Wed, 11 Dec 2019 01:28:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzIIW/L5kj3UixUy7qtSK6MELRp62zas4XSPI8P4ZMdJ3DQYlUwMu4d/95JRTcVAqCd1uzJ X-Received: by 2002:aca:4c15:: with SMTP id z21mr2077564oia.12.1576056481540; Wed, 11 Dec 2019 01:28:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576056481; cv=none; d=google.com; s=arc-20160816; b=foaO0P62FfL9NkHfPzXJd5bsTra6HfF+U1t9BMwTsvkaqMS7RPDrV3PfROJ5eUIZIl F2t0IJU5ZQfUl6Cok3liYYwQUJHFu1VWU3fLBS+YghR4l54uJdv+snSB61aCoZSEYTbs uS1S18/JIYZOrcokza1hGA5tNS8vdqpkqx2JHv8QIzcsxucDZUS4TLTwqHJ5f0Ue7ray 80MUe8lWswv45mnDM6qTH4GZH+bOdBoBOwWGoSPboQ/TV63XRd+I+cQk8oJFO655jBdc /zm4vgy7C5vRNQdqkGL2GQt/dILdyy3WC9VoS7fAXZskLFGfl9Inyen87PyqUotfphvr aIaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=5Wpt/U2oA+dw3MGMpJZP5MDT/B20p31mBdDn2Ezitl4=; b=vlW+LuenuEviMFskRqcYcppn/RXv4wrTx7VVCkNLnRNbYwVUXaZPHXvH8YAU64MgII KPSR4V0R2fs53W4FgYFFEtAgPQB05vmJ3BHzxsLSYXbW79jsiA3ddaVn9E5/B7zExJmt PB957NK0/3/bZtYPUGEKAf4Wyi8sIWNFnugIr9VRbvc6iaCtYX+O3c0xDtoPJ9LZv+vZ sKovK6HUYUoJJPjxP7WxwzKHB24nk3BSbSkyfvlS6zS5z6tAlTSG6OeuwDm1AyY9FTZc i3mB+ggjbaHfAmVGgjQiHuQ1+xuSMeD+M/whXT7kesPykexGaNG3sMn6WZRUKrs5ezmy RHmA== ARC-Authentication-Results: i=1; mx.google.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e192si856160oib.82.2019.12.11.01.27.49; Wed, 11 Dec 2019 01:28:01 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728487AbfLKJ0G (ORCPT + 99 others); Wed, 11 Dec 2019 04:26:06 -0500 Received: from inva020.nxp.com ([92.121.34.13]:49514 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726988AbfLKJ0F (ORCPT ); Wed, 11 Dec 2019 04:26:05 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id B092D1A05EB; Wed, 11 Dec 2019 10:26:02 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A29721A0C28; Wed, 11 Dec 2019 10:26:02 +0100 (CET) Received: from fsr-ub1664-175.ea.freescale.net (fsr-ub1664-175.ea.freescale.net [10.171.82.40]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 29E1920568; Wed, 11 Dec 2019 10:26:02 +0100 (CET) From: Abel Vesa To: Shawn Guo , Stephen Boyd , Sascha Hauer Cc: Dong Aisheng , NXP Linux Team , Peng Fan , Linux Kernel Mailing List , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Leonard Crestez , Jacky Bai , Abel Vesa Subject: [RESEND v2 01/11] clk: imx: Add correct failure handling for clk based helpers Date: Wed, 11 Dec 2019 11:25:40 +0200 Message-Id: <1576056350-20715-2-git-send-email-abel.vesa@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1576056350-20715-1-git-send-email-abel.vesa@nxp.com> References: <1576056350-20715-1-git-send-email-abel.vesa@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the clk_hw based API returns an error, trying to return the clk from hw will end up in a NULL pointer dereference. So adding the to_clk checker and using it inside every clk based macro helper we handle that case correctly. This to_clk is also temporary and will go away along with the clk based macro helpers once there is no user that need them anymore. Signed-off-by: Abel Vesa --- drivers/clk/imx/clk.h | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index 81122c9..00ec481 100644 --- a/drivers/clk/imx/clk.h +++ b/drivers/clk/imx/clk.h @@ -55,48 +55,48 @@ extern struct imx_pll14xx_clk imx_1443x_pll; extern struct imx_pll14xx_clk imx_1443x_dram_pll; #define imx_clk_cpu(name, parent_name, div, mux, pll, step) \ - imx_clk_hw_cpu(name, parent_name, div, mux, pll, step)->clk + to_clk(imx_clk_hw_cpu(name, parent_name, div, mux, pll, step)) #define clk_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \ cgr_val, clk_gate_flags, lock, share_count) \ - clk_hw_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \ - cgr_val, clk_gate_flags, lock, share_count)->clk + to_clk(clk_hw_register_gate2(dev, name, parent_name, flags, reg, bit_idx, \ + cgr_val, clk_gate_flags, lock, share_count)) #define imx_clk_pllv3(type, name, parent_name, base, div_mask) \ - imx_clk_hw_pllv3(type, name, parent_name, base, div_mask)->clk + to_clk(imx_clk_hw_pllv3(type, name, parent_name, base, div_mask)) #define imx_clk_pfd(name, parent_name, reg, idx) \ - imx_clk_hw_pfd(name, parent_name, reg, idx)->clk + to_clk(imx_clk_hw_pfd(name, parent_name, reg, idx)) #define imx_clk_gate_exclusive(name, parent, reg, shift, exclusive_mask) \ - imx_clk_hw_gate_exclusive(name, parent, reg, shift, exclusive_mask)->clk + to_clk(imx_clk_hw_gate_exclusive(name, parent, reg, shift, exclusive_mask)) #define imx_clk_fixed_factor(name, parent, mult, div) \ - imx_clk_hw_fixed_factor(name, parent, mult, div)->clk + to_clk(imx_clk_hw_fixed_factor(name, parent, mult, div)) #define imx_clk_divider2(name, parent, reg, shift, width) \ - imx_clk_hw_divider2(name, parent, reg, shift, width)->clk + to_clk(imx_clk_hw_divider2(name, parent, reg, shift, width)) #define imx_clk_gate_dis(name, parent, reg, shift) \ - imx_clk_hw_gate_dis(name, parent, reg, shift)->clk + to_clk(imx_clk_hw_gate_dis(name, parent, reg, shift)) #define imx_clk_gate2(name, parent, reg, shift) \ - imx_clk_hw_gate2(name, parent, reg, shift)->clk + to_clk(imx_clk_hw_gate2(name, parent, reg, shift)) #define imx_clk_gate2_flags(name, parent, reg, shift, flags) \ - imx_clk_hw_gate2_flags(name, parent, reg, shift, flags)->clk + to_clk(imx_clk_hw_gate2_flags(name, parent, reg, shift, flags)) #define imx_clk_gate2_shared2(name, parent, reg, shift, share_count) \ - imx_clk_hw_gate2_shared2(name, parent, reg, shift, share_count)->clk + to_clk(imx_clk_hw_gate2_shared2(name, parent, reg, shift, share_count)) #define imx_clk_gate3(name, parent, reg, shift) \ - imx_clk_hw_gate3(name, parent, reg, shift)->clk + to_clk(imx_clk_hw_gate3(name, parent, reg, shift)) #define imx_clk_gate4(name, parent, reg, shift) \ - imx_clk_hw_gate4(name, parent, reg, shift)->clk + to_clk(imx_clk_hw_gate4(name, parent, reg, shift)) #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \ - imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)->clk + to_clk(imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)) struct clk *imx_clk_pll14xx(const char *name, const char *parent_name, void __iomem *base, const struct imx_pll14xx_clk *pll_clk); @@ -199,6 +199,13 @@ struct clk_hw *imx_clk_hw_fixup_mux(const char *name, void __iomem *reg, u8 shift, u8 width, const char * const *parents, int num_parents, void (*fixup)(u32 *val)); +static inline struct clk *to_clk(struct clk_hw *hw) +{ + if (IS_ERR_OR_NULL(hw)) + return ERR_CAST(hw); + return hw->clk; +} + static inline struct clk *imx_clk_fixed(const char *name, int rate) { return clk_register_fixed_rate(NULL, name, NULL, 0, rate); -- 2.7.4