Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4565082pxj; Wed, 12 May 2021 08:17:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS8+4vYM8+GxdhJ6p2TEtocH6V7k0N7NI2RuycQNom6DHlNAuxfwbqRxV83S2fXN4vZ+Pt X-Received: by 2002:a05:6402:c7:: with SMTP id i7mr45120208edu.194.1620832673375; Wed, 12 May 2021 08:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620832673; cv=none; d=google.com; s=arc-20160816; b=ubjJ+xHGfsNVAfJa7YdLrVR1opkoam+ZfF+js5MbdHsRF7CeJcR2WTdyEwLY9jwMpO MNkSFa1ews7+hJd6x1HmdcCBSJpti8+fCeoLipGIOogwoCvHr44MnHlbid+nRtnhHTtc dKhwZuAZOCkKR+HkYx1motHocPvzrCbieDr8kvwQwoCqfRaajnW4QiPacJCRAkH1y9w/ IqbAIwE5nALVRvsShZeZTTLs4pVAFRS85yz35H8WgoUamWGZ+A619Sy+D0TagraAjkW/ k2NAqj38dFeFtElNwhcDzTd5Fe+n45VDJxfVwfmGAfkBhrfGEvah9OS2MpCq3tywJcyL MqMA== 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=EuFgUFPEiBBrLbF4MTfP1zcbxmhLmhUDBqMVZx/Tn6I=; b=VobZRMVFEcrYaNzHYgZSEG4pFJ7urbXPUWX2nQcjy6Ma94xdwUleiyfJve627eZHhz vNHxtqrL4E7UKux5Z4dGmg7qiRAzFexH66e4NSNPbBUxon7N8lHPr9rFzyYKgBuXjBMC TAAj9zMMiwGaGC3P90V87rEDmvI7N/gFNc8tLcdby3oeyeWlzPyTlb95sdvBPn0Azosf jW7E/bkp0QPxwBJDhK6BeLD55RRPpQG2k5+4g/r8WyZVR7aLuZCNLE7PdWeqhl68XG4u xiKBTfbzof0NHzv950kzS0VnrMVX6lA5o5YEF24KPyI3YRXAj+w16eKyoL8k40VP3N0g B0nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c6mlDODK; 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 hp41si232201ejc.369.2021.05.12.08.17.28; Wed, 12 May 2021 08:17:53 -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=c6mlDODK; 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 S232161AbhELPNF (ORCPT + 99 others); Wed, 12 May 2021 11:13:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:58514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233349AbhELPFO (ORCPT ); Wed, 12 May 2021 11:05:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE15F61948; Wed, 12 May 2021 15:00:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620831601; bh=YM0wb7YVnvLlcE9M7n/qrSk14U0ZmhG82Mmwp9xUaTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c6mlDODKjL/rrMbpN5qgitX+SOHhAzIsshHI8S8gnIQPLpNBCprUIO+i+ZKtLUeuz rH/eKR91jgIutVBovubwuJx+xduMaxrlw4TPVsfKwhFrjCR/4HUbDR0bhqQaaGSuOV 9VWyzxy47n3TN3OE7a04yZrOc4z5yYnT24+lOLcw= 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.4 158/244] clk: uniphier: Fix potential infinite loop Date: Wed, 12 May 2021 16:48:49 +0200 Message-Id: <20210512144748.057918561@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144743.039977287@linuxfoundation.org> References: <20210512144743.039977287@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 c0f4631601e2..babca032352a 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