Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4611963pxj; Wed, 12 May 2021 09:13:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6W2/hOVJRkpka7qcp1FBka0APA/2xECpASw9qz1aSOh/3tRYar3+985TeDt5KWYhv+HoJ X-Received: by 2002:a17:906:600b:: with SMTP id o11mr38433203ejj.345.1620836016099; Wed, 12 May 2021 09:13:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836016; cv=none; d=google.com; s=arc-20160816; b=to/pnW5mHc46TIMdRZK4dXVWBJcbAG1EZdZP8fFyPdwHfRq62sOXJkIguXljD7BEMj z5YGgpYDMFD8eYF8JJVJAnWmIYt/gfPpBW/egBpxEsTSjLpq0HGkNe4cJ3vhVDmkJEN5 F4J14SN2nPeNKKhGztynFrnEADdHen1UrTOKYr0GkW4ddUPMkmbFKM1ruo5aTKBLN5BV k/CDXSXS2FKhSbQ3d1K7MZiRudczziXNi5vU6Q72EQeu/9r/TtyB1Y/4Ih0lRkabVGp2 e0flBNtPIl7ZSbZfUqZ5iSum2jMZKMezFwFj9bnPFdt82FWS2jFBjJLAFjRfiD5i57FU 2sdA== 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=bDdB6FKpl+KkxPgQusFcTi8Dq94XDm/qeGa3HWCyiHywfgD3cQFzLwtaJUW8evnYYN g1cmz/RJUH7dU47RnEWlEoB3ykwz3GYjbWHWwZrMPkRqu9eazYDZsSnBh7G9km0rKALM D0usdCFhTK0wrNoq5Jd9meBrFUcj/6I4+HInDBzQ7VJdv8qrvQ03L4i8VUQR10zlUuST AIbnI/8EBimXcuu3V1fgHvNCpudhTlyzN0OZL81D5X9Qzdyytowzhj+krZRyEI960KxS F1jve/aclDYbSL4KkNs1mOeY2I92Rh7fnQrS9VjpY2Um/BsG19q1PmiHKz4pJwv1OO3Y bQPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vmgLA0vn; 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 y17si113839edw.601.2021.05.12.09.13.12; Wed, 12 May 2021 09:13:36 -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=vmgLA0vn; 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 S235218AbhELQNJ (ORCPT + 99 others); Wed, 12 May 2021 12:13:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:48504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233206AbhELPa6 (ORCPT ); Wed, 12 May 2021 11:30:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D542A61956; Wed, 12 May 2021 15:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832557; bh=D05Ms35Fa3zBhWVOkhp6js7LRYTCD4eitDpF6CmpE+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vmgLA0vnne3O/wK/8fge5p2m0P3agULS7MOZP2kq+n/c0klnx6x3cfHYSmu52I2uK qUXRyeLN8lavvJX1zo2n2+Q+D7iKL6+b+/RetGvC7ZRy8MRO8hB27v2Xpl2LAoCgnS i1lGPL+IilABhiarzLdktxnVX2Us6ArAJz47HchA= 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.10 327/530] clk: uniphier: Fix potential infinite loop Date: Wed, 12 May 2021 16:47:17 +0200 Message-Id: <20210512144830.556267125@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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