Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2511680ybb; Sat, 30 Mar 2019 06:54:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjsbGDE9Uz6GDmk2tSzrCr30sN9Z56CfTNTAH7GbKFknFfKF62925KBx1kaN04cnfK+Lce X-Received: by 2002:a17:902:b7cb:: with SMTP id v11mr24637046plz.334.1553954054489; Sat, 30 Mar 2019 06:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553954054; cv=none; d=google.com; s=arc-20160816; b=cWZAM1WwUhWn+BlxQ4I75InBE1FIuhsTfcjTXCCg+EIeGIaIdCBLxfpR+dDPNbVpct l8T/yUQo3kXtBjbGOTM1JXrtGRCQdXqPpJCa4Mbl9qE0rHlPtSRfchuuD3yWMFXVMU2b KQNod6y16Mz34kCjoo+htipIutgUNk/HUBaBUs2TKkj4WYG+yW6mTMXhNS2gc8RdOLXO y3E2KsS299bV8ovXeJeiZ0A3r847CuAiAqD+ux1dREAZDcTG0eNDIOpnItQ20aizL67Z 3oyyTJLsJCVA7r1GOJE9KGpHpEDBq/nFThD9Lh/yY/650x5RxpuBjHNCkyxgnmmm9y4Q vxDQ== 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:subject:cc :to:from; bh=5HKREkBhmKTG9JpTytNbRxX/f1Hin3C5VSCRcbJzXME=; b=V2ZOnSyHDzgxSVItPafH8lU1FDbHYNPSastEwn72wa+vZcM7YGIjhbYMnbYJcJZrlJ 8rvzBS7K0/dnVDVRm+i2mGL5Syo0agupLd98fC/tsEyYyVNVs1F8aXyf8XshRxxznijv 7UV30y9ENUEwa89XGGpCfJFGCgDLGKwqIWf0J3qNUysquzINembVUDezUmh/ubNF3n2l 9IuaAh+W8HJSz5qXWp1o2sIMqoS2Dv02Go1MKI8WMIBw4HkjXZA0rEHOIzuL8NDhc1oh v21ONcCQVb7UHCXBbI1lbSGI13GeMp0V6QuIQlHi8Q63j8x37O7ZvtqMIiVyLNVtSHng sNfQ== ARC-Authentication-Results: i=1; mx.google.com; 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 z11si4362486pfa.153.2019.03.30.06.53.59; Sat, 30 Mar 2019 06:54:14 -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; 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 S1730882AbfC3NxD (ORCPT + 99 others); Sat, 30 Mar 2019 09:53:03 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:53122 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730823AbfC3NxC (ORCPT ); Sat, 30 Mar 2019 09:53:02 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 50AF2C0C967E7D7AD65A; Sat, 30 Mar 2019 21:53:00 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.408.0; Sat, 30 Mar 2019 21:52:49 +0800 From: nixiaoming To: , , , , , , CC: , Subject: [PATCH v3 2/2] clk:mmp: clk-mix.c fix divide-by-zero Date: Sat, 30 Mar 2019 21:55:42 +0800 Message-ID: <1553954142-65515-1-git-send-email-nixiaoming@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The _get_div() function has a branch with a return value of 0 Add a check on the return value of _get_div() to avoid divide-by-zero Signed-off-by: nixiaoming Reviewed-by: Mukesh Ojha --- drivers/clk/mmp/clk-mix.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/clk/mmp/clk-mix.c b/drivers/clk/mmp/clk-mix.c index 90814b2..6ed5ad7 100644 --- a/drivers/clk/mmp/clk-mix.c +++ b/drivers/clk/mmp/clk-mix.c @@ -245,6 +245,9 @@ static int mmp_clk_mix_determine_rate(struct clk_hw *hw, div_val_max = _get_maxdiv(mix); for (j = 0; j < div_val_max; j++) { div = _get_div(mix, j); + /* avoid divide-by-zero */ + if (!div) + continue; mix_rate = parent_rate / div; gap = abs(mix_rate - req->rate); if (!parent_best || gap < gap_best) { @@ -341,6 +344,9 @@ static unsigned long mmp_clk_mix_recalc_rate(struct clk_hw *hw, shift = mix->reg_info.shift_div; div = _get_div(mix, MMP_CLK_BITS_GET_VAL(mux_div, width, shift)); + /* avoid divide-by-zero */ + if (!div) + return -EINVAL; return parent_rate / div; } -- 1.8.5.6