Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4678784pxj; Wed, 12 May 2021 10:42:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQbptZzEHKrdbhi2lGvE0Xks2L7GMcY4vKqrXuIoLEtPgzKP1z9mK1mJdJgK1i7/HJFoKB X-Received: by 2002:a17:906:eca9:: with SMTP id qh9mr38457853ejb.258.1620841330620; Wed, 12 May 2021 10:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620841330; cv=none; d=google.com; s=arc-20160816; b=eiQbgl3uRu5FI8WaHBCaKYqItqcE8yiN/P338YfCVZbIo8XTWDsvFs6grZJgijpbaM xp1TrXI4a4Rcnpbx3mPZ937BFtEJnidY8paw00OU4BKnNqbibeFBE1I2/cDAJH7hl/Jz 38Nghy4mcTRcpuASO0hFNGQ33Dv2IbbO3cImaGmMcJoo7oHM2XiQOi7qIsrYXe00cME7 0syq5fIkpbRkixZL2FpFpgA5n++PfqB6mW7x4KTDSVqkgtImPExJGzCeY3prLb0Mjg8k eOF+wPZRFl1zJdA2WE0cFnUZgaFpxVg88fyhTjhxTUSTYpO5poS/EceZSylGgpaXh0V1 LJaw== 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=PVQCvwQESji28pTThXjBOegufebHHT4uC4TMfDZFVh8McOF2QWxsn0BlkPFGWJMLYP iZ2bmW/7WdUpO52vWl7pi8Fdpgi4wpACqBgiXxwUoPzYr3oAtwvdjszmzJirtfjwJudy pHAwJ7kSmVVoz4FogFtLBXac74ODCTyMiXfm97mNA+F3WclFrmjLlvnCVorjFw1fF0JD I++qQeGKXBrJ0xdjeDliHcCVdkTuHR5L2muNh8DuyqKfEUkSM6hSv+P0knRlTd0JWzMY MFm+XS7ereBsko831Hq15BZRTtFivm6fJLVIUL+4zixbx3/6/c3+H+fSjm6BSJXduxVg txDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lN3QGugn; 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 r22si356207edq.277.2021.05.12.10.41.46; Wed, 12 May 2021 10:42:10 -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=lN3QGugn; 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 S1346713AbhELRfn (ORCPT + 99 others); Wed, 12 May 2021 13:35:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:41990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235121AbhELQJQ (ORCPT ); Wed, 12 May 2021 12:09:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3555C61C6D; Wed, 12 May 2021 15:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833985; bh=D05Ms35Fa3zBhWVOkhp6js7LRYTCD4eitDpF6CmpE+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lN3QGugnG+6LKkLwE+m/GsNEOaaprMmysvNoGd8u93jUkMtGLy4iRl45v3t8ULzZt KIibRldGOiqvfLs4UFjtD567qAH9ic/OekqXh3TfX5QbfIs2IUfoaPcCQFqnGZ7DB7 BOKDvlHO9P9PSnFJHMjYztf1CeIYgCY14UoO4BRc= 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.11 364/601] clk: uniphier: Fix potential infinite loop Date: Wed, 12 May 2021 16:47:21 +0200 Message-Id: <20210512144839.790056033@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144827.811958675@linuxfoundation.org> References: <20210512144827.811958675@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