Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2017594imm; Thu, 24 May 2018 04:35:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrxuR/Mo9YwSj+iB4hprQ5sFBT6CKTQSZy8q+PAgLWlbgZ3Imgsb58ZogLegpCSSsGMfHk3 X-Received: by 2002:a62:93c8:: with SMTP id r69-v6mr6880484pfk.59.1527161728579; Thu, 24 May 2018 04:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527161728; cv=none; d=google.com; s=arc-20160816; b=uatVTjYG7BvWpm0vH/GYuqmy+dj861ak5gCL49soaojBEbaqIAiq/ltcD3og/rRCH8 2PsTOjEd6e/7xldZfAlww9uc/vZoERB6bHe7nRoYgjVzV26ntawhQYbgNaHCuhLhb+J1 ptWh4GZHk4Kl/1d6MuDgQyJ9vbt7BPUqQMNh+w9yRsmGW7pSj2B1EDqMWWlewNuKqvIX qJDE9JN1l9CqKyeo4A4L+O7ncAuU4IUXPN0/AV6icdNDSsuSpq+/tfCbgyMriYc99Fwk D2oFugPiyBE1ewQcjxc9fc77iR4CdECYkAqFqRNdL06/Qf013Gc5eF+Ru75GBYJ4H4Fi W2Lw== 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=e31f9iYSMbkHPzXT516yETriYyWOgiTtHyDy5jSGjEQ=; b=jhZIuZ6XfwzJGDUukLtLiBNcUlpA/RPUUw2p+Ut7LxgLyA/Lzp2e2ifDZ8t6flN9uz H3h9WWX5RHLHNWSLCDxrOk6T1JPdUOLQ5M5I21W1MNhPWEbGm6ESBRjQ6+Bt28eZze4J o+C1X17nZRBGl2xRFBnQCNloujjxws5tWKKJner1jydeUHAR6SPZpENtmxMQKZMHyf+e n0gYjD8uGZnXJEzIdsvoH/8uPRiM1uRwwFhllUauL6PBAvpLOLyctA9ZO0jS1fe/jHly J+i/XgJRg7vsWwSgljuJQf2TR4aLbllcOrhkJREi4nsMEgSF3JBhXvK78a+rBDFAcns2 lE5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dzJj5+yw; 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 m6-v6si16520170pgq.611.2018.05.24.04.35.13; Thu, 24 May 2018 04:35:28 -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=dzJj5+yw; 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 S967550AbeEXJuP (ORCPT + 99 others); Thu, 24 May 2018 05:50:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:40472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967462AbeEXJuF (ORCPT ); Thu, 24 May 2018 05:50:05 -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 76BE620894; Thu, 24 May 2018 09:50:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155405; bh=lRlj3lGvNiMRlza37ic0ESEwdayzqesfMuNV6Ae7pJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzJj5+ywDc7PjDGfntaqm9YbK6bNNh44Zuwcugqw3nuR+DZcoaXlvnYR9/bGpYuer MDa+x+UqPAL+a+qQR2tQ3RHroNtrfabPlb95fFUVuVys1JjcXnjbQs4Vw0gJl7245I +s1vFAAqKyJFfNr9yE6Mij1o5hNA9H2Xb7Ff0kkw= 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.9 74/96] clk: rockchip: Prevent calculating mmc phase if clock rate is zero Date: Thu, 24 May 2018 11:38:57 +0200 Message-Id: <20180524093609.638446128@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093605.602125311@linuxfoundation.org> References: <20180524093605.602125311@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.9-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);