Skip to content

Commit

Permalink
net: dsa: check out-of-range ageing time value
Browse files Browse the repository at this point in the history
If a DSA switch driver cannot program an ageing time value due to it
being out-of-range, switchdev will raise a stack trace before failing.

To fix this, add ageing_time_min and ageing_time_max members to the
dsa_switch in order for the switch drivers to optionally specify their
supported ageing time limits.

The DSA core will now check for provided ageing time limits and return
-ERANGE from the switchdev prepare phase if the value is out-of-range.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vivien Didelot authored and David S. Miller committed Mar 15, 2017
1 parent e893de1 commit 0f3da6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ struct dsa_switch {
u32 phys_mii_mask;
struct mii_bus *slave_mii_bus;

/* Ageing Time limits in msecs */
unsigned int ageing_time_min;
unsigned int ageing_time_max;

/* Dynamically allocated ports, keep last */
size_t num_ports;
struct dsa_port ports[];
Expand Down
8 changes: 6 additions & 2 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,13 @@ static int dsa_slave_ageing_time(struct net_device *dev,
unsigned long ageing_jiffies = clock_t_to_jiffies(attr->u.ageing_time);
unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies);

/* bridge skips -EOPNOTSUPP, so skip the prepare phase */
if (switchdev_trans_ph_prepare(trans))
if (switchdev_trans_ph_prepare(trans)) {
if (ds->ageing_time_min && ageing_time < ds->ageing_time_min)
return -ERANGE;
if (ds->ageing_time_max && ageing_time > ds->ageing_time_max)
return -ERANGE;
return 0;
}

/* Keep the fastest ageing time in case of multiple bridges */
p->dp->ageing_time = ageing_time;
Expand Down

0 comments on commit 0f3da6a

Please sign in to comment.