Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2 net-next 06/14] net: enetc: simplify enetc4_set_port_speed()
Date: Fri, 03 Jul 2026 03:27:02 +0000	[thread overview]
Message-ID: <20260703032702.E6A831F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260702025714.456233-7-wei.fang@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removal of the switch statement allows SPEED_UNKNOWN to be programmed as an invalid hardware state.
--

commit 923303ff32884703a5eb3f948098684f15149ba1
Author: Wei Fang <wei.fang@nxp.com>

net: enetc: simplify enetc4_set_port_speed()

This commit simplifies enetc4_set_port_speed() by removing a switch
statement, assuming phylink only passes valid speed values. It also
updates PCR_PSPEED_VAL() to use FIELD_PREP() instead of an open-coded
shift.

> diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
> index 6a8f2ed56017c..dea1fd0b81758 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
> +++ b/drivers/net/ethernet/freescale/enetc/enetc4_hw.h
> @@ -148,7 +148,7 @@
>  #define  PCR_L2DOSE			BIT(4)
>  #define  PCR_TIMER_CS			BIT(8)
>  #define  PCR_PSPEED			GENMASK(29, 16)
> -#define  PCR_PSPEED_VAL(speed)		(((speed) / 10 - 1) << 16)
> +#define  PCR_PSPEED_VAL(s)		FIELD_PREP(PCR_PSPEED, ((s) / 10 - 1))

[Severity: High]
Does this safely handle negative values like SPEED_UNKNOWN?

If SPEED_UNKNOWN (-1) is passed here, the expression ((s) / 10 - 1)
evaluates to -1. FIELD_PREP then casts this to an unsigned type and masks
it against PCR_PSPEED, filling all 14 bits with 1s (0x3FFF).

>  
>  /* Port MAC address register 0/1 */
>  #define ENETC4_PMAR0			0x4020
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
> index b966637572a7a..db7bad2c3cbde 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
[ ... ]
> -	switch (speed) {
> -	case SPEED_100:
> -	case SPEED_1000:
> -	case SPEED_2500:
> -	case SPEED_10000:
> -		val |= (PCR_PSPEED & PCR_PSPEED_VAL(speed));
> -		break;
> -	case SPEED_10:
> -	default:
> -		val |= (PCR_PSPEED & PCR_PSPEED_VAL(SPEED_10));
> -	}
> -
> -	priv->speed = speed;
> +	val = enetc_port_rd(&priv->si->hw, ENETC4_PCR) & (~PCR_PSPEED);
> +	val |= PCR_PSPEED_VAL(speed);

[Severity: High]
The commit message states: "Since phylink only passes valid speed values
to mac_link_up, the switch statement with its default fallback to SPEED_10
is unnecessary."

Is this assumption accurate?

In the kernel phylib/phylink implementation, if a PHY establishes link before
autonegotiation completes (or if an out-of-band PCS status hasn't fully
resolved the speed), genphy_read_status() can leave phydev->speed as
SPEED_UNKNOWN (-1) while phydev->link is 1.

Phylink then propagates this state via phylink_resolve() and calls
mac_link_up() with SPEED_UNKNOWN.

Without the switch statement's default case, won't this write the 0x3FFF
garbage value generated by PCR_PSPEED_VAL() to the MAC speed configuration
register (ENETC4_PCR) and cause undefined hardware behavior?

>  	enetc_port_wr(&priv->si->hw, ENETC4_PCR, val);
> +	priv->speed = speed;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702025714.456233-1-wei.fang@oss.nxp.com?part=6

  parent reply	other threads:[~2026-07-03  3:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  2:57 [PATCH v2 net-next 00/14] net: enetc: cleanups and improvements wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 01/14] net: enetc: extract common helpers for MAC promiscuous mode setting wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 02/14] net: enetc: extract common helpers for MAC hash filter configuration wei.fang
2026-07-03  3:27   ` sashiko-bot
2026-07-03  7:02     ` Wei Fang (OSS)
2026-07-02  2:57 ` [PATCH v2 net-next 03/14] net: enetc: convert ndo_set_rx_mode() to ndo_set_rx_mode_async() wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 04/14] net: enetc: improve MAFT entry management with bitmap tracking wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 05/14] net: enetc: use PCI device name for debugfs directory wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 06/14] net: enetc: simplify enetc4_set_port_speed() wei.fang
2026-07-02 17:32   ` Maxime Chevallier
2026-07-03  3:27   ` sashiko-bot [this message]
2026-07-02  2:57 ` [PATCH v2 net-next 07/14] net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC wei.fang
2026-07-02 17:30   ` Maxime Chevallier
2026-07-03  3:27   ` sashiko-bot
2026-07-02  2:57 ` [PATCH v2 net-next 08/14] net: enetc: remove invalid code from enetc4_pl_mac_link_up() wei.fang
2026-07-02 17:35   ` Maxime Chevallier
2026-07-02  2:57 ` [PATCH v2 net-next 09/14] net: enetc: remove enetc4_set_default_si_vlan_promisc() wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 10/14] net: enetc: refactor SI VLAN promiscuous mode configuration wei.fang
2026-07-03  3:27   ` sashiko-bot
2026-07-02  2:57 ` [PATCH v2 net-next 11/14] net: enetc: move enetc_set_si_vlan_promisc() to enetc_pf_common.c wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 12/14] net: enetc: remove redundant num_vsi field from enetc_port_caps wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver wei.fang
2026-07-03  3:27   ` sashiko-bot
2026-07-02  2:57 ` [PATCH v2 net-next 14/14] net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation wei.fang
2026-07-03  3:27   ` sashiko-bot

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=20260703032702.E6A831F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wei.fang@oss.nxp.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