Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

stmmac: Validate hwtstamp_config completely before applying it

stmmac_hwtstamp_ioctl() should validate all fields of hwtstamp_config
before making any changes. Currently it sets the TX configuration
before validating the rx_filter field.

Compile-tested only.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ben Hutchings and committed by
David S. Miller
5f3da328 810abe9b

+3 -9
+3 -9
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
··· 435 435 if (config.flags) 436 436 return -EINVAL; 437 437 438 - switch (config.tx_type) { 439 - case HWTSTAMP_TX_OFF: 440 - priv->hwts_tx_en = 0; 441 - break; 442 - case HWTSTAMP_TX_ON: 443 - priv->hwts_tx_en = 1; 444 - break; 445 - default: 438 + if (config.tx_type != HWTSTAMP_TX_OFF && 439 + config.tx_type != HWTSTAMP_TX_ON) 446 440 return -ERANGE; 447 - } 448 441 449 442 if (priv->adv_ts) { 450 443 switch (config.rx_filter) { ··· 569 576 } 570 577 } 571 578 priv->hwts_rx_en = ((config.rx_filter == HWTSTAMP_FILTER_NONE) ? 0 : 1); 579 + priv->hwts_tx_en = config.tx_type == HWTSTAMP_TX_ON; 572 580 573 581 if (!priv->hwts_tx_en && !priv->hwts_rx_en) 574 582 priv->hw->ptp->config_hw_tstamping(priv->ioaddr, 0);