Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2077017ybb; Fri, 29 Mar 2019 18:25:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzk4Y9vP4yuu3iLWYCnLLRxoqkPiT9qQQYJkJGw4embylpdqR28nGfvDvpYWMYnR0fu/9et X-Received: by 2002:a62:4553:: with SMTP id s80mr49681835pfa.141.1553909158828; Fri, 29 Mar 2019 18:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553909158; cv=none; d=google.com; s=arc-20160816; b=Y7yqfoXxPXrJgkLWewgFiJJ3/n544SMzx4kOsTlHWhAUdReLzWH36H1N4z9Ex8CQei XyrHzw8llRnpKwQLSic7JBx23XT0TXXTkoCg84vLTbafKPa9woGvqMptMp2jWOFNK5Lj xIcdwWOOep1gJgeEOgvVLBtm4awBo/lRCSW+XylEdAD12v6BE2RSCsN11foIJBohAO8/ XEkDYIISk3q1MbdBVM0yYqrUjwWMxt6dzry7daOjefayumfhrDXZcnp3nAUAeYS7NPd5 xgnQhORMI63riDoLQfEogVfnmHKZn14ZFVkGwsDycIn7eScfA4pFnkNej4ogAV60rGGo l6Vw== 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=a2omS/QhmIRGYa6vKGz/WbCzagImaHBiULk6VTEhYmQ=; b=tbxtJjiugj7wmtpSgejHGmtLyNYPFccqHwf56Pd0C1nFAjvnDLSravXkCEvJ0BYgNQ UaUrRKQvquxwwe3Lbg6GE8bgpKo8ObkUci7UKL09ArDPj7zGU877DNYfzXHAsSVUeetX fTzajFtHfOTkMpACzzDvFGDWhyheD3rVXP9El6B5pr6jfPcna8gW9QV59wZgRTpVXsiz EXu1qKShpppj8a6/pBSQrm1+vpJM8TwV2vYaFXF6LyW7Qzdwl/sbW5eZ/9vBQmfHeT+s ojwediBOrT4VnaohC5pGnmzDZ/HDmyI1sOzLRBei1lO76v9mPbDNwOu39mg3MF2wX2pP +JVw== 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 v24si3089186pgi.286.2019.03.29.18.25.43; Fri, 29 Mar 2019 18:25: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; 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 S1730438AbfC3BYb (ORCPT + 99 others); Fri, 29 Mar 2019 21:24:31 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5208 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729919AbfC3BYb (ORCPT ); Fri, 29 Mar 2019 21:24:31 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id AC76CD99DFBBFFEDA9F3; Sat, 30 Mar 2019 09:24:28 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.408.0; Sat, 30 Mar 2019 09:24:18 +0800 From: nixiaoming To: , , , , CC: , Subject: [PATCH v2] clk:mmp: clk-mix.c fix divide-by-zero Date: Sat, 30 Mar 2019 09:27:14 +0800 Message-ID: <1553909234-49311-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