Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp796933rbb; Sun, 25 Feb 2024 04:37:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQe9kmJdhccPyxHXLDt/saM475ZR6E3fHiMrNPPrObG87Bnkon6W1/fTYA9q9vr0+TKvd/LFR1knduYEbxWkVEjgNqPwER9CEOHWKwQw== X-Google-Smtp-Source: AGHT+IFyeUAouqVLRTB/gvzf7tQluBEoY012H6WF5k5V6X0Jb8EbdVbGy9uNGT0c5SzA4MY/gILN X-Received: by 2002:a05:620a:575a:b0:787:ad31:d3c8 with SMTP id wj26-20020a05620a575a00b00787ad31d3c8mr4576482qkn.29.1708864651023; Sun, 25 Feb 2024 04:37:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708864651; cv=pass; d=google.com; s=arc-20160816; b=chBFGtgiXcPbbzEfIFGvsbwVxsp8LZ6/cwiMbJmyzRJ7jw1850YIZlnR2iC2nYP+SA YrFlArabiumMrUzP+ZfTRGs/QS370VU8PgegymRIUZtxSitN/osI4GHj8sLetFkGj5fi hMra1s5YcYIPZxODvBEt2li0gkcVcHPbm18E3yBBT1ODLH0WaHG/XEISqtJK0OSl9IWe poj4pFxlNIotEIjhiPOLLDdvXtSWivz7izB/kRnPd9cEWTjlKmn0tJ50VW8UkovDjB6e 2Tc6L0wFNTRxBA2sBQrP54fJlHHhYPQDqEw2SdNTmZAY1iITQZ6iQLL2Tj11VrNgWYJL tLlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=GMkJkQ5XQf70vJZkBI4YKSSGA1PbYpIYNkwgTn3Iuxo=; fh=TtyVz81524qvWhHHTJjNdcnyyg+r7LUmFCiwB1k3LMg=; b=bE4pu0lVKGg8PuHNW5IIBhfPlncEaTGZYP9D4SYoAD4Q9MauDT0qK2F8p010DxIFP9 nZjoXlLRdnYpGIksUmCITLO8sQTZRvo8Mn4khNjyGtqx1AF3ME2JftWEwfISXeahVDVf 7BHBffM3HIzDBZo9XcIKuL4I/65A8G48fxYi6fIaPiBJa7SCzQjjDxRmMlRHwShz7GSE Yi55EfrvfZAUKlV4UYG9vtnTDBjOTKzzurPPsHGJTCHRhMvZyiuwdnFLCn5wOkJpNppJ sMZaDBGPFhv9osZD6PKfe8o9IwkxtzlBdhsIRQonnshF7uMGHo/3uTQJrSsIgQGLwjh7 jyYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UEZFy1ZH; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-80063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g6-20020a05620a218600b00785b9c2ac6dsi2848884qka.11.2024.02.25.04.37.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 04:37:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UEZFy1ZH; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-80063-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80063-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C31591C20AF4 for ; Sun, 25 Feb 2024 12:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D41E4EEC4; Sun, 25 Feb 2024 12:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UEZFy1ZH" Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E319469E for ; Sun, 25 Feb 2024 12:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708864642; cv=none; b=ZY63PZE4IyrydZE8h+XvXtIkd+CT+7p6I5MumiQv45Win/mSsvZDHr3hKMAKlP0Vw7m2GDNQwgNB372mq1r/UMdVw6gdiKns5gBKAxpwbKHw5q3TvhUqxEuiRk5eHn0UhxwKO2Yzi/wQzmAoFh8wqDZbIGbyWyO42a3BJE8WHfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708864642; c=relaxed/simple; bh=JCUmCCCBdsObKnPRgnexNT5YKa+rHnpUtMGms2YqrBw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=iX5N8SPvDq+LKHdAZawJQYbDHACjD4FPAHK65Qt5NdeZWZk5T/bH6oGPQB3JwuZ6d/pdJWiqszDjH/rhJRf4AeZPIetANvRICihxauHeC0ApxP2bVq4SgvxKU1AGfirxc/Kq6DP9m9KHlX7CJirrZ7/yz2UoFcnm8fl+3VRnQso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=UEZFy1ZH; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-33d01faf711so2299146f8f.1 for ; Sun, 25 Feb 2024 04:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708864639; x=1709469439; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=GMkJkQ5XQf70vJZkBI4YKSSGA1PbYpIYNkwgTn3Iuxo=; b=UEZFy1ZHolo2LCIvQg08oyyV4OhBXfemftKc4ZLASEoKMmfrZoHk6vAVwnl2AyjAGd 7XT+VWlPrustIy9dEfDfgN4nNeJvqvlBsmb/4pmnTGQeQZpqVXKvnm917f89qHo2Wox9 kF+m6AxnGIlQ9HLwe0DGiEOXhBsDbhg5C031xQw7M7cZ2I1Z+J6T1R8KO9qSwb9lri4e dQoJ03qzZdGODCsKGD31byC9wCFH3tzMA6xExwBApmRi68o15rapKUlDhreQSHXbVVfe 8T5KLkPB7A/w6ZqOzuAPrV7u1eJ31LiUpTFvoSq/n82S5dJGi26xMU3xrTfYZTPCddUD dIYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708864639; x=1709469439; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GMkJkQ5XQf70vJZkBI4YKSSGA1PbYpIYNkwgTn3Iuxo=; b=RbEh8kWZFFcdLn+2gZpua3uqXYPyO0L0m2UqAXNT7w97OiBruRPnKpMXKfUL3IC9Ka P0Bz5AwsJx8I8Y1TF8KlyHGrDDp9pNw6lPO9V/2HzayOyUYsUtciWFDU1HvSSLoR3h0b npVHfT/o8GfaYHtiWgPZ1Ns5NTyI12PkDVXpPhzX4kys2PwIp0jE7N2H+t83Kw7zhGAO cvKazPvN/EgegKdZzesqOCEmNuc0oK1mLFG4LrjclA5l3AFq00bdWJBFc66q8yL4kPAx s7eKOSHTaFpCm+Q/5GoGZbFwSdA4nhT8MCwTkUpCgN3CBSO6UjCoonQLw7k95MQxot5i UUvQ== X-Forwarded-Encrypted: i=1; AJvYcCVO538ON5jbGO/RTSfKxjrmszBxoi/6B1FO6vOSKKZCMuivk4870UVerG0gfZhTJSvPHWIEz2IijlczKUfwU5bYEEH3FNVzgt7T0ZWE X-Gm-Message-State: AOJu0YwT5BkL35aOO4xMuvzAGodZWEq7J5rn3U2h9RhhWMk1eTXktciN tXkR9q0oyXhkhoLPe7XEOSCIxtl8iFVsgI3/vEwSy4v7HXYidLyBvnJSerlCbDE= X-Received: by 2002:a5d:410e:0:b0:33d:bfb1:4c51 with SMTP id l14-20020a5d410e000000b0033dbfb14c51mr2167610wrp.10.1708864639416; Sun, 25 Feb 2024 04:37:19 -0800 (PST) Received: from [192.168.10.46] (146725694.box.freepro.com. [130.180.211.218]) by smtp.googlemail.com with ESMTPSA id ba21-20020a0560001c1500b0033dc3fe1046sm4090407wrb.77.2024.02.25.04.37.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Feb 2024 04:37:19 -0800 (PST) Message-ID: <5d3b6c7c-b526-45e0-95fd-deedad2411f6@linaro.org> Date: Sun, 25 Feb 2024 13:37:18 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] clocksource/drivers/arm_global_timer: Simplify prescaler register access To: Martin Blumenstingl Cc: tglx@linutronix.de, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patrice.chotard@foss.st.com, linux-amlogic@lists.infradead.org References: <20240224213529.2601333-1-martin.blumenstingl@googlemail.com> Content-Language: en-US From: Daniel Lezcano In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 24/02/2024 23:13, Martin Blumenstingl wrote: > On Sat, Feb 24, 2024 at 10:55 PM Daniel Lezcano > wrote: > [...] >>> @@ -301,7 +298,7 @@ static int gt_clk_rate_change_cb(struct notifier_block *nb, >>> psv--; >>> >>> /* prescaler within legal range? */ >>> - if (psv < 0 || psv > GT_CONTROL_PRESCALER_MAX) >>> + if (psv < 0 || !FIELD_FIT(GT_CONTROL_PRESCALER_MASK, psv)) >>> return NOTIFY_BAD; >> >> Won't FIELD_FIT cover psv < 0 also ? > Hmm, I wanted to reply that it doesn't because internally FIELD_FIT() > uses a cast: > ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask) > My original thought was that the cast would clear the sign bit when in > fact (I think) it will not - it will result in the signed number and > BIT(31) set. > So I think you're right, FIELD_FIT() does cover it. > > However, there's something else odd with this code: > We're dividing two frequencies (using DIV_ROUND_CLOSEST) which are two > unsigned values. So the result of the division can never be negative: > psv = DIV_ROUND_CLOSEST(ndata->new_rate, gt_target_rate); > However, we're additionally decrementing psv by one: > psv--; > So in reality it can only ever be negative if the result of the > division was zero (for example if new_rate is smaller than > gt_target_rate). > However, in that case we would have crashed - with a division by zero > - in the statement right in the middle of the two mentioned above: > if (abs(gt_target_rate - (ndata->new_rate / psv)) > MAX_F_ERR) > > So I think we need another patch (it's best to order that before this > one): make psv an unsigned int and error out before trying to divide > by zero. > If you have any objections: let me know, otherwise I'll prepare a > patch tomorrow. I think it makes perfectly sense, thanks for making the code nicer -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog