Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp416829pxj; Thu, 20 May 2021 12:19:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSFMx/DxxsBT5bKpk/BGHb58mYQEtY2asSotiVBKTQj4F7to9J5MtvHzRWZ+MaBVxe+C3Y X-Received: by 2002:a05:6402:10c9:: with SMTP id p9mr6691163edu.268.1621538355837; Thu, 20 May 2021 12:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621538355; cv=none; d=google.com; s=arc-20160816; b=eZLY47heuuNo4nHFd722GpstwQ+/OfIiEPEhYjwXlJyNv48lXXI+nYvncAZDjD17ww H/tNuSJAa2TPzCms5lCdqGfGVADF5i7mTM26XZ66jMzh1gFCNniRaNFldMAqM8fc9UEh eKCseuf37CeZcb17108FxQSDXJif4aV+MzSby3jw8M1VhcXd7qF6opkFsjJlNxwtAPcb c4ho5ceb6c2noFz+sW2b28YPY+hgvuyqdqnoOGFCROoacXbeBGNdBqWJP8CRudDgyNLB 9AO2jQIwdA7Kgmlk6WyPSKRsXHS+fovHnfLbVfL3MA9KCzW2riQEyRFggk8DYFocHj3H 0QOg== 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=xx+84PnqSHofI9XwnGz8MuNRXQEyT9pf6jRQzrNBluA=; b=mXS8XQqiUiNwpys25Drl5Sn65IReiNZiySUCGCIMjExABDUYRkaLf7VvuIMOEXsrpE b+gPt67ue047HbscbdTmKZ5qSOCfyOJLajURYKF6PYDsY1Yx3p+I3u0y6Q1UnGlkuJKh 0zB61N1XsTfTCpddI9HsgtG3CUq/4yD36VXh0bKc/+F1SkpjZ5qJMTMQFyKe5ayq+H1V rL4okqtvNvAFRrSRVCLkxAWoFgVb62mgM/wiYF9w3sPw8aR5UaQG1uY2Oqq3GEOQExKO B1ZPULanEKTqRRW0sIXqGgSwuAMWLTev2WjCKw4m6PwRpPLGRwGULTSj2TqSGpNlL0yo bVHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Yjk5MC7V; 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 w15si3445192ejb.550.2021.05.20.12.18.52; Thu, 20 May 2021 12:19:15 -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=Yjk5MC7V; 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 S238076AbhETKqd (ORCPT + 99 others); Thu, 20 May 2021 06:46:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:33416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237222AbhETKac (ORCPT ); Thu, 20 May 2021 06:30:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D39ED61C3C; Thu, 20 May 2021 09:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504312; bh=thZBLT5OleGrMB3A34zQLhYUq+OfO+QaM23VjAiwnac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yjk5MC7VtEQc9qrJ+KJRtrt4NypvmVqjE9yDthSfC+7FtMeNJu1/m30pRuGJi9L7M OQw1BqyX+kFRib7h7KUAnbKyzO3H2Cgy+eALg1jNV4ralRBxpTp93eOBTM2n/kahRa gU+SZCep8xTtB3e30ZbJQvqxunIuNnZLz4bBq3Es= 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 4.14 188/323] clk: uniphier: Fix potential infinite loop Date: Thu, 20 May 2021 11:21:20 +0200 Message-Id: <20210520092126.562388440@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 2c243a894f3b..3a52ab968ac2 100644 --- a/drivers/clk/uniphier/clk-uniphier-mux.c +++ b/drivers/clk/uniphier/clk-uniphier-mux.c @@ -40,10 +40,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