Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4742944pxj; Wed, 12 May 2021 12:11:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6xMnhR6oCRHaDEBou3PuyJc5qsajKxhUIbi4f1vfyqdJfTVSVBG+gk9TTx1UsOyi2kH0E X-Received: by 2002:a05:6402:1153:: with SMTP id g19mr919790edw.179.1620846671222; Wed, 12 May 2021 12:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620846671; cv=none; d=google.com; s=arc-20160816; b=n67oeXYXRFFVo2eB6LXfO/ncaYZay73r3ZZXh3jtP+QG9CzxzF2N3T4qnF3oeqsB5z T6WH/hLhMt0WaEN3t0LGZK8LixznPtnSvONCF6LfgIAZqTPSjjh0XtjzCMVdj7hTrRh1 +GHCYPy+b+u1K9TTuHA2qP7mUAbYmXeQyjPYCQ24JBq0UG5OpesXXCgYOOPtNJlTrHZ1 ZA1Bava9D1IXCQKWFstfVoRueNwR+ydTdKWIhaSpYHr5Fo7kTDRHzhRbvAr0kXyL0uxo xheC0dq5oAnHnVMwGZv7F1yjf0Nbk5jSNvkVqsKix636Ytk9XG0GHxy+uUOHFY2UDVtp kwvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ls3j+P6bxfuAgnz62gR+ithrX+Fci2thcidtAPt+qzs=; b=tnF+23ADBd6yQVUGTJdsaHI0xi7NrjwJGf84ESZ1vqir+dn0gbunRt0yQwjRPyKNV8 +LhjijNfAzeJoEJcjajYp0R0lyQX2s6CZs9R68dD1BDZFrSqnuswIIgzwqymEA7V4WAr bqfM/u74Rp2YmJ3R4E7uwVth3EvwFEK+4TK3uUzjzDQXrQ+m8I+0M4H+Bcyr0kAL4Ryt QqC5RtOE+qXD0wbL5f2lKLG8O3xEasZWKd3LcaOuYWemXA+H4/oG8dWswD5QjtY9exJ0 REiHFrKkjcjpY4q4qIVCRfDarAwNVPgW9X0o5xi4X8do6Q+tF5IRD4wFBgkUNxxlhoq4 Z1XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ENZcywPf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si480873edd.136.2021.05.12.12.10.46; Wed, 12 May 2021 12:11:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ENZcywPf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359081AbhELSvc (ORCPT + 99 others); Wed, 12 May 2021 14:51:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:35700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243839AbhELQmJ (ORCPT ); Wed, 12 May 2021 12:42:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 52AF361C45; Wed, 12 May 2021 16:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620835649; bh=D05Ms35Fa3zBhWVOkhp6js7LRYTCD4eitDpF6CmpE+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ENZcywPfEH9mxe2wKrPvMYDjtc8pBA8E2bx4alOuxITCWJbKu6jMhyhHe/8Gs2IiJ +BeD/NQP+RE7CaUXv+uiIBf6EqWFW6pgYc6fDJjBBW1bjHSpdGlEM1ofU2FuvTXfzu 8jdy0s/z4zkBWAIr9QkbrrcWKnynRWsqw+kRwtsQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Masahiro Yamada , Stephen Boyd , Sasha Levin Subject: [PATCH 5.12 412/677] clk: uniphier: Fix potential infinite loop Date: Wed, 12 May 2021 16:47:38 +0200 Message-Id: <20210512144851.034892475@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144837.204217980@linuxfoundation.org> References: <20210512144837.204217980@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit f6b1340dc751a6caa2a0567b667d0f4f4172cd58 ] The for-loop iterates with a u8 loop counter i and compares this with the loop upper limit of num_parents that is an int type. There is a potential infinite loop if num_parents is larger than the u8 loop counter. Fix this by making the loop counter the same type as num_parents. Also make num_parents an unsigned int to match the return type of the call to clk_hw_get_num_parents. Addresses-Coverity: ("Infinite loop") Fixes: 734d82f4a678 ("clk: uniphier: add core support code for UniPhier clock driver") Signed-off-by: Colin Ian King Reviewed-by: Masahiro Yamada Link: https://lore.kernel.org/r/20210409090104.629722-1-colin.king@canonical.com Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/uniphier/clk-uniphier-mux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c index 462c84321b2d..1998e9d4cfc0 100644 --- a/drivers/clk/uniphier/clk-uniphier-mux.c +++ b/drivers/clk/uniphier/clk-uniphier-mux.c @@ -31,10 +31,10 @@ static int uniphier_clk_mux_set_parent(struct clk_hw *hw, u8 index) static u8 uniphier_clk_mux_get_parent(struct clk_hw *hw) { struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw); - int num_parents = clk_hw_get_num_parents(hw); + unsigned int num_parents = clk_hw_get_num_parents(hw); int ret; unsigned int val; - u8 i; + unsigned int i; ret = regmap_read(mux->regmap, mux->reg, &val); if (ret) -- 2.30.2