Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2442924imm; Mon, 28 May 2018 08:10:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrKzXz6BPb6rX6GJyo+iZtJo2ebTOczPSL6qyS81M0FpJsuOWKeSUX5DljU7QPXpXSF3nVQ X-Received: by 2002:a17:902:8f97:: with SMTP id z23-v6mr14192485plo.329.1527520238047; Mon, 28 May 2018 08:10:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527520238; cv=none; d=google.com; s=arc-20160816; b=RhwZmZqCLhDkldP2q81yiQg3+WZPFLv9SS4bYjUoIEm5yia5dctBVS/RvI/qzTZ5GV DLyiaQTvL+OkiPYXiVBDVO9cqNR5GZjB3pTNuJ6NQvDLgyV1oPekpzeqLhjIwKGivnDh mMROQLTaCwaYUsNwRvLNBG2CVZA4uQ8inOPS5dzP6lyNCX2BaEbajZlCCTMp+YM007U4 gkojlVUaKXRvh2de59qrpachw4/TJ+hEgxMDk8foIaIGcXSFQyoN9oWPEGSkVehT4jkx j3InxpsqUhfgwJl5nQL8z7dQR0IY91YWue4c5e7wJIKGmtH0mbXwzKYdJwlMcfoNobYf H1tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kbUSMRTfsNn2lEDbQ0F5FFFDHIoPP7uBltr9ryFubDQ=; b=jzzs+4t8sMlQekTLGshGmhe880UJiTYw0GYFA4BEHzbO4Pb/9aSL/Sjgtsy2GqH9gG BmU+mqI6CtjfGiD+ApXloOsZRNJJCDIY7ePvQV4Q6QUaAL8HMZxx3Hk+T1KXQmyCmY4c JitP0SGxloDaWygFlilUtSkSHEkTIUyxcJ9V8yp291PbsQgPoBImqRk8CRnGar01Jgrw XWIZa4T/m/4kq784MO0imPIvv2wHz9sOidd4UQAOPxtla4LtJ7A8i3B5ffwBSN9J55n9 aw8tAXWAJpRE7TfSsLzMMxuT+q5UuOnla77lra6WlbgfNjIdUDHhA2GTgSWOphxN5WCK cWwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gOYPG8Vq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x32-v6si29737848pld.435.2018.05.28.08.10.22; Mon, 28 May 2018 08:10:38 -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=@kernel.org header.s=default header.b=gOYPG8Vq; 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 S939693AbeE1PIj (ORCPT + 99 others); Mon, 28 May 2018 11:08:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43866 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1033792AbeE1KYc (ORCPT ); Mon, 28 May 2018 06:24:32 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E108620844; Mon, 28 May 2018 10:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527503072; bh=cxn96YwYDue+eqJwHwo8TGKCHx39g1b4cPbGiaTSCT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gOYPG8Vqhx1f7XZjmqaN8sLspK7v4Ti0FBhG+lyDjNVjtZ1420SJYRKED4H5p74nG +YCw73tq4CmyABOvzrURIHlJvt2tE3TrqXIR4CAO8RnI+hHm830myZgP1Vtxe1i1Hj 9lbiau7fb+5rI4JPvoVuPX4Hr3pxL/tHKAcZw0yU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shawn Lin , Heiko Stuebner , Sasha Levin Subject: [PATCH 4.4 233/268] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Date: Mon, 28 May 2018 12:03:27 +0200 Message-Id: <20180528100229.729430836@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shawn Lin [ Upstream commit 4bf59902b50012b1dddeeaa23b217d9c4956cdda ] The MMC sample and drv clock for rockchip platforms are derived from the bus clock output to the MMC/SDIO card. So it should never happens that the clk rate is zero given it should inherits the clock rate from its parent. If something goes wrong and makes the clock rate to be zero, the calculation would be wrong but may still make the mmc tuning process work luckily. However it makes people harder to debug when the following data transfer is unstable. Signed-off-by: Shawn Lin Signed-off-by: Heiko Stuebner Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/clk/rockchip/clk-mmc-phase.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) --- a/drivers/clk/rockchip/clk-mmc-phase.c +++ b/drivers/clk/rockchip/clk-mmc-phase.c @@ -60,6 +60,12 @@ static int rockchip_mmc_get_phase(struct u16 degrees; u32 delay_num = 0; + /* See the comment for rockchip_mmc_set_phase below */ + if (!rate) { + pr_err("%s: invalid clk rate\n", __func__); + return -EINVAL; + } + raw_value = readl(mmc_clock->reg) >> (mmc_clock->shift); degrees = (raw_value & ROCKCHIP_MMC_DEGREE_MASK) * 90; @@ -86,6 +92,23 @@ static int rockchip_mmc_set_phase(struct u32 raw_value; u32 delay; + /* + * The below calculation is based on the output clock from + * MMC host to the card, which expects the phase clock inherits + * the clock rate from its parent, namely the output clock + * provider of MMC host. However, things may go wrong if + * (1) It is orphan. + * (2) It is assigned to the wrong parent. + * + * This check help debug the case (1), which seems to be the + * most likely problem we often face and which makes it difficult + * for people to debug unstable mmc tuning results. + */ + if (!rate) { + pr_err("%s: invalid clk rate\n", __func__); + return -EINVAL; + } + nineties = degrees / 90; remainder = (degrees % 90);