Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp342588pxj; Thu, 20 May 2021 10:33:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRFEjrWfSFybl36TS396UaUryFFr4AE3P2iZvmF4PvgUI4675G+UbyRhPR0IJ0TRi8jKjB X-Received: by 2002:a17:906:a18e:: with SMTP id s14mr5606112ejy.311.1621532001352; Thu, 20 May 2021 10:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621532001; cv=none; d=google.com; s=arc-20160816; b=sugBmMJGnxx0BwDrLHRYQ/AAuXQ6OjkpNLMql7eaUBC6QbR7A6MEYIEwuUf4hG11HS RXEJLe4ZbLdJ4APlbTzWmrFV9wS/KTtwrKHmUfa0lCNzkx0d8yI1dARHIegvJndITVmC i+M8BcQIlvKU4LCzETcF9J8vTnl9FJJkMlhfybJ1WXod7ylitz73Dm4hmZHmJpw5SbOR +3sfvwHNxk+kqsghsLkSVelq+PkcRs9MyuXSOPV4lLaRPrrt8BJHL99QIgy4neYmRPer 0dYAqXSfXrHIsbbwI0O4hx5O74yyBFhdjWHzimwKaSwQQfxnTc65gT564k6M+tdLMZem M3/A== 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=Kh3L0Pu0k4CT39ftwt0LYtrx8JPS/v3+STsp8Emaxr7IXObVyEGaN2Ds9tJO0amgKR pMNsTjrLLAhD+LUwIBfUS1umlPo6scWsLgJ+NNea98AvFsMgXSnsD+j/J8uDC+YxM8H/ sNYOuZ4So2DLJsUFpr9/2viUI+z45FMxZwrV7K5fAj7wDC9olAjgSLZuind8g19hWU4d /TlrM370n4CN6FkYCHhxL08mUn2twoWh8k9e6fVGL1YJWINvIJ6vSkq/HQF7e7PoD0an n6I4PAHDe2N/i8jAenF9RQMPvqfJRngxapzALtE/F5taC6vpDHscWC2tlxmW1PljLRPn 5soQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YPl09w+a; 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 x10si607895ejb.330.2021.05.20.10.32.55; Thu, 20 May 2021 10:33:21 -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=YPl09w+a; 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 S234953AbhETKBc (ORCPT + 99 others); Thu, 20 May 2021 06:01:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:60864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234659AbhETJ5M (ORCPT ); Thu, 20 May 2021 05:57:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F8DB6140F; Thu, 20 May 2021 09:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503476; bh=thZBLT5OleGrMB3A34zQLhYUq+OfO+QaM23VjAiwnac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YPl09w+a/AykjJoTkNylJ/p8cxsmx/hklVhXz5pgeB44L3RBQ71sTjpexoa6R3mxm o8ATX809qJHaT/eSRekWhjNE6qcNywT9rnLihQSkoN+lWcwf2M+sA8mgury+rsJsRC i0QamDDG1RX78Kjs0MDH+DaA+uaEPvAcx/lFx2B4= 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.19 238/425] clk: uniphier: Fix potential infinite loop Date: Thu, 20 May 2021 11:20:07 +0200 Message-Id: <20210520092139.250619600@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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