From nobody Sat Feb 7 17:49:06 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 DEAF025E440 for ; Wed, 30 Apr 2025 17:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033344; cv=none; b=pM3oa1ShRMqad0HqgjtJyRnao57tR/FyiDjFy1laVNWz3jNX6UeJo+2X3USDS+8JsVkTKd90Yb8YrbF0XU+/Q19B1BEAWTn2gKUu/53d8rOghZQv2gMAoN8Q9LTfAVrGNP3mjm+F8dw9q0Oi3StX57RSHTBPQqK100vSrMfU2G0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033344; c=relaxed/simple; bh=lm5ga5E1Bh0WGysa1ZSSmKbnAd9w4JpDDVcJpw+p0k4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=OIt/YnlPHOXcFEqAI/1agWP2oUfUlAfV4td1zFi/we4IGjHUNf7EZw96SgXRnkes1Q5WLx85Ei04sPFtw//xNwK/xu5aV97Gb0So8RyDuWYWZmEJxVgq65hw7/+aKd4JtKl52qcAgL803vCYtnUWOTGG0xycfijcOX4g0bjkVoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PmKPxZYp; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PmKPxZYp" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-739515de999so98606b3a.1 for ; Wed, 30 Apr 2025 10:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746033342; x=1746638142; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=FpIgS0wmOV5UbvgaGzkA8qij/rEeOqGzeG6VWVukYPI=; b=PmKPxZYptul18cSKHetms8n+PTcVIzKUlAVUFOQgagL5/znyW/MBGYppFcxrDsnUpA Ermr+cqYzHLXL7RUKbxvb8H9vTwMAjn2NkBn242oJ2bwrezB5K7naNc9tFXtF8jV8aXA NSjCHVPL2ntKIVTFZnoIkXx7inIx/ZY56zsg8LVD3+FJJYd6h3tIuexxAoSxvMGihqBE 1OVGqyp+Z6yYdp8/gum8K2OWtoUdvtzrXhSd8k505E/ILCHcmirvFUQI9I9ig4nCRnAk zhDEkazss/WPAJhXXFS0QNOMb/i5ZXd0vdnj6EV88u0TAfqmaFuMS/NXx+Hfo0k3tXmv E2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746033342; x=1746638142; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FpIgS0wmOV5UbvgaGzkA8qij/rEeOqGzeG6VWVukYPI=; b=Je6EIN6UItxeZ+OejDvcLKG7/orvygpsfC+ei9cTm/vzeuMCSujTfUqhMJGoahHk54 UjoMq8fWLB/1b6DPyFdDon4aH7uRk/zX1ZAyVGrSfPd+imENKcJm57zweWzRYyseWkf5 P+1BCHBQt7QHEEa5WWkhz0XnoiiOTegjlVYCe9RyTVVTkjyCZIwWu2YMzdGdnfVK6MVF cceLq132OQc1ddNCht0uIpQKDufkDbbhgFKuv+EuF48HgTkjG3kHa9oGeW4jA5deGIBW tUbZh7OJjhUpUjUdcCcZKDLqZu/jUd+gSwwoux3rMLNW5QuZnfcfmMzfDPmW1CfaYssx 1b+g== X-Forwarded-Encrypted: i=1; AJvYcCX8ZsmrJMlDfvIWy8n2ufdlizMhmB0Yi7/O1b1qB8/9UxA/VaktvzPLIip4+DlWUoNDa7shYo1JCf/qtGE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3aER5npMhF/8J8jaJROkmwGLhEv+rllnl0PUOJIIcn7aiJA79 N/UeOmW1h6CW73YBHJrQBZd8Vr+V8JgAr5ZwIzKxNSGdIQta6IihShIoSjmRTQqyfMG2MNshCur AuAdeSg== X-Google-Smtp-Source: AGHT+IGv8XMgRIoeJR1rySLXISqqmVQqJou5NGwUjKxk7iOH4VQdGHhiObrDzUu60o16T054lU4v3OaRDTR/ X-Received: from pgkb21.prod.google.com ([2002:a63:eb55:0:b0:b1f:857e:2198]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:e617:b0:1f5:75a9:526c with SMTP id adf61e73a8af0-20a87c5680dmr5326067637.13.1746033342084; Wed, 30 Apr 2025 10:15:42 -0700 (PDT) Date: Wed, 30 Apr 2025 10:15:30 -0700 In-Reply-To: <20250430171534.132774-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430171534.132774-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430171534.132774-2-irogers@google.com> Subject: [PATCH v2 1/5] bitfield: Silence a clang -Wshorten-64-to-32 warning From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Ian Rogers , Adrian Hunter , Thomas Gleixner , Jakub Kicinski , Jacob Keller , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clang warning -Wshorten-64-to-32 can be useful to catch inadvertent truncation. In some instances this truncation can lead to changing the sign of a result, for example, truncation to return an int to fit a sort routine. Silence the warning by making the implicit truncation explicit. This isn't to say the code is currently incorrect but without silencing the warning it is hard to spot the erroneous cases. Signed-off-by: Ian Rogers --- include/linux/bitfield.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bitfield.h b/include/linux/bitfield.h index 63928f173223..cc5cfed041bb 100644 --- a/include/linux/bitfield.h +++ b/include/linux/bitfield.h @@ -176,7 +176,7 @@ static __always_inline __##type type##_encode_bits(base= v, base field) \ { \ if (__builtin_constant_p(v) && (v & ~field_mask(field))) \ __field_overflow(); \ - return to((v & field_mask(field)) * field_multiplier(field)); \ + return to((__##type)((v & field_mask(field)) * field_multiplier(field)));= \ } \ static __always_inline __##type type##_replace_bits(__##type old, \ base val, base field) \ --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:49:06 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 0D480265CA7 for ; Wed, 30 Apr 2025 17:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033347; cv=none; b=VRaUC40gQ/X0VT96py93PVUyfZDyO4idjwN1mXsYcNmg8yzAGmpYk5qzrWFKQteNywdCV6sbpjq9l9hiBnZa+AR44eeOkWma0MqeJASc9I38WNcc76aCAUwldNlVaomUiJ5DD37zQGNglZQ2Im4aMKcaq2Ly47Cw7pBlB06oStg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033347; c=relaxed/simple; bh=/nCqqKVIM3lCaTp25K5Y9r9lVgOCOQUHMpBywdgb4IQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qD4HR1LQ+6bqFO4Y6Xt7IVYI5WwupaeagimsyGkO4Uph4voo2z8ciyqVXrYXVPQFUn1kPSjBO5hCdrZN+R8Ly+NUxhSB25gzrxho+lt1u33QC2w8L308/XiEHsF0agQE+T4qfD0bn1vM7TxlEJ8izSmOSQptp0WsGCDZfZ4xRAI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vM8hCfsn; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vM8hCfsn" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2240a96112fso976265ad.2 for ; Wed, 30 Apr 2025 10:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746033345; x=1746638145; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=gN/a6V8QiIvdypmyI6y6Go6q2Ye8wXD3lVvCZhX5yNo=; b=vM8hCfsngFt/TKd0/thKvS5ZnmXWlk2O1sYawqKwrBiHW6pWAL+OnD13z11M1Pl748 tRRVVqNmBw8W/qsr/frtZo6xIWX6BKtvc567rNKJfDwPReGLm/Hzl5NcFm9BN5TlT/Gx dS1u+8qbkBYOdH9bKUEnvCvKzIx4hzAQlhD8YAFvyMytGwUjpboIWYp1V0BescE/KiJF jEs9q22upl3EoSmxhciTjBA5T18drI/Mgj3gb7tyZiJxcq6N/NFfqbW5vDCR9bZZAY7q lKBzKQ7FuVsmNOxueBUqZrbI+8IQr1yrb8y6TXTfTD30ZNSd2Zr6+BnrhUU3EaC++IjX YyPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746033345; x=1746638145; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gN/a6V8QiIvdypmyI6y6Go6q2Ye8wXD3lVvCZhX5yNo=; b=IDFzSkToZe/8O+UHI8TQu1HTIII2PA+GPheJRK7kpAZJ2mQWjAapgmuB/zXpcSUSwj +lCjjS1j2gg7438RaK9U4G+maZekWkrFVyPjRTtNqpDYKSb3VaH0/Z+NU8Dj8RCFD8CW W2FGouixOs5yvFDAHRSNBpZHiLbtzX/Kcjj627clQEvDZz+gT7Ytm4/e7Ed7oXZM0ZI+ kETmxwNXrNRsCRuhNILYFAwKNNJ53wedl1yzdBsjRDKRR6/mR9wybtCq5TTgSLIjIoI8 4UFbcHjmoO6fmJGGJnVD0Qsi3aXtPhqFsHAq8eQO97MlvYuAviwb0hJigdHJoFCl+NZd 60zg== X-Forwarded-Encrypted: i=1; AJvYcCUW/fFKZvjBkS8HdB9umDJ7YtumSDbjQo/ij/adflHYUnirBvSpJG85mP3DRskp8OLjGYQXeynrPTOIh4w=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2XuksiSLC4IWcDr92biTo1ry1MrBKn7zrQeJk8an5Mb6hE+TO VJ84Ds7VHVlM5BD/IhIUArvwncgkaAPYfaGcOjuS9l74WpRRtn2i68tm0U/AvoIMHcEOiPaecal wGVwm5g== X-Google-Smtp-Source: AGHT+IEyeKPexv1uh48dcAlUBWAzGseOfey8PKS/qHG5wARnrrceWevHm0oXIBRzRj/577/EUtzzAPcRJ5k6 X-Received: from pgam18.prod.google.com ([2002:a05:6a02:2b52:b0:af2:3385:de87]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:dac2:b0:21f:71b4:d2aa with SMTP id d9443c01a7336-22df5764482mr52271135ad.5.1746033343976; Wed, 30 Apr 2025 10:15:43 -0700 (PDT) Date: Wed, 30 Apr 2025 10:15:31 -0700 In-Reply-To: <20250430171534.132774-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430171534.132774-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430171534.132774-3-irogers@google.com> Subject: [PATCH v2 2/5] bitmap: Silence a clang -Wshorten-64-to-32 warning From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Ian Rogers , Adrian Hunter , Thomas Gleixner , Jakub Kicinski , Jacob Keller , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clang warning -Wshorten-64-to-32 can be useful to catch inadvertent truncation. In some instances this truncation can lead to changing the sign of a result, for example, truncation to return an int to fit a sort routine. Silence the warning by making the implicit truncation explicit. This isn't to say the code is currently incorrect but without silencing the warning it is hard to spot the erroneous cases. Signed-off-by: Ian Rogers --- include/linux/bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 595217b7a6e7..4395e0a618f4 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -442,7 +442,7 @@ static __always_inline unsigned int bitmap_weight(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) - return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); + return (int)hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); return __bitmap_weight(src, nbits); } =20 --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:49:06 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 3A5C4266580 for ; Wed, 30 Apr 2025 17:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033348; cv=none; b=nV3Iwyv7VJqyWx/deARD7TgfS9jGf3LjKjzw/GdwQJyM3rrpC/Phkn2PuvRtEymDV+N8Z97WQeIo6Pkf1xGbtWJtvMrvAAP4YIwhgv1GGU1thN/ut/2qHvtLSG4IAOP8pSIcttaoKA7ap/X1caam1CrclqV55sV1cw/EGVYTyRU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033348; c=relaxed/simple; bh=b5n+p0p3B+o0lVnDJxYolZguQtjCrIGPwnCN1vjSRAU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lTpsDlhOXPex3LBBp+BQ9WUr5le26j1GUZMSLvnNse8CRtiQ0B4VNZXch0sLmgUffFlFvZD2tyWw93W8DBDVY1sW95xdiuBc181wza7z+c+H7haLxAe69iFUy4LrfmuO0dLfNP8cJfcCAmpwS8JG7idIi2wPtaU7k4OLVWPPOFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vhd5Jn0V; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vhd5Jn0V" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-736cd27d51fso100504b3a.2 for ; Wed, 30 Apr 2025 10:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746033346; x=1746638146; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=hsdZl0+5u5nJRx5OChJBArmUD0oJ0ouyPxFpzVvIMfU=; b=vhd5Jn0Vm0NjAJurOaU6aQCoj+6yX8d/7ai3EpCOQLiv3AyhF1rc9xPQwSWGtAzl+O yrN/RltA41dkhz7N96pWuC3cnqvmPyQy0iBb8LwnxzCOIhPakHR466Tp7SEijmCLh6OU pTNdpkmsiRoHstoIrgwlyPhUtgtgoY55aHr2I+OWx3XAwzfkghHhj7pu2VnhyDulmFMm DyJByI0OaiDZ0LaDx/HMHqvju3PiuScSjLUFH+hX8Fmib0d/ibY6de/NTwyaLNVefSTU FjOSx6BOvsrJaXfH1dBs4dcdwpPirweJHY05o88OGdvT4qAQHzYck3tPjtN5NFnnxcrl HnBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746033346; x=1746638146; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hsdZl0+5u5nJRx5OChJBArmUD0oJ0ouyPxFpzVvIMfU=; b=k0GccNSBKKaSLVN278n2nPI8J/B2T3x6JaQC/gKKR4gKfDR3dE17xV/Ubt2i8iYQel /x8VDerazoLVEpcV3SV0qgo3+iFwB63nO43qy2N5J13O1nqlm5XqzI0CwKYBnjwnx6O6 hWAdxAkxJTMm+M8xE1NGjb9DUkuCUFEBgyJk0ocA0bgE027WJv1gOMPUiMiDV8GofZMg mjTBURJiSwNPUO5T/U0t9RFeoKrsilzW5wc+CWvURfjA8UxgtSaK9GfERPdJINTwVnOv tCpcZcmZy9WXUoBmIQX+Yt2i1vNX8evuDDnzkhOQad9ovbLSUjH2jnfzOEAL7j6Wxn94 GL6w== X-Forwarded-Encrypted: i=1; AJvYcCU8nsUOBuSn+7yX734W+UVdQZ5HXJgvtGumAPaSFA2WBKd2S/SGkPDBI8O5ZE2V8Xx00Ld2s5Fk3lo0cU0=@vger.kernel.org X-Gm-Message-State: AOJu0YwVn4ogHnOTZUFC51dN3HdQZWib9fhIcf6R90lG7gN4J7LsATwa Yy+HLometAbO7gOrLOLOndhdnD4xmc2fgHDG7+8+gz1yXgNG4Qb5voe8zP09GixX+tfQkPC2WCe /ogInkw== X-Google-Smtp-Source: AGHT+IH5YtRVCcmk/wqXASBTNnMEzZz9u8UpGehwrJivWav/O6WKRgJlaCeWX2JmolUzo5pIQPg8Xc06cId1 X-Received: from pgct16.prod.google.com ([2002:a05:6a02:5290:b0:af2:47b7:4d61]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9c97:b0:1f3:33bf:6640 with SMTP id adf61e73a8af0-20a87d4bda7mr6205234637.18.1746033346436; Wed, 30 Apr 2025 10:15:46 -0700 (PDT) Date: Wed, 30 Apr 2025 10:15:32 -0700 In-Reply-To: <20250430171534.132774-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430171534.132774-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430171534.132774-4-irogers@google.com> Subject: [PATCH v2 3/5] bitops: Silence a clang -Wshorten-64-to-32 warning From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Ian Rogers , Adrian Hunter , Thomas Gleixner , Jakub Kicinski , Jacob Keller , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clang warning -Wshorten-64-to-32 can be useful to catch inadvertent truncation. In some instances this truncation can lead to changing the sign of a result, for example, truncation to return an int to fit a sort routine. Silence the warning by making the implicit truncation explicit. This isn't to say the code is currently incorrect but without silencing the warning it is hard to spot the erroneous cases. Signed-off-by: Ian Rogers --- include/asm-generic/bitops/fls64.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitop= s/fls64.h index 866f2b2304ff..9ad3ff12f454 100644 --- a/include/asm-generic/bitops/fls64.h +++ b/include/asm-generic/bitops/fls64.h @@ -21,7 +21,7 @@ static __always_inline int fls64(__u64 x) __u32 h =3D x >> 32; if (h) return fls(h) + 32; - return fls(x); + return fls((__u32)x); } #elif BITS_PER_LONG =3D=3D 64 static __always_inline int fls64(__u64 x) --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:49:06 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 DFC6F267733 for ; Wed, 30 Apr 2025 17:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033351; cv=none; b=alKbB2UnUZ8gISMsDVoOrakcrZSoYeFyJ5UiKpDZnVaLhVwegF3ShxdYySog21mCNibCu0sEJ42OjUGLrfUTD04FZ+9yTlKsfzmxnQj4sgdLI33mAEhcluDJp5VS2XEBGGfqErBedOQWoS0mlRtaUXe9elxR252r93xHblGQuNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033351; c=relaxed/simple; bh=0giGEwbxakAUv76u37w4z4HZNA3HR28IEwGrKloZfbQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=rCXRS2zjque6A93ttQlaur8f2SwCKR9cYxIerABC7OEH28UH2zFjDyJUJ7kEjJwU2cCiv3PU8oFiEHphK1eAepdQbeJNLGECA11mjr2eKnXyVlQ3mwyq+88t+e0CfyjnJk9qlR39sPrm6gEL7Yj5MTmH/zyHfyt3BbvJyxKk8UM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=x/1N4HOn; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="x/1N4HOn" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3032f4eca83so94732a91.3 for ; Wed, 30 Apr 2025 10:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746033348; x=1746638148; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fOjn9I/CPl6hOGWikVl+PEhxM6YNnhs+3iDFhqJ7e1Q=; b=x/1N4HOnrjhrEuaC+/BduGHIgnd9t3WVz8bjvEjk5WlhqqB/SUKujBNRP82AaIoGh4 Ff7UaID+dL5ZEtcYQwTdhCtgL2upjme2iCZMjxTx6kaMSl+x3DxoYAphKIA5KBJt1lVM PpcUX9ZRuxu0cK9yAH9f+L3GLwIjjaVMQae3ly9RoVz+A8K/OQkw31erSbj2MhLTBx3q ySFOKrO9F4A0skALa85MX5nPUE1yNhPZCsySMZQlT3S5aM41jJ/jkf1Au9hX/KOrRGHp TbrESs3eF1v/rWS0Jleuw32xBUsyKX4DG/Uw0p5Ff/c7arWfU3TSviZThsFnchfh24Dk HXbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746033348; x=1746638148; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fOjn9I/CPl6hOGWikVl+PEhxM6YNnhs+3iDFhqJ7e1Q=; b=jwNCKz5mGDVCtQMSDiaUljBO4625WB9BfBxWo9JyWQzjlIWBmDFv2szJW5Hyc0QJ2+ V8OSptU+tyE371aZHgztFxE+0d1ujSbwkeMLaIhIcMpzaoKFq2JYl7RepaQGu/h2tDiX z4FgT3s7pd+tgbuj59/9rNt1Zrmf27A5NAK1Gww1TSQTwPOmjdkv+4GEunTW06zEapoA CC+PXDHQHWaUpgE2I9Q36vgCO5Et4lELLvo6Q+Vok5hzAk1HngVy3xINyG9DBOA8RBgb SvrJ8Y5zVFnGN+hLLoxC8SE4BAkTcfdzKgCkgsfB8gerh1tCb2ID6702P7awTUi8b95l +bsw== X-Forwarded-Encrypted: i=1; AJvYcCXYlSwAw3eifl6QZqUftP02+i7iKm5CbUnIA733BA+ng0g41s55Zy4BX8Epexl4jPWK/jZldmFQi3IFhAA=@vger.kernel.org X-Gm-Message-State: AOJu0YwVwT8XbGExqigxaFbqgkLmnr/oJOu8IqVVu3grnNOXl0JbFf9i UKznlhQdXUEUDher/muRILCpOiOdCQG6cHzDoMfixd5pAD8wHv+6kbXgxWB0sELUZLd/phH8B0/ gvCO2SQ== X-Google-Smtp-Source: AGHT+IHK97p3d4624e1GJoE8HKE9+msldMS/AyxZk3q0FqC3fhWjqcopfMGNBtO9wUuHcIl2vdgL7V5NAXJ3 X-Received: from pjbsm11.prod.google.com ([2002:a17:90b:2e4b:b0:309:f831:28e0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4984:b0:2ff:796b:4d05 with SMTP id 98e67ed59e1d1-30a343ffdcbmr5747063a91.11.1746033348290; Wed, 30 Apr 2025 10:15:48 -0700 (PDT) Date: Wed, 30 Apr 2025 10:15:33 -0700 In-Reply-To: <20250430171534.132774-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430171534.132774-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430171534.132774-5-irogers@google.com> Subject: [PATCH v2 4/5] math64: Silence a clang -Wshorten-64-to-32 warning From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Ian Rogers , Adrian Hunter , Thomas Gleixner , Jakub Kicinski , Jacob Keller , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clang warning -Wshorten-64-to-32 can be useful to catch inadvertent truncation. In some instances this truncation can lead to changing the sign of a result, for example, truncation to return an int to fit a sort routine. Silence the warning by making the implicit truncation explicit. This isn't to say the code is currently incorrect but without silencing the warning it is hard to spot the erroneous cases. Signed-off-by: Ian Rogers --- include/linux/math64.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/math64.h b/include/linux/math64.h index 6aaccc1626ab..f32fcb2a2331 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -179,7 +179,7 @@ static __always_inline u64 mul_u64_u64_shr(u64 a, u64 m= ul, unsigned int shift) #ifndef mul_u64_u32_shr static __always_inline u64 mul_u64_u32_shr(u64 a, u32 mul, unsigned int sh= ift) { - u32 ah =3D a >> 32, al =3D a; + u32 ah =3D a >> 32, al =3D (u32)a; u64 ret; =20 ret =3D mul_u32_u32(al, mul) >> shift; --=20 2.49.0.906.g1f30a19c02-goog From nobody Sat Feb 7 17:49:06 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 F3F1A2676FE for ; Wed, 30 Apr 2025 17:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033352; cv=none; b=QSGdBNNOdqPbJA4xM4ww7qlMpsCaZkfUEQ+K+Ov7vPKH/wZVgSu3vSMaymoJJ4Kv6sRDA7Ov7R7QDv1LqntSya165TuKEbBApIwFMyc98H//I1nZ1U/5N7oJCWWZ6rF+xHs6fLp+bIGKr96F3G93t5JwDZKwxWtMKA97obkkyys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746033352; c=relaxed/simple; bh=mAU7UddOSIuhHOgW0dcTHe2+YPpXYqGh56bzZQb4Iac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kUaaMb1+c82JZ+41RVGiai26jihkEVJ+s43kHtsddc9qanQQUkyxPmtpXXYUiUM7snfPqGYyk18MzLeQq69HcohKoAqYLlU3kUZkLvTwELS2/CtPbK73M6Vl07tbnno5Q5EmAJDA+yTu+S99bIPUO5xxeZLV0xWw08kZxnSw9mM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ppKhcx7S; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ppKhcx7S" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-224192ff68bso564575ad.1 for ; Wed, 30 Apr 2025 10:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1746033350; x=1746638150; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=WhBH53x+wqLHSip++JVbv92U64Pz0+iOyWwwIUecJ6E=; b=ppKhcx7Sp+v1WszhWVuLL3r8QHFclpXg3wjKDy2t8Cyjd/0KJLtuNIKJl4bfLDyK1l zUFXYO7YaxnuePFw6XuDR+83h0yBWVu3Ri4C78PqpZSI2MhOpP4xExeTQS0pCNTGydNp IjakmkXsXRD+++uNyKHzEAnQXFMJUtBruatI567QUrDTBdP5tj7/W88n/u3Z5L7w2QRD jDRUp4L7QEFSB5LE/NAtuLCGA7W68Qoytejy82A1exGfh4hOGPhYezqePKUJoX8CIR4B H53apjFSViNVMUugUyTRBTUov8AJV/1hFaHFdKM0bKvfbKU/HSUiBALg8iz2+3vOCV/8 lzxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746033350; x=1746638150; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WhBH53x+wqLHSip++JVbv92U64Pz0+iOyWwwIUecJ6E=; b=pVvnDT9ZjDXsOCk8vlehwE1lNANvIVDEwC2b2KRRELCynnQVLPDDfjhczCm3F/+YSo atS1eq9At3MtTF9ziLxR62b6kwUsEGVGYKKFOrFtaD7T3doNJwBWr8lwdlOag/bK8LiK zQKyvlzg6d5YY3eaAf9eBNjtndC4ybl/nRcyF5LodFSKm7kKwG+oyZX2CAw1+BhcOXsJ hRjdelOmClCXihMEb0BLn8z0K8WRQwJ801EeTg2nwCigaF5OAWlnmTRiuNGBVv3ZsrJA nYoNIpDpC/VmraafR9Cy23Hz+soIQXEDu11+5X2cIrlW0Fpux9efLovEd1P4ogbRj+i9 FZCw== X-Forwarded-Encrypted: i=1; AJvYcCViD5hnEsSco0lbN+e7vyIgYv3aFpLFzjpz9ErZTh3JcEvtfg7vFATw0HoV8AeYglqW/2fY/LfXRiMkb0k=@vger.kernel.org X-Gm-Message-State: AOJu0YzqcrqRrSZhcFp131v7y9bdBlbMOb+R/R/8sBACkapNhkGEuqv8 gXbmDNxvJtJ0JKQVlbMtQisgklWomEHIC2LCqCzXzQysFnWyn2shHZ5AN528P2fEBeOIaIaO4nN VbQsgAw== X-Google-Smtp-Source: AGHT+IEaapOgmoVRsKolxvo/uh0+Fje0GanC2UTPR9ZO79czz3tAeLom6ayGJKwoq/mQfddsskfR6kPqjVdO X-Received: from pgmm35.prod.google.com ([2002:a05:6a02:5523:b0:af2:50f0:bc79]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2d0:b0:223:325c:89f6 with SMTP id d9443c01a7336-22df34aa393mr68396565ad.10.1746033350412; Wed, 30 Apr 2025 10:15:50 -0700 (PDT) Date: Wed, 30 Apr 2025 10:15:34 -0700 In-Reply-To: <20250430171534.132774-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250430171534.132774-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.906.g1f30a19c02-goog Message-ID: <20250430171534.132774-6-irogers@google.com> Subject: [PATCH v2 5/5] hash.h: Silence a clang -Wshorten-64-to-32 warning From: Ian Rogers To: Yury Norov , Rasmus Villemoes , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Ian Rogers , Adrian Hunter , Thomas Gleixner , Jakub Kicinski , Jacob Keller , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The clang warning -Wshorten-64-to-32 can be useful to catch inadvertent truncation. In some instances this truncation can lead to changing the sign of a result, for example, truncation to return an int to fit a sort routine. Silence the warning by making the implicit truncation explicit. This isn't to say the code is currently incorrect but without silencing the warning it is hard to spot the erroneous cases. Signed-off-by: Ian Rogers --- include/linux/hash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/hash.h b/include/linux/hash.h index 38edaa08f862..ecc8296cb397 100644 --- a/include/linux/hash.h +++ b/include/linux/hash.h @@ -75,7 +75,7 @@ static __always_inline u32 hash_64_generic(u64 val, unsig= ned int bits) { #if BITS_PER_LONG =3D=3D 64 /* 64x64-bit multiply is efficient on all 64-bit processors */ - return val * GOLDEN_RATIO_64 >> (64 - bits); + return (u32)(val * GOLDEN_RATIO_64 >> (64 - bits)); #else /* Hash 64 bits using only 32x32-bit multiply. */ return hash_32((u32)val ^ __hash_32(val >> 32), bits); --=20 2.49.0.906.g1f30a19c02-goog