Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp546611pxj; Thu, 20 May 2021 15:54:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFof7iiaLQ3NqGF1OqsMfaKxNUsQrYwsxxj6FGzYuduO/kAThCmO6b0VyHbP2991uxCYmw X-Received: by 2002:aa7:df11:: with SMTP id c17mr7393860edy.317.1621551251676; Thu, 20 May 2021 15:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621551251; cv=none; d=google.com; s=arc-20160816; b=TpXKlSf3/RUt01pooWtuQfIPJdBHcTEyJqYXhnNw0CG+ruaArNFodXLa4CL20f8ool xia7+3TvAkWT1OwiSdqmmfO8xui8Zo6zrocca8jReMMmh055hscNIXLFc7Srt2jOIlqX oi4cgQSf/dt5th3Kuhcl3upB9JLmkGc3PRr9YcZFHgy19liWi0doyOTR1iW8xQqQ3wmk o3heK6PLmTP0/agGpZyjTxo2L1NUkZ2PxOBOsd6GM52+3Ym/vtGuKG6cRPxI4EOMpzDT nb59f+cbt2gUE1WGe0xvpTJh+6ZKkuFhblqrL/NqX6X8vW/hxOZHD1BRairZ6fDMNfjv 2WKQ== 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=K48THj3D1kB4JhqLUYC6kDvYlfjz8AfCLqxcz7J5oc9AD13j7ON/TCkyagcfFdMlxw fBfZzZitmFeTvIAa1w95GRpmg9YQpCx44NmPEpchdOTUqzpK8en1jjzYp40NKBW6kPm3 MUxGHmZZ94utnZ57uie9Km43wyU3XWH/IuQe0kD1+QEFq/R3nTPX39+y2d6FaKazkkiN 63nyxXTuiJc4UGRhsKwi9fzTKCHHqQ0AuUxNu29WfsoJDw/uZGPmMgbGNIxO1cenTuv/ e3pj1zEswn7KLk5Ypf5xSLqIPxbj7auLunVrQ5n92oTyr1LXt7KhOtckbPUYJQf/AsSJ N+Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KPqHgdiQ; 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 k9si4485237eje.640.2021.05.20.15.53.48; Thu, 20 May 2021 15:54: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=KPqHgdiQ; 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 S237414AbhETLRk (ORCPT + 99 others); Thu, 20 May 2021 07:17:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:52462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238803AbhETK4L (ORCPT ); Thu, 20 May 2021 06:56:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 246F961CE8; Thu, 20 May 2021 10:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504899; bh=thZBLT5OleGrMB3A34zQLhYUq+OfO+QaM23VjAiwnac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPqHgdiQeGVhU48eK8RzP5GnQnFRwZiPFxnOqHFG0WpwiVVSlv8lMjjAd9UvBXRRl ca06p6WjW1BosXRaKBloKWZxSjDY+tJMj4jDLyGBg80GnBGy1uLMhROfgNGI4FsbfE 4xv9asvzbNiAPaRRxgLl+KlViEG/7+0PHh/dwH50= 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.9 131/240] clk: uniphier: Fix potential infinite loop Date: Thu, 20 May 2021 11:22:03 +0200 Message-Id: <20210520092113.062799427@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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