Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1976634imm; Thu, 24 May 2018 03:54:59 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqelcO5AGcKc9lG6mV2990ceGkamSi/+xIiJMaVh0Iy68pEeGWxPxsaO3NdpuJc78a6EgWC X-Received: by 2002:a63:b406:: with SMTP id s6-v6mr5598239pgf.334.1527159299338; Thu, 24 May 2018 03:54:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527159299; cv=none; d=google.com; s=arc-20160816; b=CMjgJ+FzJdE68zCkJRnQw8VW9p7Biz/mxBDStjwDfr0NElanSNzZPfDjQG0akOJSgv 1je6IDOHXx0SUFk4Y709B+o6Mgq0qGeAfD9dZrAfgwm+egrxBoR7iFmwxt+APm0xLFnA soMELI2N8Sp0Kvq9KYHZFmypi0tGtlHmZLq19gHrj8Z/Pz2xrYflvRsb0VrR7P/v4RzG cV5MTJBjUhEOyhSr/jGPSDSJUiw3GqHBvmR7Oyi8sBfh1+5kD/qiIf/t5nB+47JmobBB yUPVLH/2ki5uNGPgYngssMi7+FNvbUYbzVbd7hx2NvmkO3ixT9DyJM/yKt64caKlYGcy iARw== 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=cszFybg0gMg5ft7T9nFMqOOlzOdeLvnYUndm2WVhSbA=; b=xe9uIMLyL3LdZPNEdJYBrhUNHcwxPWwQvhWgjagay95Dhyr2X7nt1ix6vCaFpISeQf 6DvBzH4TgKRT08+LQnghEG7hboSaERGjFUMK32ggfKu+ibWXnAcQnuB6aQeq1H8Xy15H U/BgpRX7Ueu4aYD2epymDu1FrZnQxSgKy0ApVE8PKGYJ6QRTs20WDCS4N29gscQ7HnWq EQNjcunNzsWZRK6GqmHaJA5Dw+Z8qRMcNnfQ32JpQhXfe5+ndG2e7qMlKg6SCVw+vK5l f/p/ShY/gRh8CH2rudxfELMoTZzOgS27AK7A7BoJiZ0hjZ2SpBjwXl5HYq+01Nyig9Od 1l3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0pyV51pk; 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 u10-v6si16350378pgr.642.2018.05.24.03.54.44; Thu, 24 May 2018 03:54:59 -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=0pyV51pk; 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 S1032639AbeEXKx7 (ORCPT + 99 others); Thu, 24 May 2018 06:53:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:36890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030383AbeEXJ5C (ORCPT ); Thu, 24 May 2018 05:57:02 -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 C499E2089C; Thu, 24 May 2018 09:57:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155822; bh=XSA4QxDlyIXGCFXFx0E4CZxqcmeIOLfDiYrLBi6aLlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0pyV51pkSm4ZIf3eOKuwyjMfvc1227JYWobB11MNc4f1mDSuiaNdPYjKFxFnX04Rz epKQrNkE3JLAuAN9hVlJZPdbuIIEgvPJ3z9gDRO5I0AL9v1TjcH/EnX5NCtiL4SXWg zU6KkHizUqlKdqZw3a2IK92r06lK6ZPVg4LA/dTk= 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.14 130/165] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Date: Thu, 24 May 2018 11:38:56 +0200 Message-Id: <20180524093627.260856482@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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.14-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);