From patchwork Thu Dec 21 11:24:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Liu X-Patchwork-Id: 10127499 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E75856019C for ; Thu, 21 Dec 2017 11:22:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B18B629BB1 for ; Thu, 21 Dec 2017 11:22:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A633529BBD; Thu, 21 Dec 2017 11:22:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3AB6E29BCF for ; Thu, 21 Dec 2017 11:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=6HzCC+FCZSCH2irCI6VzE2PB0UeQ5bZ/B5Y1lLxBObA=; b=ggj 6UQbR5qn2p9niRQhm+zmmTtWkrqe2/f93BoX3lfNdDLOtOGB2OAN3msKrU7G1Vmvs13OzE8bUtvdQ RkuZ9TtLme/C7qmGdaaSbi1sefOWD+5S8vx4VcZmWn+gGU4CvAdNU91Me1DI0gVrXzSHbIPfUae9c jbCihe/8veGVQeXTWY1TR2glornYhghhihYwZmulbgjxvAJE1JnnVcc/lHDEJ0LVPVwxNdaHpFAOF hEiosn8Gt+wl8kyWFBTRWSou9U2gTWTVbb0TjKNcZ2h/dL15jdxdmKNUu6S05LJAQ1ftfq+htSPJY 8nVPNvkIxECHJX3iV44qc2K1OXvvt0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eRyw4-0002of-Ji; Thu, 21 Dec 2017 11:22:48 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eRyw0-0002nR-2R for linux-arm-kernel@lists.infradead.org; Thu, 21 Dec 2017 11:22:46 +0000 Received: by mail-pf0-x242.google.com with SMTP id n6so13835921pfa.4 for ; Thu, 21 Dec 2017 03:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lUyFkV5b71wTVdDNKH2+9NUSBYAm4VN9IYWtj+dC5Ak=; b=jp8KFgtJNyIo7dzXLkIrMUiTNB6iPsIC2UMaxp7LxoRH8FRlp2ob1itNCFGx5/nb55 VzgtGbYixozCXegD4FFPqY5A0FLuVDtZPHwTm/uJ05Rp5IOLN2HfcLo3rYqKTnEhsvRW nsXdiR1uleUsZpz9UvCMfGzfuekhlLdHq3I2bN/FP97N4czqDTkccVv62mWIZxsVBtOm MRkLsd/+qUtwfh2z+pwv/m8ZNujWxnbdNK/TM5bdqkOB4i4twqLLo71cwGoeRYjNz+8s 3i8GCrrecaPs9F6pTy3qlbKjnVMGZ/owaFqjbBSBQEyzHtG8dDhXTV19DA4vgxGuu8Ie qr0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lUyFkV5b71wTVdDNKH2+9NUSBYAm4VN9IYWtj+dC5Ak=; b=tWqdfei/Jr4gNUNcEJKfXoSo31k9VfaA4vkFKEQ2kXNdCk65bDkBMP9GM3BUTw+cw3 H5hmVi/5LxfskHvwxrS8NLoAEoEWOQZfz/iqZ/Xd3Kg28uKHgFHOWFaa1imJDBhOC719 PJxaxiybiD/naTlrfQbz7PyXxaBBNX5R/3oayVD2A5QmpYESbpRbs5S/cKerzIUbkVDg Ky9f7xb/+xfehKdHD8DZ0RZ/lpYno9nUs69ZOhk+knaZmYCWTpL3HNCGLzbkywjmUR6q 4d93WFVceCkSC1aEm2gvJswxXJdrFouqHQV6q8DaBd+uOm/Ry1wvfPKuqDPy06+8DV4m qjFQ== X-Gm-Message-State: AKGB3mJX9WlVZsBzA5FjEA+QsQdVa0VeHh1C+IM4jqA94fHlxTzUmdhv /qB1mRUvtopR8WvlAxhorUM= X-Google-Smtp-Source: ACJfBotVlACPgPVy5LVpueerfQyO9fGocsloKPwknlwfTDSe/YNtJm1kszUInWlh+hh8KyaSnDerig== X-Received: by 10.99.109.68 with SMTP id i65mr9224654pgc.19.1513855352838; Thu, 21 Dec 2017 03:22:32 -0800 (PST) Received: from 60-242-179-244.static.tpgi.com.au (60-242-179-244.static.tpgi.com.au. [60.242.179.244]) by smtp.gmail.com with ESMTPSA id z63sm42528897pfd.71.2017.12.21.03.22.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Dec 2017 03:22:32 -0800 (PST) From: Jonathan Liu To: Maxime Ripard , David Airlie , Chen-Yu Tsai Subject: [PATCH] drm/sun4i: hdmi: Fix sun4i_tmds_determine_rate Date: Thu, 21 Dec 2017 22:24:11 +1100 Message-Id: <20171221112411.21550-1-net147@gmail.com> X-Mailer: git-send-email 2.15.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171221_032244_193161_9C5FE7CF X-CRM114-Status: GOOD ( 11.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-sunxi@googlegroups.com, Jonathan Liu , linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP There are several issues in sun4i_tmds_determine_rate: - doesn't check if the best match was already set before comparing it with the enumerated parameters which could result in integer divide by zero - doesn't consider rate halving when determining closest match if it can't match the requested rate exactly - sets best_div to i which corresponds to rate halving when it should be set to j which corresponds to the divider Fix these issues. Fixes: 9c5681011a0c ("drm/sun4i: Add HDMI support") Signed-off-by: Jonathan Liu --- drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c index dc332ea56f6c..3ecffa52c814 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c @@ -102,10 +102,13 @@ static int sun4i_tmds_determine_rate(struct clk_hw *hw, goto out; } - if (abs(rate - rounded / i) < - abs(rate - best_parent / best_div)) { + if (!best_parent || + abs(rate - rounded / i / j) < + abs(rate - best_parent / best_half / + best_div)) { best_parent = rounded; - best_div = i; + best_half = i; + best_div = j; } } }