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

net: dsa: don't call ptp_classify_raw() if switch doesn't provide RX timestamping

ptp_classify_raw() is not exactly cheap, since it invokes a BPF program
for every skb in the receive path. For switches which do not provide
ds->ops->port_rxtstamp(), running ptp_classify_raw() provides precisely
nothing, so check for the presence of the function pointer first, since
that is much cheaper.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de>
Link: https://lore.kernel.org/r/20221209175840.390707-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Vladimir Oltean and committed by
Jakub Kicinski
8f18655c cd2aafa2

+4 -4
+4 -4
net/dsa/tag.c
··· 33 33 struct dsa_switch *ds = p->dp->ds; 34 34 unsigned int type; 35 35 36 + if (!ds->ops->port_rxtstamp) 37 + return false; 38 + 36 39 if (skb_headroom(skb) < ETH_HLEN) 37 40 return false; 38 41 ··· 48 45 if (type == PTP_CLASS_NONE) 49 46 return false; 50 47 51 - if (likely(ds->ops->port_rxtstamp)) 52 - return ds->ops->port_rxtstamp(ds, p->dp->index, skb, type); 53 - 54 - return false; 48 + return ds->ops->port_rxtstamp(ds, p->dp->index, skb, type); 55 49 } 56 50 57 51 static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev,