Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4126480yba; Tue, 23 Apr 2019 15:52:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwMUpw6l3ZuNbKCAkz3pMaqmBZJCKzdR4+07aWIV+CnT3Bnssbhp1voUZivWlGEiKp6euD X-Received: by 2002:a62:7603:: with SMTP id r3mr29792435pfc.32.1556059978303; Tue, 23 Apr 2019 15:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556059978; cv=none; d=google.com; s=arc-20160816; b=FASh3UeYyELwFoJKzoK6psBxWI9kdFxq4KeVivj0m1ggI8Apue0WHgNPDLtdEsv4V2 vJJ1P8h1VsCDFszYxc59azrKEQ2L0WWPULDYpYALRDblg9B2MsdBHuYOPos/iCGH4LCR L5z/xh6sGsH5s2CTBc8K5lOBm7w7OAZMy7ssakapGKE/QpMWp010KXODd6rI3NwQ+YH8 VaxLUU5fuLad+xuWTxqsEMUxt08KQW9phDOtbtBZCE8cEcihyqtQeNV4UBtNKSWETQ/Z RLYwcvXwT2HNgYu4TkBIF20NPURb6TkQQkyYVbwqFhDMa2p/A+z3VA3CMZkvX36tiO3s o0pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:user-agent:message-id:to:subject :from:cc:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=rcMnnOUuhNzkMRb37EZius6K806drDzTSNYrMRj1Mpg=; b=W5dZGeBF4EY1t7O/Fh03vB8PQaGUhGmObvrO0oNI6CB95Oh/JR6z/Lyc74xi7Axdt8 hSGYaXez/KqAC3FlFcIFjmIoGuxZwKvjOlmJyvMdpKNy3aErsIkdeh+9sDYS2QYRSxqx SIPa0VjBypxBQ4uHpv/2RwoE1VpjgVhcCa5skE61XHS/ie0yfv+rJuzEyz33mAFFdh2h R0XR1A6s9FUuYIW+c/pxlJSjNXCfTFKc1G2IFW6YemL7B1/axpKcb25gwviOXDgGxIlt Hz3JVjr9ja7jjLlrpRE486MhrRX+8Hi3SvJAd/m+RNiIDJfIMFvWkdDdto37DoRhbcqj pIsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YbJ/44xw"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z186si15654826pgd.155.2019.04.23.15.52.42; Tue, 23 Apr 2019 15:52:58 -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="YbJ/44xw"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728647AbfDWWvp (ORCPT + 99 others); Tue, 23 Apr 2019 18:51:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47028 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbfDWWvo (ORCPT ); Tue, 23 Apr 2019 18:51:44 -0400 Received: from localhost (unknown [104.132.0.74]) (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 B73E1218D3; Tue, 23 Apr 2019 22:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556059903; bh=SLbCAZJQDRjk9vfOn393HVdMCmgStLY/ewawo1pjTEg=; h=In-Reply-To:References:Cc:From:Subject:To:Date:From; b=YbJ/44xwF2XkY70C8ezjis7D1gJTyERQsW1BJULYaY3DojG/gKkDZwEcDpIpPovXB 7Wn3dzuyjn11xp2pcoCLDPnYnUSVyqMxfNn0SEsnKom8V+4w8YXdE+ruwR9q4fYlmN N6Vg8eY3NdKvD+8ZoQnQeKflQGdFAQ0c3nQMD1SQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <1553954090-65470-1-git-send-email-nixiaoming@huawei.com> References: <1553954090-65470-1-git-send-email-nixiaoming@huawei.com> Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org From: Stephen Boyd Subject: Re: [PATCH v3 1/2] clk:Fix divide-by-zero in divider_ro_round_rate_parent To: jbrunet@baylibre.com, mojha@codeaurora.org, mturquette@baylibre.com, nixiaoming@huawei.com, sboyd@codeaurora.org, soren.brinkmann@xilinx.com Message-ID: <155605990288.15276.7089726827167650203@swboyd.mtv.corp.google.com> User-Agent: alot/0.8 Date: Tue, 23 Apr 2019 15:51:42 -0700 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting nixiaoming (2019-03-30 06:54:50) > In the function divider_recalc_rate() The judgment of the return value of > _get_div() indicates that the return value of _get_div() can be 0. When does _get_div() return 0? It can't be CLK_DIVIDER_MAX_AT_ZERO or CLK_DIVIDER_POWER_OF_TWO. I suppose it could be CLK_DIVIDER_ONE_BASED if CLK_DIVIDER_ALLOW_ZERO is set? Or just CLK_DIVIDER_ALLOW_ZERO is set? Or a table that has 0 in it for some odd reason. > In order to avoid the divide-by-zero error, add check for return value > of _get_div() in the divider_ro_round_rate_parent() >=20 > Signed-off-by: nixiaoming > Reviewed-by: Mukesh Ojha > --- > drivers/clk/clk-divider.c | 3 +++ > 1 file changed, 3 insertions(+) >=20 > diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c > index e5a1726..f4bf7a4 100644 > --- a/drivers/clk/clk-divider.c > +++ b/drivers/clk/clk-divider.c > @@ -347,6 +347,9 @@ long divider_ro_round_rate_parent(struct clk_hw *hw, = struct clk_hw *parent, > int div; > =20 > div =3D _get_div(table, val, flags, width); > + /* avoid divide-by-zero */ > + if (!div) > + return -EINVAL; Can you please give more details on what's happening here? Who's the caller? What are the arguments being passed in? Shouldn't we check for CLK_DIVIDER_ALLOW_ZERO and then return prate as it comes in instead of returning an error? > =20 > /* Even a read-only clock can propagate a rate change */ > if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) {