Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1944236ybv; Fri, 14 Feb 2020 08:38:36 -0800 (PST) X-Google-Smtp-Source: APXvYqy0jQL8c5GriSKzubPTq+s5y4z/7ZHkEMUXxD26fptRina4h/BGmgEjC9DeLiGgBYtB1qwo X-Received: by 2002:a05:6830:10a:: with SMTP id i10mr2867658otp.365.1581698316770; Fri, 14 Feb 2020 08:38:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581698316; cv=none; d=google.com; s=arc-20160816; b=kHvs6+fOQbMjZ/m7pU3chHAZ9jjkRob0l/CKWkmhlcSuHMi6lSj8WhU692/nhzU8Sk dkiNW1zBGnOfMtceb2U0e4rVvCJ4F5rAySsLan+rRzHMUwCAfBKpknzWF9iz1ClKMC4t fCxxytFVQXjsNpQV0/hlKMW9LgnC5ZpdLV2Cwe/2Q+Cw/X3SU5K63GRwW45y4PiB9vN4 sKEfbYANZZDuK0K+NwD3/VtNO1P4IoV5fs2aNsEc9rSip+QxIbHwiH9CobKRobNeDnkt 2SIJ3WLH7UOiozaIrBkyoTeo9g43zraBQ89RXRAm/2eUPgXkAu3yTJ8hJY+3p3KZfQWN 90VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qMkQh1WgVyisgZUiUTJeTDO9bx9xZZuF9eXDAWgf9N4=; b=0naiY0CsTwi7DJD54IcZDPkuj4F4AjckmNOG93xI2RDHLFHWEeumhz5DFSKbBRLWkc q1EfjjlOsd36RJY36gELATOxONyW5lnuG7n1o+L5WZ21u6VK0AY0KS0cBvtA/QVW/h96 80h5uXv42uBkHg2UfMWRvZlTsZjNC25vIlEwOojH10u+r8yrfWGw+gtpG9uK11n+Md3J fivMh/w/vQamW2TKpNKKkyPQn9WT3IZCN14bn2+ChqR8n/J9ayVerEkd8XYs1Yf2pP/S cFrji4OWiUHWtV3gGUte+vKr0h6Zz63f4MrFssziYiuWiwv6s9nDGDvUdlvmcHXJbII1 X5FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Cjbg+4uX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h64si2790477oif.215.2020.02.14.08.38.25; Fri, 14 Feb 2020 08:38:36 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Cjbg+4uX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405717AbgBNQXs (ORCPT + 99 others); Fri, 14 Feb 2020 11:23:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:57038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405061AbgBNQWD (ORCPT ); Fri, 14 Feb 2020 11:22:03 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4911B246D8; Fri, 14 Feb 2020 16:22:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697322; bh=Omc6XSnNs5KMFz1tBz8lSNoR8tkXrcQQyKZa4berMYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cjbg+4uXM88/mvL71ebO3gFnAJWGvFvVzU4WQgOI5A010jBEAO+Se16H+B18TiYRi NLIJGP+9kQYRX1XjLXzxHCjB9838gMytbrcH5epRxXyhJFQUYS2o483PuWi5mECPHM ZSJIEkJmq7TGOxuOfis5Eo7F8SeS9sAhRjNqwJNw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Douglas Anderson , Matthias Kaehlcke , Stephen Boyd , Sasha Levin , linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 031/141] clk: qcom: rcg2: Don't crash if our parent can't be found; return an error Date: Fri, 14 Feb 2020 11:19:31 -0500 Message-Id: <20200214162122.19794-31-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Douglas Anderson [ Upstream commit 908b050114d8fefdddc57ec9fbc213c3690e7f5f ] When I got my clock parenting slightly wrong I ended up with a crash that looked like this: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 ... pc : clk_hw_get_rate+0x14/0x44 ... Call trace: clk_hw_get_rate+0x14/0x44 _freq_tbl_determine_rate+0x94/0xfc clk_rcg2_determine_rate+0x2c/0x38 clk_core_determine_round_nolock+0x4c/0x88 clk_core_round_rate_nolock+0x6c/0xa8 clk_core_round_rate_nolock+0x9c/0xa8 clk_core_set_rate_nolock+0x70/0x180 clk_set_rate+0x3c/0x6c of_clk_set_defaults+0x254/0x360 platform_drv_probe+0x28/0xb0 really_probe+0x120/0x2dc driver_probe_device+0x64/0xfc device_driver_attach+0x4c/0x6c __driver_attach+0xac/0xc0 bus_for_each_dev+0x84/0xcc driver_attach+0x2c/0x38 bus_add_driver+0xfc/0x1d0 driver_register+0x64/0xf8 __platform_driver_register+0x4c/0x58 msm_drm_register+0x5c/0x60 ... It turned out that clk_hw_get_parent_by_index() was returning NULL and we weren't checking. Let's check it so that we don't crash. Fixes: ac269395cdd8 ("clk: qcom: Convert to clk_hw based provider APIs") Signed-off-by: Douglas Anderson Reviewed-by: Matthias Kaehlcke Link: https://lkml.kernel.org/r/20200203103049.v4.1.I7487325fe8e701a68a07d3be8a6a4b571eca9cfa@changeid Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/qcom/clk-rcg2.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 0ae1b0a66eb55..d8601b138dc1e 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -194,6 +194,9 @@ static int _freq_tbl_determine_rate(struct clk_hw *hw, clk_flags = clk_hw_get_flags(hw); p = clk_hw_get_parent_by_index(hw, index); + if (!p) + return -EINVAL; + if (clk_flags & CLK_SET_RATE_PARENT) { if (f->pre_div) { if (!rate) -- 2.20.1