mirror of
https://github.com/torvalds/linux.git
synced 2026-06-05 04:56:13 +02:00
net: dsa: sja1105: reject other RX filters than HWTSTAMP_FILTER_PTP_V2_L2_EVENT
This is all that we can support timestamping, so we shouldn't accept
anything else. Also see sja1105_hwtstamp_get().
To avoid erroring out in an inconsistent state, operate on copies of
priv->hwts_rx_en and priv->hwts_tx_en, and write them back when nothing
else can fail anymore.
Fixes: a602afd200 ("net: dsa: sja1105: Expose PTP timestamping ioctls to userspace")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250318115716.2124395-3-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
00eb88752f
commit
b6a177b559
|
|
@ -61,17 +61,21 @@ enum sja1105_ptp_clk_mode {
|
|||
int sja1105_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr)
|
||||
{
|
||||
struct sja1105_private *priv = ds->priv;
|
||||
unsigned long hwts_tx_en, hwts_rx_en;
|
||||
struct hwtstamp_config config;
|
||||
|
||||
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
|
||||
return -EFAULT;
|
||||
|
||||
hwts_tx_en = priv->hwts_tx_en;
|
||||
hwts_rx_en = priv->hwts_rx_en;
|
||||
|
||||
switch (config.tx_type) {
|
||||
case HWTSTAMP_TX_OFF:
|
||||
priv->hwts_tx_en &= ~BIT(port);
|
||||
hwts_tx_en &= ~BIT(port);
|
||||
break;
|
||||
case HWTSTAMP_TX_ON:
|
||||
priv->hwts_tx_en |= BIT(port);
|
||||
hwts_tx_en |= BIT(port);
|
||||
break;
|
||||
default:
|
||||
return -ERANGE;
|
||||
|
|
@ -79,15 +83,21 @@ int sja1105_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr)
|
|||
|
||||
switch (config.rx_filter) {
|
||||
case HWTSTAMP_FILTER_NONE:
|
||||
priv->hwts_rx_en &= ~BIT(port);
|
||||
hwts_rx_en &= ~BIT(port);
|
||||
break;
|
||||
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
|
||||
hwts_rx_en |= BIT(port);
|
||||
break;
|
||||
default:
|
||||
priv->hwts_rx_en |= BIT(port);
|
||||
break;
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &config, sizeof(config)))
|
||||
return -EFAULT;
|
||||
|
||||
priv->hwts_tx_en = hwts_tx_en;
|
||||
priv->hwts_rx_en = hwts_rx_en;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user