Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1939336imm; Thu, 24 May 2018 03:16:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrM5uDEwcclCgqBvlA5giUHuEP4ZS/8VvzjcgbcfH5z8YdJ4iSJ0gN5HISJ4GSEnnihcwmd X-Received: by 2002:a63:bf45:: with SMTP id i5-v6mr5394402pgo.41.1527156987154; Thu, 24 May 2018 03:16:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527156987; cv=none; d=google.com; s=arc-20160816; b=jwGjpC4bdoJBKQDb+7FcuSgx/EUMgrgrTxzV6/chG8J8mVhAq4521wLDtJkprXf/hh AOJAuX7Koc7+3fxsNIRve72Rh6Ra9JjS4LWdQM1mw9Wr/srf6KaCoabHDJKVjZO/OMT/ BszcSkwiUpcaDFVinUVuCxzfQK/7Tbh4qNryPjpua3qWMno3dqmIlpdah4AP3y36lz3n DjUR4B1OsG28mZIOnRZ3EOjRcXabtgtNvPaOU+b5Mx8bT0iM1HtreuHLcoAkvsZw2A7R YWfIaI6IGIosn/RNUVqf/Ov5OXODp9T/86i5c09rgle+l69X5yYmgyXIpRJq1DPr02xg dFxQ== 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=ZJXV6cFI66zld1YvpxoTwgMS5FvcTWcU5znmCj8kWRI=; b=WiEmN/gG2N2jJuf4cDmxZzdjp3X3AP2J8iD4wY2uZWCJuBtVd1Lw0Sw9ukolwn3cYT EA5QsHA+KNP8n32BDiLwODU/3w+jIa+HT5Rz3AwlMLlaIiPsuxTFhXFhZ6XXejjOFFzI wo0lEDDvjA6oTW0Q4Mfbsba/qdpM93wFE/LLEQi1LtsJEB6cC4szx5q7+lUk5Fjk9lhm sGYtdFQ9c1icg8tkDTBTSjO+v5j8qUvbalLm7+KXyxEq6yq5pcjL8j795oCCgwqle4CE 1qC/PLf6R2I/2x0HLMD9aTFGWVsPpWIT8jRpsCJLNTUMdGXyCN9LjcGjnZSMNr9xE105 HFyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dJldi74D; 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 s5-v6si16468925pgo.12.2018.05.24.03.16.12; Thu, 24 May 2018 03:16:27 -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=dJldi74D; 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 S1031644AbeEXKP2 (ORCPT + 99 others); Thu, 24 May 2018 06:15:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:53884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031430AbeEXKEa (ORCPT ); Thu, 24 May 2018 06:04:30 -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 5C64A20896; Thu, 24 May 2018 10:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156269; bh=67ld6No8Jyxjf4YGKcMcHdkXzrNMb5e6+T4lrFyVcs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dJldi74DtWD+yr749Mnm0iiOafwx1OrTtAvjJcrxfJrzaZWvGbtjDlO3bhtj6jT/g QTLDNzqjOodSrP23aGNTnxEDXg2Gm6tE4thFWDBc81I2pmJEdfsem8FhPjGy6JYzbj Ikquj69Hce1RvqrJeun2q7zyxKPFE9uKDoodxKJQ= 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.16 125/161] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Date: Thu, 24 May 2018 11:39:10 +0200 Message-Id: <20180524093033.285232799@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@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.16-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 @@ -58,6 +58,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; @@ -84,6 +90,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);