From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 63EED21D3E8 for ; Wed, 31 Dec 2025 10:56:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767178617; cv=none; b=adX3UzsXty8GeZTv6Xl5ED2W41Hpx+APIdLEf3WDC/CIds6V4N78ERexTaSj34egAWXF6d4eO9uXhMZfwwKfkik38o2bcbgLGZnkm0d6FgUEq5xfN7J/0ajGABDswGvCHhgoi3pIFKPld8XXEeJ6SepkwG+GacYws58vuT9czUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767178617; c=relaxed/simple; bh=gsvl1XJ48HrY4nODG0MTCbODAOb6WMQKqG7cDrnLhF4=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HjulHLocL7TlQ900FMgIuz4CEYYG6q+cii9f+MpPdzc8U31Lmyb4ha3gRf66PqFHSTMGT9A721wmxZGRKrPjabfMzna4OEoCxZec8iWnJ6rmVp/rnWZeXwjqKjbSo0WMDXpUefIZ4+M7iAp5RGG941COlG8cyMdn8Jr56seQQNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GmWnudX5; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GmWnudX5" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-477ba2c1ca2so113631685e9.2 for ; Wed, 31 Dec 2025 02:56:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767178614; x=1767783414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=i7R9+4upUD30LvVBHKBIsvpaPmqe/LxN03we2YAJ0+o=; b=GmWnudX5lpAJstB9doSzEkJbRvhiixjhMM7nbsJU0WG7OK4GGyvOjNF0+ZBUjg/kAj LuhCfkLT7WB/OX+5viuW7BSo856S1R168RJHk59L0/v+8Cd0tudlK6lVZnSj4RhGl35f PqMjZ76qaQBGEbfDcW4IPqe+dIHkox4NxmxuW9r9o9wJdk9yanoIHI0nn3NqjAHabbWt MgYUFfaAr1s962rNxm9ILE13IZeHUoDD8fi9u7rentq7NL/sjZiYJNIMvaGnSVcxdEyr 3JVuq0FBjo/SYkgGCmQb2IDiJQFkqqAiZd8scXzXufly4B/T6grQQV9tjKxnuhqP4yBp FaTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767178614; x=1767783414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=i7R9+4upUD30LvVBHKBIsvpaPmqe/LxN03we2YAJ0+o=; b=ezBirAgk+Oyu6Lnz8QYEw2lcG0OE51ax62rfB3KH1knrQJ9UCYYL1jE6XP6v6WpmNM EaMDfy5e1MAzzjcNe+NSHVuONBYGrYW7cUSsWEsffygyUdTySuZgyaVRooHBZ6sLdmvS jq75ryewkbgW/HHJlEFL5QX4BaOdnENEQsSBvnWEsDtr1W8EGY2M0Z+p5wGmX+zLK6sS u65F/88DXBiZX3gHWu8OynVKZsaMbKA7oByuVawAPHud3Kch5x2hmQ1kJwYwaWLFiQyB QUQTSYeTXgKb2HGyyWxYT0HKrcw0TppWfUC12sSMMdDfK3FLe9u/BABRKnTMbPtkZcbK A9qg== X-Forwarded-Encrypted: i=1; AJvYcCWgGESgzsgMvIgJU2GOdkg1YlULDzsqpDJ/mJ/br4YSzLEQo8aOReNAmhgi7nL6UVN753oXxX0sv+vHY+k=@vger.kernel.org X-Gm-Message-State: AOJu0YxUQe31Cqobp23P+2J4gFWEOw7GhvHr+onZMeTpC3zcTRrVmoCk A89Xy1wE57YsVI42k77hzZCiSONa1S7wvCx3xgOMkl4wQEX23IUswpSC X-Gm-Gg: AY/fxX5vQE55bK0dGNFibHvVDXB6r2ATxgNBsEjJoPeCAcx1B6aFmSjEnYWjqiHRWVq OYuOMtVczAwjAlVOIhbu7yRcfi2KeeL4GTFepmVMsaB/So5EpniB/vPYzbEzY6tUbbnbzNHoKeY FO5y7HG02fQVo/+l0F5TbwDSqvb6+jqxuphvZdiTjq8ZXutEY8siz9t1i6idaky+1WZSL6F2YUf 8ZoT8BYwMDoNpH4VIrZkB9IwjS2Rlg70IrTY5AioeUuVxyLy221+Vt6zJUg9f8VUbsYbGab+NVY kcuxFwVtDpNmBbHNgUakLZq3G+8SwWdme8EHNT1ekUzxwCVEdHdMLn3W2dukka1ARBfl3MNsToo WuZ/jVKQV9eGZhuhzgvGRUSovUqboEIIuvOQ/o7bkxDClVxkp2NZu7g28OCP52j+sBRGkWlKUGa Ph9I9LbZg6o1pxwOZgrRzb9HxefO8Ty2p0Jo6vCX5UI7KcIw9ZD9+CSXYgGcV+kQc= X-Google-Smtp-Source: AGHT+IHDZb5mskiCuLOc+8SBDEk/OvIO6Pug2fQj87O+qUGMgHUJl5YBr1B9MzEZuOqkC4xwyZSO8A== X-Received: by 2002:a05:600c:8595:b0:47d:5d27:2a7f with SMTP id 5b1f17b1804b1-47d5d272cd4mr54788585e9.26.1767178613627; Wed, 31 Dec 2025 02:56:53 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47be273e4d5sm696441795e9.6.2025.12.31.02.56.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 02:56:53 -0800 (PST) Date: Wed, 31 Dec 2025 10:56:51 +0000 From: David Laight To: Junhui Liu Cc: Michael Turquette , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, Troy Mitchell , Brian Masney Subject: Re: [PATCH v4 1/6] clk: correct clk_div_mask() return value for width == 32 Message-ID: <20251231105651.430f75f8@pumpkin> In-Reply-To: <20251231-dr1v90-cru-v4-1-1db8c877eb91@pigmoral.tech> References: <20251231-dr1v90-cru-v4-0-1db8c877eb91@pigmoral.tech> <20251231-dr1v90-cru-v4-1-1db8c877eb91@pigmoral.tech> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 31 Dec 2025 14:40:05 +0800 Junhui Liu wrote: > The macro clk_div_mask() currently wraps to zero when width is 32 due to > 1 << 32 being undefined behavior. This leads to incorrect mask generation > and prevents correct retrieval of register field values for 32-bit-wide > dividers. > > Although it is unlikely to exhaust all U32_MAX div, some clock IPs may rely > on a 32-bit val entry in their div_table to match a div, so providing a > full 32-bit mask is necessary. > > Fix this by casting 1 to long, ensuring proper behavior for valid widths up > to 32. > > Reviewed-by: Troy Mitchell > Reviewed-by: Brian Masney > Signed-off-by: Junhui Liu > --- > include/linux/clk-provider.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h > index 630705a47129..a651ccaf1b44 100644 > --- a/include/linux/clk-provider.h > +++ b/include/linux/clk-provider.h > @@ -720,7 +720,7 @@ struct clk_divider { > spinlock_t *lock; > }; > > -#define clk_div_mask(width) ((1 << (width)) - 1) > +#define clk_div_mask(width) ((1L << (width)) - 1) That makes no difference on 32bit architectures. I also suspect you need to ensure the value is 'unsigned int'. If you can guarantee that width isn't zero (probably true), then: #define clk_div_mask(width) ((2u << (width) - 1) - 1) should have the desired value for widths 1..32. It probably adds an extra instruction. (OTOH so does passing width as 'u8'.) David > #define to_clk_divider(_hw) container_of(_hw, struct clk_divider, hw) > > #define CLK_DIVIDER_ONE_BASED BIT(0) >