Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3897011ybl; Mon, 9 Dec 2019 01:53:09 -0800 (PST) X-Google-Smtp-Source: APXvYqyE1OtBKD/G0IGWiq1oO/oJknlppbHDgEl7hcG37N14NqflvQUXvXCBQFbj15og+veH9m3q X-Received: by 2002:a54:4086:: with SMTP id i6mr13724763oii.65.1575885189238; Mon, 09 Dec 2019 01:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575885189; cv=none; d=google.com; s=arc-20160816; b=Q4en8r/l33ixHlLxfepjN40ShhGFpOXMV4to1NSTj/pePlInNKzYubIB85cMv9eMCX MscCXJar00jBOZ4MU0F67G0p4ULhdWpiMuUY2pM8VK0tf0LGAw1wUtrF7gFInCwG7SFd pE4CjNI8PKtWUuZ0zVbWNZRikoNRfJgngW4K3b1ZvKgWsBh3ma+YjHtFQw+PpmKgFvI9 4GvJYr83QfYr+rL+LNDCc4dirXNtIJMRsx7VU6RGn+OoPCYZRSdD1zPwWOGK+cEPOdJS ySR40dQlRtWTSDpYqxbGt1tlQxOGpbmd7Ed+Yd3uRlMUaVTxaliSioMijBaFqdQn++it Tsyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:dkim-signature; bh=/lV4JOds+hQfSWH7coNmWVW3vJirPTXEaWuWEYduTYk=; b=F62zJ39gUjCsGCyNZb/EgS2+vx3wOgZT8CiGk8StVuftNSFLFQyI04Hjo7A/vMeD3C lYYtPmglOgocdKwK1dpALifVBVmBl2OUoIFl71rcaJ/HRQmlzzE3yC/U9HGSPwFDHkoG yJCOpdRYxrKGFB/I+7br9MQjQLGI/cJERyVPfd1TWMM2vsq0Zyxb3NR2HQfijqj20At3 mRrfPMWAeeHaxsSZ5VJEvXWiZnrl95VlO9r2kYftdyY+56vSTz52pZ67S2orVIo/kRG2 eYistBYAsuT1K051Y5d3BXUHxKzKMD4n8ZxNkr0D59VkILEtJfmSLeALEAXbJ03kqtIU PMdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=1QP8E5rE; 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 k7si11575799oia.44.2019.12.09.01.52.58; Mon, 09 Dec 2019 01:53:09 -0800 (PST) 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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=1QP8E5rE; 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 S1727378AbfLIJvR (ORCPT + 99 others); Mon, 9 Dec 2019 04:51:17 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52210 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725994AbfLIJvQ (ORCPT ); Mon, 9 Dec 2019 04:51:16 -0500 Received: by mail-wm1-f66.google.com with SMTP id g206so14729931wme.1 for ; Mon, 09 Dec 2019 01:51:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=/lV4JOds+hQfSWH7coNmWVW3vJirPTXEaWuWEYduTYk=; b=1QP8E5rEnnpU1XZQRU97MeWENs2Clw1QWJ71vLW8hAfEkhPVRwKXiPNjy/x0GSLHYy iEBd0l9DIz9rS1Oyx0EPugmBekdTVFsgULtW+CLZXn6/HjLgmtUzplUdlOsDM5LAUDj0 ZcxA33nqqE0xugQ3p8BMXNCeyP1AYFooYXFa5XI0QPTEhBKECdxMuXuvxVKG7YuiLuvu HcyR3Y2Qfj6WJ/wDGu3KhySAy/so+P9mJ6kfLB8OW3wCl4ZRytOKZZXu2Ml1Q45RY5jB fTuVR/SzH8ZWZBk7CdkFP5J3sdSMCEMFKPUnlAg2AJyR7r3onPgGF9+GTHCkZZdD9moJ 1SZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=/lV4JOds+hQfSWH7coNmWVW3vJirPTXEaWuWEYduTYk=; b=bCcYrZQkWHIqsYGCu8+QwWGhesd7ldBhao2ky9ZN5iMgVGXnRe7EXeYGIkXRz0MYUh /IBFnPaK/28BIRzykn8dRo8wQ1jUJ7A/g5WyzgjmqgmXuMHi68HTs+8SZpgko8ILCZfZ MNO9ih8TYRcj3k0LI23ErRtaIG2Xa/Nx+kYat2qauAqwGrKM4thn51majwiTbHzQnNhh A2fJ/qAYaA7QPI9nek6RsfUBWTtezuatoIhKlU5jMaLPjLZpu4HjjbhU1Y+/empf/nwq PeuqH6PKIMz2vXUCdPtLR5rrZHhRnpEB1GfpAFaodYXa168R/GvtZQxhTdm6NX/Awy8x kZ6A== X-Gm-Message-State: APjAAAV3QfHJCO8a+iHn7EPws7XECqdp2OBRopj+vq1j4MTLGB8hWQAZ 4SEiV9kSGpt6vutlMLWvNzzhmA== X-Received: by 2002:a1c:238c:: with SMTP id j134mr24393284wmj.151.1575885074948; Mon, 09 Dec 2019 01:51:14 -0800 (PST) Received: from localhost (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id y6sm25826838wrl.17.2019.12.09.01.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2019 01:51:14 -0800 (PST) References: <20191208212206.16808-1-repk@triplefau.lt> User-agent: mu4e 1.3.3; emacs 26.2 From: Jerome Brunet To: Remi Pommarel , Neil Armstrong Cc: Michael Turquette , Stephen Boyd , Kevin Hilman , linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: meson: pll: Fix by 0 division in __pll_params_to_rate() In-reply-to: <20191208212206.16808-1-repk@triplefau.lt> Date: Mon, 09 Dec 2019 10:51:13 +0100 Message-ID: <1jo8whesj2.fsf@starbuckisacylon.baylibre.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun 08 Dec 2019 at 22:22, Remi Pommarel wrote: > Some meson pll registers can be initialized with 0 as N value, introducing > the following division by 0 when computing rate : > > UBSAN: Undefined behaviour in drivers/clk/meson/clk-pll.c:75:9 > division by zero > CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.4.0-rc3-608075-g86c9af8630e1-dirty #400 > Call trace: > dump_backtrace+0x0/0x1c0 > show_stack+0x14/0x20 > dump_stack+0xc4/0x100 > ubsan_epilogue+0x14/0x68 > __ubsan_handle_divrem_overflow+0x98/0xb8 > __pll_params_to_rate+0xdc/0x140 > meson_clk_pll_recalc_rate+0x278/0x3a0 > __clk_register+0x7c8/0xbb0 > devm_clk_hw_register+0x54/0xc0 > meson_eeclkc_probe+0xf4/0x1a0 > platform_drv_probe+0x54/0xd8 > really_probe+0x16c/0x438 > driver_probe_device+0xb0/0xf0 > device_driver_attach+0x94/0xa0 > __driver_attach+0x70/0x108 > bus_for_each_dev+0xd8/0x128 > driver_attach+0x30/0x40 > bus_add_driver+0x1b0/0x2d8 > driver_register+0xbc/0x1d0 > __platform_driver_register+0x78/0x88 > axg_driver_init+0x18/0x20 > do_one_initcall+0xc8/0x24c > kernel_init_freeable+0x2b0/0x344 > kernel_init+0x10/0x128 > ret_from_fork+0x10/0x18 > > This checks if N is null before doing the division. Thanks for reporting this > > Fixes: 8289aafa4f36 ("clk: meson: improve pll driver results with > frac") In mainline, the commit above went in with sha1 3c4fe763d64d. Also, this commit is not really responsible for the problem. Having HW initialized with N = 0 would have failed since the beginning, I believe. In this case the correct fixes would be: Fixes: 7a29a869434e ("clk: meson: Add support for Meson clock controller") > Signed-off-by: Remi Pommarel > --- > drivers/clk/meson/clk-pll.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/clk/meson/clk-pll.c b/drivers/clk/meson/clk-pll.c > index ddb1e5634739..6649659f216a 100644 > --- a/drivers/clk/meson/clk-pll.c > +++ b/drivers/clk/meson/clk-pll.c > @@ -66,6 +66,10 @@ static unsigned long __pll_params_to_rate(unsigned long parent_rate, > (1 << pll->frac.width)); > } > > + /* Avoid by zero division */ > + if (n == 0) > + return 0; This can only really happen after init, in recalc() rate. I would much prefer if you could check the n value right after it is read (meson_parm_read()) in .recalc_rate() and add a comment explaining that some HW may have this parameter set 0 on init. > + > return DIV_ROUND_UP_ULL(rate, n); > }