From patchwork Sun Feb 25 15:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 13570889 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 03B9DC54E49 for ; Sun, 25 Feb 2024 15:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cKdJ+IgLf+RG0IEq6nlPXmyDkJZPbTNoAPxEWga1Gh4=; b=PY/7erQu0De6Ux wHI4DUu2qUyle4Rn0uDE6hN5ZWXC+8YpePVdDYoxYokjRyid509/n+78TzUH47MgwiY2r/SCLu0sq 4CnB4vuHilW5fVEUutx3KDgBcV4fxaDZrsdeXBT1ZrbAz6GWYc7pvYSV3DoGO6fffunXRNuFQikKi MEkGH+n30y/uZiHfjAj84hb6rlZxXmTM9LSAAXKF5hEbomR5WVVoAP491K/Cg/9JFOuKtWsRZ+ITK R5ENvkCtoegu+1BadoX6PdSb2n2X4301h+tg3N2gcA46Bke+z5DMmMRXsD4Tn7Y7C2CClD/2KfVLj GGsMYk9ZCAftv1UEpeCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reGCa-0000000F9Ay-1JHH; Sun, 25 Feb 2024 15:14:04 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reGCV-0000000F97M-0bhC; Sun, 25 Feb 2024 15:14:00 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-55a5e7fa471so3033841a12.1; Sun, 25 Feb 2024 07:13:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1708874034; x=1709478834; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NmS4gDNEWmUck8GHVINRNCbZHkdEW63y1bKjUv7oLPQ=; b=DtdIOOfhNzJdZ+dz6Xzm/QTkFV7s7qRVXAEvnmlCAJvtAkfczunncSAxrb8poCTun5 mBaYdtX4lpjFTwKrptDvspZg5aCJUQmfMnxoqhmPE3FxylCyO9/FRIgNJVs17dSvbV3o M17NRJDHfz7h214FMrpQfZDtsGtovGpm87tYbISDKGlwxoNgMfmV2Tj+TDIN9vrw7bU+ YWsKuG8cDRGYzLp3xSvOR+mVymBE2n2fLxd2joj+Vhv0xdp1XcpIkOfgpPPbJhl8b/JD H5zAwF8zpRXBA4lt0ESfV1z5F6vY5/pe+DcQrEqurgP66CgbpeBDgs6T/fR9G2NRy2Kc KDIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708874034; x=1709478834; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NmS4gDNEWmUck8GHVINRNCbZHkdEW63y1bKjUv7oLPQ=; b=vUyjrB+2zkMy4IVgBpOa4AhdbM0LFpTI1od2YCzJHEuCAQAVHSpN9uXlQTrCB/6sBh 2pCfNSlN4aESgUEGKdyD1bvczLUCsML4WtFxdHhkYodoJqRbOiRL86pHbFbJGjlp8Dwj 6uqNyhk8d+TU0HxQNTGZjY72DKDXaWxAV6ovNyCluY8mH5RZJ1X/NfuUMKWoGwfQVZFZ a7/syKAn8Uh5Xr9uCsmoAbOsvU2P8n2fdt13TWNsRNJkFyBx9n8i/YqpNVZlTnDOK6dL GnNumQypoSJ7xfVY1Sio8ntA8vVD6DGMF6StpR1LCKBZLLljrLRpgplmPEVA2SGNC1Xu S2eg== X-Forwarded-Encrypted: i=1; AJvYcCUFG2tr114psoGBwd2oKOW1fJ2VE521q3dLTOefX5P9tRWEZeUDPLTvIArtdKGd9+34yC/qT2xXl4AwERZl6JD1VhsbDOaxpijCA+6eOCwEZMo= X-Gm-Message-State: AOJu0Yzv6TY6HHFsPRoBg5LHrNCF0qhewE16zZFbwNBOoYCR37ZJ5vv2 J1XbP4blgtKPJglaKBxXcLX3rg6WCC/MIBeftp2gqMgSa3c/SKMW X-Google-Smtp-Source: AGHT+IEkhbI4nG+Vw4+mL6QrL0isP40UUWu3tf2QCFS7NrKvQ48vP8UHbsY+NMoO6aJCF078nPvsqw== X-Received: by 2002:aa7:c34b:0:b0:565:d125:221d with SMTP id j11-20020aa7c34b000000b00565d125221dmr1109817edr.32.1708874033937; Sun, 25 Feb 2024 07:13:53 -0800 (PST) Received: from localhost.localdomain (dynamic-2a02-3100-94e3-d600-0000-0000-0000-0e63.310.pool.telefonica.de. [2a02:3100:94e3:d600::e63]) by smtp.googlemail.com with ESMTPSA id f5-20020a50d545000000b005651ae4ac91sm1588450edj.41.2024.02.25.07.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 07:13:53 -0800 (PST) From: Martin Blumenstingl To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patrice.chotard@foss.st.com, linux-amlogic@lists.infradead.org, Martin Blumenstingl Subject: [PATCH v3 1/3] clocksource/drivers/arm_global_timer: Make gt_target_rate unsigned long Date: Sun, 25 Feb 2024 16:13:34 +0100 Message-ID: <20240225151336.2728533-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225151336.2728533-1-martin.blumenstingl@googlemail.com> References: <20240225151336.2728533-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240225_071359_236842_439B4533 X-CRM114-Status: GOOD ( 11.06 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Change the data type of gt_target_rate to unsigned long as this is what we get back from clk_get_rate(). Signed-off-by: Martin Blumenstingl --- drivers/clocksource/arm_global_timer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c index 8dd1e46b7176..fb3ffd54c822 100644 --- a/drivers/clocksource/arm_global_timer.c +++ b/drivers/clocksource/arm_global_timer.c @@ -52,7 +52,8 @@ */ static void __iomem *gt_base; static struct notifier_block gt_clk_rate_change_nb; -static u32 gt_psv_new, gt_psv_bck, gt_target_rate; +static u32 gt_psv_new, gt_psv_bck; +static unsigned long gt_target_rate; static int gt_ppi; static struct clock_event_device __percpu *gt_evt; From patchwork Sun Feb 25 15:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 13570890 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 1693AC54798 for ; Sun, 25 Feb 2024 15:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=To54eC24sUuvJoVYlnp4MF2BDmLQg87GrzY/apIPq4E=; b=EU33+bx/vbgTg4 SvkFfyBfYdY5NnPZs0dNI0lX+wyiXzeyBKPEeQdR8BEXOfeUuBE7iC0gDK6Ye5X6pP2txO/pIgpLh kXw0VWwMrcqT78rZU2iYdvhryW5yMEan3v8yBWdZi35NdOGd6L1qQoBMSICxV8hscSM7BS7+9ebo4 i5tNS2Nrx3J1o647tqOLwU9rUy2JZ89GM77rqF6TU6pWS/sRv4c7fW+L82voc/sxRc/1iMugvzuQa n1W6nehOa45u3FuRRX1VxiDf7OqF8iX2spPE3+v7zSWg3y1WiCOE4l3yVefuJqTxZ4FMluHHerK2Z 01oSYaSRQR/aXcRkLgtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reGCk-0000000F9GZ-1w86; Sun, 25 Feb 2024 15:14:14 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reGCV-0000000F97S-2px1; Sun, 25 Feb 2024 15:14:02 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-564e4df00f3so2870777a12.3; Sun, 25 Feb 2024 07:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1708874035; x=1709478835; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LqzAK/rpa5OgHPM2K5eydECFHp0Pspegr4Gfp32qYnk=; b=Gs9mV4nVsWjZ9rCnsyyFce8NVP6lE+K69Tpr0P9v88KLLq0+rtybiAyIrZTA6MU7+Q 89JDC4dOZA1NkzLE19zSyOUiWjQBcTQqVDtv0vSrBlVoEjgAalctx9Rs3ksJDwcvlvYc 0NFNr/7FRWvNyp5fsljHwl39n2iVWuAu1lsccfj0Fj9UfG0d+2NUeEGJb9lrGB5Ko9Ld qFvMxbdujvGuzxmDxW+UWJBhw3t6HO0mLUZR/9dyeajZnnGew0jgo1leWchdM58KuhQy T7Vb4xhZe9bmENFnx3lulMnq2Mgo2RbnTs89YcHL1GX8a/EjbUOI35YfTjzqjIxyZL/3 Cjhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708874035; x=1709478835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LqzAK/rpa5OgHPM2K5eydECFHp0Pspegr4Gfp32qYnk=; b=GX2u+BgStyE+sDYWOQGmvzZYH4FQAMIimJaknjuRXxIZk3RupYPgudbHBed1r/2pdA cBE4Uu+mBy5L9f3FQYfNMCSrgSqCzOBxcGkE0eTfQI5Ck3CMGlnYf7jRuBKDZYKne48j dZymY8g/rT5s+wtps886bsAoz7vQ6dLMmupTOQ1HPz4jiUwlxYqdmb+xsuCWFeORM2j8 oXiEv5yMsHqPddu4n52pDdXJKxiglr8GjLkF/dVJDGuOjmp90uiQZrCKl/WfrdAbvkvd dEEHvOWB2cW85pSZEthTCckJvwCyOl3xR6fELGC1WCvUMwT1wb3jNNqT3k7JR5osBAeT XVyw== X-Forwarded-Encrypted: i=1; AJvYcCUYrjdRvzKQcyBHQ/n8pv5VK+o6NaIAoD+HT3kp06Bthj95HFnc+GLIAaxp0wQQ3iLwg1w+EwsZwsla0hC3lbO+zWAlC/I+0wvp7b+i0eI6Cwk= X-Gm-Message-State: AOJu0YwrRjyZWpSQtfgsOekjf9irUrD9ZxfeP4AXW+KU+/7qJia7BafW LXz6cAwAnQKKzkp0ITuXI1nRJPvenMAwO/glIikYO4X+nN7VKBox X-Google-Smtp-Source: AGHT+IGkQ09BVgHI1DnowCCqKMkEwUFloLKHKWTtL/sGl3j4U7VUMrYUG75/56+rg5mzCYn+UJBPZg== X-Received: by 2002:a05:6402:2c7:b0:565:8e3a:5add with SMTP id b7-20020a05640202c700b005658e3a5addmr3081349edx.15.1708874035054; Sun, 25 Feb 2024 07:13:55 -0800 (PST) Received: from localhost.localdomain (dynamic-2a02-3100-94e3-d600-0000-0000-0000-0e63.310.pool.telefonica.de. [2a02:3100:94e3:d600::e63]) by smtp.googlemail.com with ESMTPSA id f5-20020a50d545000000b005651ae4ac91sm1588450edj.41.2024.02.25.07.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 07:13:54 -0800 (PST) From: Martin Blumenstingl To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patrice.chotard@foss.st.com, linux-amlogic@lists.infradead.org, Martin Blumenstingl Subject: [PATCH v3 2/3] clocksource/drivers/arm_global_timer: Guard against division by zero Date: Sun, 25 Feb 2024 16:13:35 +0100 Message-ID: <20240225151336.2728533-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225151336.2728533-1-martin.blumenstingl@googlemail.com> References: <20240225151336.2728533-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240225_071359_750367_07D7C2A4 X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org The result of the division of new_rate by gt_target_rate can be zero (if new_rate is smaller than gt_target_rate). Using that result as divisor without checking can result in a division by zero error. Guard against this by checking for a zero value earlier. While here, also change the psv variable to an unsigned long to make sure we don't overflow the datatype as all other types involved are also unsiged long. Signed-off-by: Martin Blumenstingl --- drivers/clocksource/arm_global_timer.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c index fb3ffd54c822..257599d682f0 100644 --- a/drivers/clocksource/arm_global_timer.c +++ b/drivers/clocksource/arm_global_timer.c @@ -291,18 +291,17 @@ static int gt_clk_rate_change_cb(struct notifier_block *nb, switch (event) { case PRE_RATE_CHANGE: { - int psv; + unsigned long psv; - psv = DIV_ROUND_CLOSEST(ndata->new_rate, - gt_target_rate); - - if (abs(gt_target_rate - (ndata->new_rate / psv)) > MAX_F_ERR) + psv = DIV_ROUND_CLOSEST(ndata->new_rate, gt_target_rate); + if (!psv || + abs(gt_target_rate - (ndata->new_rate / psv)) > MAX_F_ERR) return NOTIFY_BAD; psv--; /* prescaler within legal range? */ - if (psv < 0 || psv > GT_CONTROL_PRESCALER_MAX) + if (psv > GT_CONTROL_PRESCALER_MAX) return NOTIFY_BAD; /* From patchwork Sun Feb 25 15:13:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 13570891 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 F1FA4C54798 for ; Sun, 25 Feb 2024 15:14:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DEsRaCoagv4VQKOsZmvGDlgAxBIk2QBYCK/vI1ALdi4=; b=QOmOKv/nC5Dk3e BcS/KFgx6DK3uo0tCsS8zLRWhYDcIQUBQAH11xQJYPjTlecQ3eXLvmCcuqj6wdab9g85hqKJ9g3a8 aA4sNJ8vOIYYZzCywCq03bv4DZRCcVfPi4ykoV9mwQtzq6OToVBdcRMFBMBKcrAVvsA2laBrij8qW al8BiGjiix4xJh6lpBfvTNYd8pImVex+PjX04t8qw8gXSD+qRflMbrWGUj33A3rB8WLZ0WH2BU/ux fG5rFFlMqB8qtlPqGF82iNi5zpSgkxL2krb9AJ5xJf+ArWbPYMULVFEZOJYSn52fcdzS5xWf1XyTz n2Q73Gkc1AvaLYxvgWng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1reGCt-0000000F9ME-3pXL; Sun, 25 Feb 2024 15:14:23 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1reGCV-0000000F97T-2qIs; Sun, 25 Feb 2024 15:14:02 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-55a179f5fa1so2460800a12.0; Sun, 25 Feb 2024 07:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1708874036; x=1709478836; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sRqUqyxM5BwYZ552SwBc1mEqP/KlJT+duufn8/IdCwI=; b=ODi0uu/Kq00u+2a34g0M9lq0rzEOdTq/7n+lg8L+nQkcj/yRX2xo9BkWFM/4hVuc5d 0sxECkInagqxKSmbhCiB6lhWn9MkTgkJYQTSEh5KA5bZSqyo59AVypmiPR9j9jcBgoIR a+YCXP7AKRLttfOiaLUlEfKhcaIGekiTotm60tARU22N85/PW8ijPL7qdRYxLeOnCb43 ZK7rf+njYLRrpTOdViXEzg/rUmB7/BoOMpwiWcQOHg/FXldi2VW+NhJyYYvY5lbmUiMh BMCp965PUhlwqHiLp1KTndjcSWo8Q1rrXQeu+N5HVBz8AVhhvDMXygjnAMcVPizELInr JBPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708874036; x=1709478836; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sRqUqyxM5BwYZ552SwBc1mEqP/KlJT+duufn8/IdCwI=; b=jECQ+aqXbJlQrFh9uqob8a4iBTRX+HnVsUbAm31QpfW3o1aTxhV935gcWzPbYoiRD9 n8OxiTIgXaYIA1JbrsHfqPwPfxx7hbDfqgpm+bPjPrNG/aoVCa1lYY8VKob1xwJ+Hq/U IekLRM5wDUOrw7UtvXiv4NxgoCqInlXRgC49jPcNEvuTlN2YKgkkSuADapCYU0JVMW6F oMkAQiirAwi2MTINTfdzK7G1Gg3rVKKvJs0n/+dOg1BUZAyjJCo2s81qaxP6yDHyaLD7 hVLBuk6SypDlXiaWcCVYB4IN3ydC/J3AhMM0ci7JQFAvb6GIVlLUAqgi4uzNfWwDvwNr aG6g== X-Forwarded-Encrypted: i=1; AJvYcCVio0HBXDT4HoG0lgfdewGHs82RhTfzDrDXXOuaA3IH0rJrix47kZSt/lycRdQH5bbyM/PCMtB1gxvbVGT8EOykdtmc/r+uEyEnuMCnksPrUfo= X-Gm-Message-State: AOJu0YxMaSinr42AuJpaOrrPG504PquIlq3b4u0e0A4+FL5gahJI2iJ9 d40G05njo8OwI8Yc8p8RmyNzSe4V03Khho+xipvRSb7+cjkaUxqb X-Google-Smtp-Source: AGHT+IH/nJnTUXso9xp8HekK1IjRVINalYAkwjwR4Jk7//muUbYijeHEbdBfJgf96o6NZ6fJ/+967A== X-Received: by 2002:aa7:da09:0:b0:565:cd29:dd30 with SMTP id r9-20020aa7da09000000b00565cd29dd30mr1166096eds.30.1708874035965; Sun, 25 Feb 2024 07:13:55 -0800 (PST) Received: from localhost.localdomain (dynamic-2a02-3100-94e3-d600-0000-0000-0000-0e63.310.pool.telefonica.de. [2a02:3100:94e3:d600::e63]) by smtp.googlemail.com with ESMTPSA id f5-20020a50d545000000b005651ae4ac91sm1588450edj.41.2024.02.25.07.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 07:13:55 -0800 (PST) From: Martin Blumenstingl To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patrice.chotard@foss.st.com, linux-amlogic@lists.infradead.org, Martin Blumenstingl Subject: [PATCH v3 3/3] clocksource/drivers/arm_global_timer: Simplify prescaler register access Date: Sun, 25 Feb 2024 16:13:36 +0100 Message-ID: <20240225151336.2728533-4-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240225151336.2728533-1-martin.blumenstingl@googlemail.com> References: <20240225151336.2728533-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240225_071359_749194_70E9C683 X-CRM114-Status: GOOD ( 13.75 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org Use GENMASK() to define the prescaler mask and make the whole driver use the mask (together with helpers such as FIELD_{GET,PREP,FIT}) instead of needing an additional shift and max value constant. Signed-off-by: Martin Blumenstingl --- drivers/clocksource/arm_global_timer.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/clocksource/arm_global_timer.c b/drivers/clocksource/arm_global_timer.c index 257599d682f0..8a82b60b467b 100644 --- a/drivers/clocksource/arm_global_timer.c +++ b/drivers/clocksource/arm_global_timer.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -31,10 +32,7 @@ #define GT_CONTROL_COMP_ENABLE BIT(1) /* banked */ #define GT_CONTROL_IRQ_ENABLE BIT(2) /* banked */ #define GT_CONTROL_AUTO_INC BIT(3) /* banked */ -#define GT_CONTROL_PRESCALER_SHIFT 8 -#define GT_CONTROL_PRESCALER_MAX 0xFF -#define GT_CONTROL_PRESCALER_MASK (GT_CONTROL_PRESCALER_MAX << \ - GT_CONTROL_PRESCALER_SHIFT) +#define GT_CONTROL_PRESCALER_MASK GENMASK(15, 8) #define GT_INT_STATUS 0x0c #define GT_INT_STATUS_EVENT_FLAG BIT(0) @@ -248,7 +246,7 @@ static void gt_write_presc(u32 psv) reg = readl(gt_base + GT_CONTROL); reg &= ~GT_CONTROL_PRESCALER_MASK; - reg |= psv << GT_CONTROL_PRESCALER_SHIFT; + reg |= FIELD_PREP(GT_CONTROL_PRESCALER_MASK, psv); writel(reg, gt_base + GT_CONTROL); } @@ -257,8 +255,7 @@ static u32 gt_read_presc(void) u32 reg; reg = readl(gt_base + GT_CONTROL); - reg &= GT_CONTROL_PRESCALER_MASK; - return reg >> GT_CONTROL_PRESCALER_SHIFT; + return FIELD_GET(GT_CONTROL_PRESCALER_MASK, reg); } static void __init gt_delay_timer_init(void) @@ -273,9 +270,9 @@ static int __init gt_clocksource_init(void) writel(0, gt_base + GT_COUNTER0); writel(0, gt_base + GT_COUNTER1); /* set prescaler and enable timer on all the cores */ - writel(((CONFIG_ARM_GT_INITIAL_PRESCALER_VAL - 1) << - GT_CONTROL_PRESCALER_SHIFT) - | GT_CONTROL_TIMER_ENABLE, gt_base + GT_CONTROL); + writel(FIELD_PREP(GT_CONTROL_PRESCALER_MASK, + CONFIG_ARM_GT_INITIAL_PRESCALER_VAL - 1) | + GT_CONTROL_TIMER_ENABLE, gt_base + GT_CONTROL); #ifdef CONFIG_CLKSRC_ARM_GLOBAL_TIMER_SCHED_CLOCK sched_clock_register(gt_sched_clock_read, 64, gt_target_rate); @@ -301,7 +298,7 @@ static int gt_clk_rate_change_cb(struct notifier_block *nb, psv--; /* prescaler within legal range? */ - if (psv > GT_CONTROL_PRESCALER_MAX) + if (!FIELD_FIT(GT_CONTROL_PRESCALER_MASK, psv)) return NOTIFY_BAD; /*