From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f51.google.com (mail-yx1-f51.google.com [74.125.224.51]) (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 2D29B2FE07E for ; Wed, 10 Dec 2025 18:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390438; cv=none; b=nd5lEsTJ6zn1VPHuS7/4mZxTO2VnZsjl1zHhiDR9LJ33yRHW2eS+4J2rYv/BbXMHbAcTfQSzXky4zlZGNwWuHYZD5VnNeQ+JeF4lEK5MG5oqPu4wCfUeN/0PlzSm5Mmp6AoVZa+KQAAjDP4ZkjbCLdZO2FoQVMlpADYQdBobeTY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390438; c=relaxed/simple; bh=Wtn11a9iEnf43J1eX/LK36QsqtWTGu7jL2VTy9DfQB0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Q95H66QKlVNTyvZHCsIqVlfBvGCYBuUg+LnsrZFXo69tsVDrkP4TNMVDnXt5TdZs9kpVEEHPif3TtTuaCf2NtWNqe85O4zr5y5JxsGbUNTO0qWVMfTMpPJwHiptmDQ+7DWGBcsS4oTtfdQw0+nC9GntJJwfNWt7thbbtW2m26aY= 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=VIkVp+Pj; arc=none smtp.client-ip=74.125.224.51 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="VIkVp+Pj" Received: by mail-yx1-f51.google.com with SMTP id 956f58d0204a3-64472121ad5so126757d50.0 for ; Wed, 10 Dec 2025 10:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765390436; x=1765995236; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=9+csY2ByO8RttGedAiCGy1ilPBafiqYG3jRO+0XdJFE=; b=VIkVp+Pji01mIAVj9Vr920CctEdTk9D94QfCltJuceXWyYj0dSXoFef2nguNmTDYN8 /Cezcl2RdJZ/30+7ja2DEKZXfqn0d2MWdofhX85HgD5wx5Zk3bWLQQTx+h6P5LONcs3H g4vIO3fwf6PHvgACRq/nOZ/4hkh8/y+wq3aw8RqTMTzPdlpKfu+3MdE2QSxEPZT0SEEk tLGET54KSmuTtSxwDN3n736pFf1fOLNwJjL93JofxGFd4NF7RYAtUBsYbHLV1Q174sKA 4llpefqOqc7q06vChIuL2HL1lUKhTztNPOlbgOfn4frUfbqhlkIHRFWZ3lo6hJpkv8HA eksg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765390436; x=1765995236; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9+csY2ByO8RttGedAiCGy1ilPBafiqYG3jRO+0XdJFE=; b=OZkGHpa42BnMt++9RSalg1z5IPpOunAENjptHaLjvRP/JHtFicRfG76T2wn3gd2JXU IMuoISTC6m9FO8u7BBH0E5d2qrRP+ASo/edrmMFKw3yozqFn8Pqq3j4/GzRVHm2Yscvy wW2Nj+VvR0k5VENVn2dOPF6hBRupvKKciLcS3+yyzjOce4B84ba54ScVrJkPuVVFn0IW CVi+cVJqjUL55Wb3GDu0thw91XRmrqqF2Wvpi/1VrHvXgWwXgSYyc22aDB1a5gbLsGls gTIJmDdq18+uj2/EOLUE4PeRikmBsVIjjf3W4WTr0XO7djua2nlgVmJVz8ZgjGNujRlH SAwQ== X-Forwarded-Encrypted: i=1; AJvYcCXS2Do0/OxeLpebZVGivjnHhBn+tCMwz1ewelm9RpHdE+XxU83HMK4aWn3zINLZy8xJ1gUoASNtVBhFyyg=@vger.kernel.org X-Gm-Message-State: AOJu0YzR5QXnIdCLJIcGlVcwL0jzv7p575jwOZKF+znBAHhGdCLhEQxo uE5w4E9ZXMDd6BXSVJt35kYhI2axRyGpV0CrEjWjGbvExJmT+y8/gcgf X-Gm-Gg: AY/fxX5pW0IYX//28uvRV6lX9zvcT0aFn2+CYulEkD0cHyC2S6sSe+WVS0ovDv4wzfR OZ9cAOAzjDIe9Czv1tXyWgr09OabpGLEFrF9OXGWx3NiejW9ixyk8xoo0YeJflA2D8zMi8d+a1m bKH4e3orMoONNySHgOVA+aoxBIJzhTiuS04QZ/IowsPvv9nR5tqOsLlNqDArhEzlYuiYAjKRTZY 9gD9UQm8JDlwAGfPvSWVwoTAqBYUrzUq+KwA49LmDJvY80HGAp/s0q2XLY1bSyQe2NHExaY51/O ARk1kJQHlJhxY41nSqzwD7Yy01xlgj0/P+kvnLZvZXwg1RwyMOKhJJVst9XowsOw6bYFfJblhuH j2q+C0N7fmwgsG8IzvaDbsaRKaSQtundaNpHOZJJYQCX8xxxvtK7Rk3wTqGXIjR5Iou3MKJ37gE 5Nz059Iew= X-Google-Smtp-Source: AGHT+IFNQ+uuN8jF42ubdJrRT5xIjGkXIwoFJdbKXMVHKukzaq26xU+wZQxTC29eXTthtXTon21EyQ== X-Received: by 2002:a05:690e:1287:b0:63f:b4ee:792c with SMTP id 956f58d0204a3-6446e9116famr2757099d50.19.1765390436050; Wed, 10 Dec 2025 10:13:56 -0800 (PST) Received: from localhost ([2601:346:0:79bd:74ed:2211:108a:e77a]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64477dab6f4sm149212d50.12.2025.12.10.10.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Dec 2025 10:13:55 -0800 (PST) Date: Wed, 10 Dec 2025 13:13:55 -0500 From: Yury Norov To: David Laight Cc: Mika Westerberg , Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Geert Uytterhoeven , Alexandre Belloni , Jonathan Cameron , Crt Mori , Richard Genoud , Andy Shevchenko , Luo Jie , Peter Zijlstra , Jakub Kicinski , netdev@vger.kernel.org, "David S . Miller" , Simon Horman , Andreas Noever , Yehezkel Bernat , Nicolas Frattaroli Subject: Re: [PATCH 2/9] thunderblot: Don't pass a bitfield to FIELD_GET Message-ID: References: <20251209100313.2867-1-david.laight.linux@gmail.com> <20251209100313.2867-3-david.laight.linux@gmail.com> <20251210055617.GD2275908@black.igk.intel.com> <20251210093403.5b0f440e@pumpkin> <20251210094102.GF2275908@black.igk.intel.com> <20251210101842.022d1a99@pumpkin> 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-Disposition: inline In-Reply-To: <20251210101842.022d1a99@pumpkin> On Wed, Dec 10, 2025 at 10:18:42AM +0000, David Laight wrote: > On Wed, 10 Dec 2025 10:41:02 +0100 > Mika Westerberg wrote: > > > On Wed, Dec 10, 2025 at 09:34:03AM +0000, David Laight wrote: > > > On Wed, 10 Dec 2025 06:56:17 +0100 > > > Mika Westerberg wrote: > > > > > > > $subject has typo: thunderblot -> thunderbolt ;-) > > > > > > > > On Tue, Dec 09, 2025 at 10:03:06AM +0000, david.laight.linux@gmail.com wrote: > > > > > From: David Laight > > > > > > > > > > FIELD_GET needs to use __auto_type to get the value of the 'reg' > > > > > parameter, this can't be used with bifields. > > > > > > > > > > FIELD_GET also want to verify the size of 'reg' so can't add zero > > > > > to force the type to int. > > > > > > > > > > So add a zero here. > > > > > > > > > > Signed-off-by: David Laight > > > > > --- > > > > > drivers/thunderbolt/tb.h | 2 +- > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h > > > > > index e96474f17067..7ca2b5a0f01e 100644 > > > > > --- a/drivers/thunderbolt/tb.h > > > > > +++ b/drivers/thunderbolt/tb.h > > > > > @@ -1307,7 +1307,7 @@ static inline struct tb_retimer *tb_to_retimer(struct device *dev) > > > > > */ > > > > > static inline unsigned int usb4_switch_version(const struct tb_switch *sw) > > > > > { > > > > > - return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version); > > > > > + return FIELD_GET(USB4_VERSION_MAJOR_MASK, sw->config.thunderbolt_version + 0); > > > > > > > > Can't this use a cast instead? If not then can you also add a comment here > > > > because next someone will send a patch "fixing" the unnecessary addition. > > > > > > A cast can do other (possibly incorrect) conversions, adding zero is never going > > > to so any 'damage' - even if it looks a bit odd. > > > > > > Actually, I suspect the best thing here is to delete USB4_VERSION_MAJOR_MASK and > > > just do: > > > /* The major version is in the top 3 bits */ > > > return sw->config.thunderbolt_version > 5; > > > > You mean > > > > return sw->config.thunderbolt_version >> 5; > > > > ? > > > > Yes that works but I prefer then: > > > > return sw->config.thunderbolt_version >> USB4_VERSION_MAJOR_SHIFT; > > I've put that in for the next version (without the comment line). FIELD_GET() is here exactly to let people to not opencode this error-prone bit manipulation. So, let's continue using it. David, can you explain in details why this code needs to be fixed? Why and when typecast wouldn't work so that you have to use an ugly '+0' hack, or even drop the FIELD_GET(). My current understanding is that the existing FIELD_GET() implementation works well with any data types, including bitfields, and what you suggested in this series - does not. If it's correct, I don't think that switching to your version is well-justified. Thanks, Yury