All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marek Behún" <marek.behun@nic.cz>
To: Nishanth Menon <nm@ti.com>
Cc: Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Tom Rini <trini@konsulko.com>,
	Siddharth Vadapalli <s-vadapalli@ti.com>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Michal Simek <michal.simek@amd.com>,
	Ramon Fried <rfried.dev@gmail.com>,
	u-boot@lists.denx.de
Subject: Re: [PATCH 1/2] net: phy: Make phy_interface_is_sgmii a switch statement
Date: Thu, 13 Apr 2023 23:22:21 +0200	[thread overview]
Message-ID: <20230413212221.3vt2ju7rsxtdaas3@kandell> (raw)
In-Reply-To: <20230413190234.mzmhscso6hpmh64r@jiffy>

On Thu, Apr 13, 2023 at 02:02:34PM -0500, Nishanth Menon wrote:
> On 20:56-20230413, Marek Behún wrote:
> > On Thu, Apr 13, 2023 at 01:07:12PM -0500, Nishanth Menon wrote:
> > > Recent commit 75d28899e3e9 ("net: phy: Synchronize PHY interface modes
> > > with Linux") reordered the enum definitions. This caused the range of
> > > enums that this api was checking to go bad.
> > > 
> > > While it is possible for the phy drivers to practically use the enum's
> > > directly, drivers such as dp83867 use this helper to manage the
> > > configuration of the phy correctly.
> > > 
> > > Reported-by: Tom Rini <trini@konsulko.com>
> > > Signed-off-by: Nishanth Menon <nm@ti.com>
> > > ---
> > >  include/phy.h | 12 ++++++++++--
> > >  1 file changed, 10 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/include/phy.h b/include/phy.h
> > > index a837fed72352..1c4dc23bc5ba 100644
> > > --- a/include/phy.h
> > > +++ b/include/phy.h
> > > @@ -373,8 +373,16 @@ static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
> > >   */
> > >  static inline bool phy_interface_is_sgmii(struct phy_device *phydev)
> > >  {
> > > -	return phydev->interface >= PHY_INTERFACE_MODE_SGMII &&
> > > -		phydev->interface <= PHY_INTERFACE_MODE_QSGMII;
> > > +	switch (phydev->interface) {
> > > +	case PHY_INTERFACE_MODE_SGMII:
> > > +	case PHY_INTERFACE_MODE_QUSGMII:
> > > +	case PHY_INTERFACE_MODE_USXGMII:
> > > +	case PHY_INTERFACE_MODE_QSGMII:
> > > +		return 1;
> > > +	default:
> > > +		fallthrough;
> > 
> > Why not just put the return 0; statement here instead of fallthrough and
> > drop it from after the switch statement?
> 
> Just dropping the default also will work, though it does leave something
> un-handled. handling the default on the other hand allows for additional
> code (meh?) to be added in default.. But really what? I'd rather drop
> the default and fall through to save on a couple of lines.. if that
> is'nt creating confusion..

You can't drop the default if you use a switch statement and not
enumerating all enumerator entries.

So you either have to use

	switch (x) {
	case A:
		return 1;
	case B:
		return 2;
	default:
		return 3;
	}

or

	switch (x) {
	case A:
		return 1;
	case B:
		return 2;
	default:
		break; /* or fallthourgh */
	}
	return 3;

The first one is shorter one line. It is also used in this way already.

IMO it makes more sense.

But keep in mind, this is just a nit-pick. I don't actually care that
much. I just think it makes more sense this way. If all possibilities
are handled by return statements inside the switch, you don't need to
have another return in top level of the function.

Look for example at Linux' include/linux/phy.h function phy_modes():
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/phy.h?h=v6.3-rc6#n216

Marek

> 
> > > +	}
> > > +	return 0;
> > >  }
> 
> -- 
> Regards,
> Nishanth Menon
> Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D

  reply	other threads:[~2023-04-13 21:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 18:07 [PATCH 0/2] net: phy: Make phy_interface_is_sgmii|rgmii a switch statement Nishanth Menon
2023-04-13 18:07 ` [PATCH 1/2] net: phy: Make phy_interface_is_sgmii " Nishanth Menon
2023-04-13 18:56   ` Marek Behún
2023-04-13 19:02     ` Nishanth Menon
2023-04-13 21:22       ` Marek Behún [this message]
2023-04-13 22:51         ` Nishanth Menon
2023-04-13 18:07 ` [PATCH 2/2] net: phy: Make phy_interface_is_rgmii " Nishanth Menon
2023-04-25 19:13   ` Ramon Fried
2023-04-13 18:08 ` [PATCH 0/2] net: phy: Make phy_interface_is_sgmii|rgmii " Nishanth Menon

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=20230413212221.3vt2ju7rsxtdaas3@kandell \
    --to=marek.behun@nic.cz \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=michal.simek@amd.com \
    --cc=nm@ti.com \
    --cc=rfried.dev@gmail.com \
    --cc=s-vadapalli@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.