Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2511083ybb; Sat, 30 Mar 2019 06:53:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmv3G/2VbyL3qwa6tP7awzHciLzAClDru0oKbvisdHO1bi8r4Uv2oauFE4U2XQBUfdfCps X-Received: by 2002:a17:902:2e01:: with SMTP id q1mr55419831plb.253.1553953993284; Sat, 30 Mar 2019 06:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553953993; cv=none; d=google.com; s=arc-20160816; b=EZiLd/FrZXbB/h2F8m6xF3zOYyYkhXDUMTixfwIdK1yllOy34k3nK9oY89w9Fe/6Jd u3oymiKPpRVR0s21AZ3X2f604hILF8j6wfZEBDj1N2E/wlcAA6Gpl/wR7Ey1050C84gq 1EhJ1YXkD+sLcW9XnNS/vwZZHymsPoyW2rFTh3oWBH9V6oRwkGo9RdtS6IcLCLHvKv2N /WLNiz3wNRXfySPoRROexXJTzPGF5Q6fadm1yx55mqpyEMKOMA/xR5nHIe8FsLTgaIBk BEoIpEA71ZMHR5OuDAwo3IPVuTddpP6mgO5LLi1xQa/C7xPAIM6DdMT/GyRDRKtg+t/H I5FQ== 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=KdKpB5oVvjep5IgeREqzKHs3PKmp9i1MJvAD1AFabWc=; b=lLnTbDA6MDcGbgqSkYwpyRpIuUtalv8vzb26TM2HSWmwawJNcHOJqBXqycATfepALc fkan9UsJdkZHshPx7xgDTsGMMQXhgBAwIgaoWIGcKW1U1XnEhrbMa2ZAwA1uM16Bk2vQ OmOmnZIkRP9IGH+jwKB0IU350PXQY1t0GCUirj6LhBOCLgkkrOYKE3b99I1vSy+90PVK EIImwZaTMUZp8WdeRKsAsselmFmNEWYW7cUqpA4IFH5MyrRvpAWVlLCnLicnbb7gQqyA 0lK+/W6ut8/BOIh0fbd9+4x73lwgnFTWA5pZm6ptA24YAGM3Y4BM6uhCxgCKsoSiGLM6 0/2w== 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 d2si4375550pgq.129.2019.03.30.06.52.57; Sat, 30 Mar 2019 06:53:13 -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 S1730863AbfC3NwT (ORCPT + 99 others); Sat, 30 Mar 2019 09:52:19 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:52500 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730823AbfC3NwT (ORCPT ); Sat, 30 Mar 2019 09:52:19 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D9C36D101AD6E7DE13A7; Sat, 30 Mar 2019 21:52:07 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.408.0; Sat, 30 Mar 2019 21:51:57 +0800 From: nixiaoming To: , , , , , CC: , Subject: [PATCH v3 1/2] clk:Fix divide-by-zero in divider_ro_round_rate_parent Date: Sat, 30 Mar 2019 21:54:50 +0800 Message-ID: <1553954090-65470-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 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. In order to avoid the divide-by-zero error, add check for return value of _get_div() in the divider_ro_round_rate_parent() Signed-off-by: nixiaoming Reviewed-by: Mukesh Ojha --- drivers/clk/clk-divider.c | 3 +++ 1 file changed, 3 insertions(+) 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; div = _get_div(table, val, flags, width); + /* avoid divide-by-zero */ + if (!div) + return -EINVAL; /* Even a read-only clock can propagate a rate change */ if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { -- 1.8.5.6