From patchwork Wed Sep 11 07:39:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13799840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96071EDE998 for ; Wed, 11 Sep 2024 07:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=jMhPnhQLGUUwFA6J63dF4flmVGV7ie7Si62HtCm+ens=; b=iEfY3FNMqH6lhikaOQkx94ehXP eHvDPaHYLfG4uMx5swXoQtH6zjTdGcK45rqWn2VRA1D0Is4ZBc1OIWdbvkflfrfL6fLTS9ZdFcdeD ip1eZ/fdDJhWN8PzS2uGODUoMI5nB9Kv/aehc7kmRcaj+j6eSNTp95J6xd6bf81piPgPK/GQ52oog POeo3ntFd7ebGpUbkfvEq9FaG0XnmhEEFSrTz0ArCi/y81o5TrBZ2qodFL0DQ3LynMv3oYhmZJR0t v0+dHSFEFdgIZ+pTgdeHcoox0x6fUsG/qfHaZzBwdIhdIgUxqSv37Yza67YVwT3haniYjnJeXV5UF KP9+O5ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soI0q-00000008Uwi-0yu7; Wed, 11 Sep 2024 07:43:40 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soHwf-00000008TnF-0Enu for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 07:39:22 +0000 Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-374d29ad870so3987505f8f.3 for ; Wed, 11 Sep 2024 00:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726040359; x=1726645159; darn=lists.infradead.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=jMhPnhQLGUUwFA6J63dF4flmVGV7ie7Si62HtCm+ens=; b=ImJZohxa5Cfq22lr/UJKt7niZ91R41bMw9XTMNb96vp+cgO9cCuA6sHjBNh58a2ful Jp/CEFp4Dbog3UAMfrEkYFKOIUTAKwwXO0JIdy/WhMHWqEYUuNhzP1SNdXZHxf0xKFNt G8lN2Pgd2O3KwXPdQilhN7nXxZ9TbTHnb4f478+WFAtavHlpleUzfPH9BSkvxYi3zYhH Kb+TMCGn3l3YE5OkvkgSeEu6K57M5Rhsnya/w8BvCb8RgFX9LwowgwaJuJL4iKYB7PtR 4aZ8WiJuehyM9Y0N/DJfuEFh0Sjj2LTc+rhRR/hhDhqJvaGkNxCMPoFy1CN33L1+nnGl 97tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726040359; x=1726645159; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jMhPnhQLGUUwFA6J63dF4flmVGV7ie7Si62HtCm+ens=; b=njrm31IniurAnHRGDBKAbIK//QOZwQBheImOvUvhRrzXimAs2cyb5bvW1DhiReUYXY w7dR4YD17k6iVHc1mD4jVGMvaujzYAvTm4UFBOOd1Ic90TL2c9M2/PWF7ycAKkRCP+et Bvyo2mQ/w7OVZUOF3jQTcVSmPOQPANt2wr9cK3CmifkH/L6vdBpYb2gcn5bV+nnlJCNb KpJexFoYvuVTtYyOIQjF7TBeCXW/hBl1FWIu/M9uhhaKRqaQIu7P9GcT4+DijU4bjHnE 5dLTpZ4wr+InOvRhUVgVpsGJ7Tx75G/qNH9aZDno4I7+xzF7CkV2QuZlLPYGgzAO9uum ksmg== X-Forwarded-Encrypted: i=1; AJvYcCUamZXs95//adM9rwgVd9Dm0xiQK7wrS+R8e8JkalX1J6XFFwWmA3pAl4P8KfwC4gzGG+q6/7w4ZYy1GEseLks7@lists.infradead.org X-Gm-Message-State: AOJu0YzB3/EPA74jvkMwlvu53bH5LeAq983OwCwA9wAs2XXjrUvoQCjJ rgqW6HS9boEvOCcn3i/vSs+9TReCc61eTwDRen3pzHCo0T/5W/LQFlaMSAbgpVc= X-Google-Smtp-Source: AGHT+IESuS36LExi/2RVMu8sWMe6uqy4QE6i31lVfI6gt/QUy4qRreYxyP5mTDnkIk3YvBnM5tmX7A== X-Received: by 2002:a5d:6945:0:b0:374:b24e:d2bf with SMTP id ffacd0b85a97d-378895d46c9mr11371355f8f.27.1726040359142; Wed, 11 Sep 2024 00:39:19 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42cc01d3d17sm41603025e9.0.2024.09.11.00.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 00:39:18 -0700 (PDT) Date: Wed, 11 Sep 2024 10:39:15 +0300 From: Dan Carpenter To: Nikita Shubin Cc: Hartley Sweeten , Alexander Sverdlin , Russell King , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] ep93xx: clock: Fix off by one in ep93xx_div_recalc_rate() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_003921_127453_17580494 X-CRM114-Status: GOOD ( 13.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The psc->div[] array has psc->num_div elements. These values come from when we call clk_hw_register_div(). It's adc_divisors and ARRAY_SIZE(adc_divisors)) and so on. So this condition needs to be >= instead of > to prevent an out of bounds read. Fixes: 9645ccc7bd7a ("ep93xx: clock: convert in-place to COMMON_CLK") Signed-off-by: Dan Carpenter Acked-by: Alexander Sverdlin Reviewed-by: Nikita Shubin --- arch/arm/mach-ep93xx/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-ep93xx/clock.c b/arch/arm/mach-ep93xx/clock.c index 85a496ddc619..e9f72a529b50 100644 --- a/arch/arm/mach-ep93xx/clock.c +++ b/arch/arm/mach-ep93xx/clock.c @@ -359,7 +359,7 @@ static unsigned long ep93xx_div_recalc_rate(struct clk_hw *hw, u32 val = __raw_readl(psc->reg); u8 index = (val & psc->mask) >> psc->shift; - if (index > psc->num_div) + if (index >= psc->num_div) return 0; return DIV_ROUND_UP_ULL(parent_rate, psc->div[index]);