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: 10128167 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 2341160390 for ; Thu, 21 Dec 2017 18:05:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F29129C37 for ; Thu, 21 Dec 2017 18:05:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01BCE29C42; Thu, 21 Dec 2017 18:05:47 +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.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9A50429C37 for ; Thu, 21 Dec 2017 18:05:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C02E46E40D; Thu, 21 Dec 2017 18:05:44 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 708EC89F19 for ; Thu, 21 Dec 2017 11:22:33 +0000 (UTC) Received: by mail-pf0-x241.google.com with SMTP id c204so13821909pfc.13 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=RVW1PR6NcL7bzm4p6YTk9baDhKOxMc8LkIuZVjr2xWizKicc+v2GeLfK2uFAiVWTR6 g9K7WC3nr5eGr1oFJvgjhfzPcE6dL8y56ovUyEWtuUNqUM3a8+CDwwsFolfi2kMxAEJd /Jpb9oe9NL+YHjegMGzmF0zQ6eKZCkpEJ1Sue17wS415nWI9rPiyoOpuXgNUUYye9uSo AkLyVmFzxODopYXauAK8nyuikE60FLX9GZ0xwjSBIEzxmBcdMpvwCfByJ996gk9UTB1E uXwOk346feShL2H8FAn+5wlxDTbIxdVXPGRfvpjO88IaD2vT5pG9ucEadm38KWRWhGaD XI+g== X-Gm-Message-State: AKGB3mKQFxdkRiEAYNrC1EhNumVTngIA346uvMpTyYXR3BGmRaos2DdW b2/QhCWP41C2QBu8kA5ZSFk= 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-Mailman-Approved-At: Thu, 21 Dec 2017 18:05:43 +0000 Cc: linux-sunxi@googlegroups.com, Jonathan Liu , linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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; } } }