From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (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 3E54730AD05 for ; Wed, 10 Dec 2025 18:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390438; cv=none; b=kNyc7j4HNT1Fe2ELBoi34dubjngSL13w7jZ9bcemO0Yply2qNBw0lnrzueDWwoYpd9k6mB2SoxJtQWicvPI1a+yVgnafAE4M46zHpJEN7BaAGxl+MOv/fj5SxbJZVR0Abt38mdrg1On3/wtOdhqfKas4FIKyU5OOJpID1E/1yKU= 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.52 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-f52.google.com with SMTP id 956f58d0204a3-64472121ad5so126756d50.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=Jm2ovNIht4x8fahDGU3Edj+f9WgiDCkUaZ6/5WMzmTar7b3RVwrtjUuCddZCaPmLbg ptH0kYw0XWCJtP1ipCIoyV9FEfWbjSE3zGJb45WtkhTl7jRhW7izuoPySpwoP1QIHZqM tyWtHG8Q0PYfruKICM0bCMfA/arZsHUdCkRzxKaB4kFHJlBituyd3HBDZ7wZAhJJ3Kco F/bG/jOssfrI4I4UNDuU8sj8cAyeYqipSR7qJKct5C19xUkDRSL2YaPRKM6sPCs3w3DF cMXCBwwXHF9lQ+FQQmQa0uMJoJ7et7T6jwhUWkDaVCpGfLvjXOG0VAGBRiXbDhFyZJSx FyvQ== X-Forwarded-Encrypted: i=1; AJvYcCWGAvRbjVX4Te309XDfFlKHfHYrPiLRSgzUYkH7FMB/RQ1XZ0t3ARo2Na+7NlHVeflMXeSweWo/cFs=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2G7sV99IJPr1Pr75zBBD6ZS3Bgn4F4UR0E+Ui8gB1H+lNURPo ZvF0QdQaTGUKp4gC/qTNJ/R+OOBB7VpT/MmcbB0CTm+BMKnObwXrtsXP X-Gm-Gg: AY/fxX47P6fKWUy2Sr02MFYD3NgLXur8xqVykrllfilnZ8BUhDmOMdwOX/n0DxHlKhN duL3Y8dWTtVF/EkTij3BmBfbQGNZXC4NhxNQ2EUsPsyuKi5yrroVxQnjqkOExcTkJ95nRxiymwB YbknmeGhQzBeVUifrrPMiVwAng9XRERecdPs8yuVPPDTaPkSK1ApXPATfn9eBH0LulZuTG51TKl UXOgDQVMv2z1/lwyYDXPa9y5etv+6Im3E1nv6J97zWrWnTNm9SC8C4neF8RTjPJ3DdX08GZ3oSt tkEBXtzYc9KK40oUdnaRVdNKDLXnLG9rQ6y6HEhychkNIWsGbzGIfUAhCNx0xMwKYPUxyPI8e5o UYhzq1sgKRw3Dwxi0YfuOL01xCHhoXzRZhWxi+ReKqdrHRcVIuq91uMXRWY8wsxgixC1Qu9vDm1 b2dySAcbI= 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-usb@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