The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Daniel Golle <daniel@makrotopia.org>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Andrew Lunn <andrew@lunn.ch>, Xu Liang <lxu@maxlinear.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v3 1/3] net: phy: mxl-86110: add basic support for led_brightness_set op
Date: Fri, 22 Aug 2025 03:06:04 +0100	[thread overview]
Message-ID: <aKfQjLVRtZKo1rYZ@pidgin.makrotopia.org> (raw)
In-Reply-To: <20250821173620.367ce05c@kernel.org>

On Thu, Aug 21, 2025 at 05:36:20PM -0700, Jakub Kicinski wrote:
> On Wed, 20 Aug 2025 14:34:07 +0100 Daniel Golle wrote:
> > > > +	if (index >= MXL86110_MAX_LEDS)
> > > > +		return -EINVAL;
> > > > +
> > > > +	/* force manual control */
> > > > +	set = MXL86110_COM_EXT_LED_GEN_CFG_LFE(index);
> > > > +	/* clear previous force mode */
> > > > +	mask = MXL86110_COM_EXT_LED_GEN_CFG_LFM(index);
> > > > +
> > > > +	/* force LED to be permanently on */
> > > > +	if (value != LED_OFF)
> > > > +		set |= MXL86110_COM_EXT_LED_GEN_CFG_LFME(index);  
> > > 
> > > That is particularly complex. We know index is a u8, so why not
> > > GENMASK_U8(1 + 3 * index, 3 * index)? But set is a u16, so
> > > GENMASK_U16() would also be valid.  
> > 
> > I chose this construct to avoid reusing the macro parameter as gcc would
> > rightously complain about that potentially having unexpected side-effects.
> > 
> > Eg.
> > 
> > #define FOO(a) ((a)+(a))
> > 
> > Now with var=10, when calling FOO(var++) the result will be 21 and
> > var will be equal to 12, which isn't intuitive without seeing the
> > macro definition.
> > 
> > Also using GENMASK_TYPE would not avoid the problem of macro
> > parameter reuse.
> > 
> > However, I agree that the macro itself is also weirdly complex and
> > confusing (but at the same time also very common, a quick grep reveals
> > hundreds of occurances of that pattern in Linux sources), so maybe we
> > should introduce some generic helpers for this (quite common) use-case?
> > I can do that, but I certainly can't take care of migrating all the
> > existing uses of this pattern to switch to the new helper.
> 
> IMHO this is one of the cases where the code would be far clearer
> without he macros..
> 
> #define MXL86110_COM_EXT_LED_GEN_CFG			0xA00B
> # define MXL86110_COM_EXT_LED_GEN_CFG_LFME(x)		(1 << (3 * (x)))
> # define MXL86110_COM_EXT_LED_GEN_CFG_LFE(x)		(2 << (3 * (x)))
> # define MXL86110_COM_EXT_LED_GEN_CFG_MASK(x)		(3 << (3 * (x)))
> 
> Right?

I agree. If everyone is fine with using numbers and bitshift instead of
GENMASK(...) then I'd also prefer it in this case.


      reply	other threads:[~2025-08-22  2:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 12:11 [PATCH net-next v3 1/3] net: phy: mxl-86110: add basic support for led_brightness_set op Daniel Golle
2025-08-20 12:11 ` [PATCH net-next v3 2/3] net: phy: mxl-86110: fix indentation in struct phy_driver Daniel Golle
2025-08-20 12:36   ` Andrew Lunn
2025-08-20 12:12 ` [PATCH net-next v3 3/3] net: phy: mxl-86110: add basic support for MxL86111 PHY Daniel Golle
2025-08-20 12:40   ` Andrew Lunn
2025-08-20 12:34 ` [PATCH net-next v3 1/3] net: phy: mxl-86110: add basic support for led_brightness_set op Andrew Lunn
2025-08-20 13:34   ` Daniel Golle
2025-08-22  0:36     ` Jakub Kicinski
2025-08-22  2:06       ` Daniel Golle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aKfQjLVRtZKo1rYZ@pidgin.makrotopia.org \
    --to=daniel@makrotopia.org \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lxu@maxlinear.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox