Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2111069ybb; Fri, 29 Mar 2019 19:31:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzf8DWxb6AMSRkrZM+DEO/DUtMym5onvvNO7qbWSkfGzcd+4c0mSd0oD6DOFVpDtG/ObHt X-Received: by 2002:aa7:8615:: with SMTP id p21mr26758804pfn.98.1553913083888; Fri, 29 Mar 2019 19:31:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553913083; cv=none; d=google.com; s=arc-20160816; b=SGotXpWHxs2+7zlxah7oimOPX3RqI18C5yy6VPTVeYCUmkF4AJr1hjGzPwsHiEuIVX tDbSUzjRV/zLjp6I7JPh+SVhyBnqeDZzbPTv0fBkJOZB77HyhZaz0f9AHeoAAAnUKdEP 6AYACVLdRawATm+hpkHIzOdquN7kBO8qkjwYLPvagq8JWLPWukz5sbsJjGsPTr7HOqEE FuSeA3M5Eo7tALf1ygdWDJ8Vwh+njou4IcBG5UMCnygrJL1se/J64Du69qeVM6quP24L FL9Eh0EvDM6at5tkRxMe0ScOsY60dh7wTC7RWs70OuzqrHGIhVf9QARj6FDAcarvo6kq Bp/w== 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=Sy83/sQlh12UIpck+fUhMwOgQuMYOEPq1rR6toMskcbkUvNjL9DvsqNx7agFvWUR1t O4jTk/yr19j9NPYb5HIDYQ/7700d8WNfqwi8c+1mFHktDutVqSalTCWHiTNb1n0ZsFmE 4cyMy7qZepfQunVOsKqM7GpUGmZjjg+qAVtf/IL+CONqWqazzBHH15ETzDf+VtP64JD4 NK/xJA6N+GFox2VlRU78SQmAPVtAlwIz2dZ1eggYajKRCCYlw8YOVrMWOuC/nwA8tV3p zi8yYd7Hgn63EoAPdvqCZW6F3sZAZ8D+E73HflslskX1nL7qXHTlynsjbFi4XQru3QCi /OKw== 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 d126si3256149pgc.597.2019.03.29.19.31.08; Fri, 29 Mar 2019 19:31:23 -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 S1730408AbfC3Cad (ORCPT + 99 others); Fri, 29 Mar 2019 22:30:33 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:42948 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730104AbfC3Cad (ORCPT ); Fri, 29 Mar 2019 22:30:33 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C26B3DAA1DB5CBC2F028; Sat, 30 Mar 2019 10:30:30 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.408.0; Sat, 30 Mar 2019 10:30:22 +0800 From: nixiaoming To: , , , , , , CC: , Subject: [PATCH v2 2/2] clk:mmp: clk-mix.c fix divide-by-zero Date: Sat, 30 Mar 2019 10:33:17 +0800 Message-ID: <1553913197-51325-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