can: export export slcan_ethtool_ops and remove setter functions
Subsystems (2)
cover can: export export slcan_ethtool_ops and remove setter functions
The c_can, flexcan and slcan use a setter function to populate net_device::ethtool_ops. Using a setter here add one additional function call and add some small bloat in the object file. Exporting the structure allow to remove this setter.
The mcp251xfd uses a similar pattern except that it does some additional initialization. As such, this driver is left untouched.
* Statistics *
For the slcan driver, this patch reduces the object file by 14 bytes (details in the first patch). Although we did not conduct a benchmark for the other drivers but we expect the exact same figures.
Vincent Mailhol (3):
can: slcan: export slcan_ethtool_ops and remove
slcan_set_ethtool_ops()
can: c_can: export c_can_ethtool_ops and remove
c_can_set_ethtool_ops()
can: flexcan: export flexcan_ethtool_ops and remove
flexcan_set_ethtool_ops()
drivers/net/can/c_can/c_can.h | 2 +- drivers/net/can/c_can/c_can_ethtool.c | 7 +------ drivers/net/can/c_can/c_can_main.c | 2 +- drivers/net/can/flexcan/flexcan-core.c | 2 +- drivers/net/can/flexcan/flexcan-ethtool.c | 7 +------ drivers/net/can/flexcan/flexcan.h | 2 +- drivers/net/can/slcan/slcan-core.c | 2 +- drivers/net/can/slcan/slcan-ethtool.c | 7 +------ drivers/net/can/slcan/slcan.h | 3 ++- 9 files changed, 10 insertions(+), 24 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/3 can: slcan: export slcan_ethtool_ops and remove slcan_set_ethtool_ops()
The function slcan_set_ethtool_ops() does one thing: populate net_device::ethtool_ops. Instead, it is possible to directly assign this field and remove one function call and slightly reduce the object size. To do so, export slcan_ethtool_ops so it becomes visible to sclan-core.c.
This patch reduces the footprint by 14 bytes:
| $ ./scripts/bloat-o-meter drivers/net/can/slcan/slcan.{old,new}.o
| drivers/net/can/slcan/slcan.o
| add/remove: 0/1 grow/shrink: 1/0 up/down: 15/-29 (-14)
| Function old new delta
| slcan_open 1010 1025 +15
| slcan_set_ethtool_ops 29 - -29
| Total: Before=11115, After=11101, chg -0.13%--- drivers/net/can/slcan/slcan-core.c | 2 +- drivers/net/can/slcan/slcan-ethtool.c | 7 +------ drivers/net/can/slcan/slcan.h | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-)
drivers/net/can/slcan/slcan-core.c +1 -1
@@ -866,8 +866,8 @@ static struct slcan *slc_alloc(void)snprintf (dev->name,sizeof (dev->name),"slcan%d" , i); dev->netdev_ops = &slc_netdev_ops; + dev->ethtool_ops = &slcan_ethtool_ops; dev->base_addr = i; -slcan_set_ethtool_ops (dev); sl =netdev_priv (dev);/* Initialize channel control data */
drivers/net/can/slcan/slcan-ethtool.c +1 -6
@@ -52,14 +52,9 @@ static int slcan_get_sset_count(struct net_device *netdev, int sset) } } -static const struct ethtool_ops slcan_ethtool_ops = { +const struct ethtool_ops slcan_ethtool_ops = { .get_strings = slcan_get_strings, .get_priv_flags = slcan_get_priv_flags, .set_priv_flags = slcan_set_priv_flags, .get_sset_count = slcan_get_sset_count, }; - -void slcan_set_ethtool_ops (struct net_device *netdev) -{ - netdev->ethtool_ops = &slcan_ethtool_ops; -}
drivers/net/can/slcan/slcan.h +2 -1
@@ -13,6 +13,7 @@bool slcan_err_rst_on_open (struct net_device *ndev);int slcan_enable_err_rst_on_open (struct net_device *ndev,bool on); -void slcan_set_ethtool_ops (struct net_device *ndev); + +extern const struct ethtool_ops slcan_ethtool_ops;#endif /* _SLCAN_H */
Signature · 1 line
2.35.1
PATCH 2/3 can: c_can: export c_can_ethtool_ops and remove c_can_set_ethtool_ops()
In reply to Vincent MailholThe function c_can_set_ethtool_ops() does one thing: populate net_device::ethtool_ops. Instead, it is possible to directly assign this field and remove one function call and slightly reduce the object size. To do so, export c_can_ethtool_ops so it becomes visible to c_can_main.c.
--- drivers/net/can/c_can/c_can.h | 2 +- drivers/net/can/c_can/c_can_ethtool.c | 7 +------ drivers/net/can/c_can/c_can_main.c | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-)
drivers/net/can/c_can/c_can.h +1 -1
@@ -223,7 +223,7 @@ int c_can_power_up(struct net_device *dev);int c_can_power_down (struct net_device *dev);#endif -void c_can_set_ethtool_ops (struct net_device *dev); +extern const struct ethtool_ops c_can_ethtool_ops;static inline u8 c_can_get_tx_head (const struct c_can_tx_ring *ring) {
drivers/net/can/c_can/c_can_ethtool.c +1 -6
@@ -24,11 +24,6 @@ static void c_can_get_ringparam(struct net_device *netdev, ring->tx_pending = priv->msg_obj_tx_num; } -static const struct ethtool_ops c_can_ethtool_ops = { +const struct ethtool_ops c_can_ethtool_ops = { .get_ringparam = c_can_get_ringparam, }; - -void c_can_set_ethtool_ops (struct net_device *netdev) -{ - netdev->ethtool_ops = &c_can_ethtool_ops; -}
drivers/net/can/c_can/c_can_main.c +1 -1
@@ -1364,7 +1364,7 @@ int register_c_can_dev(struct net_device *dev) dev->flags |=IFF_ECHO ;/* we support local echo */ dev->netdev_ops = &c_can_netdev_ops; -c_can_set_ethtool_ops (dev); + dev->ethtool_ops = &c_can_ethtool_ops;return register_candev (dev); }
Signature · 1 line
2.35.1
PATCH 3/3 can: flexcan: export flexcan_ethtool_ops and remove flexcan_set_ethtool_ops()
In reply to Vincent MailholThe function flexcan_set_ethtool_ops() does one thing: populate net_device::ethtool_ops. Instead, it is possible to directly assign this field and remove one function call and slightly reduce the object size. To do so, export flexcan_ethtool_ops so it becomes visible to flexcan-core.c.
--- drivers/net/can/flexcan/flexcan-core.c | 2 +- drivers/net/can/flexcan/flexcan-ethtool.c | 7 +------ drivers/net/can/flexcan/flexcan.h | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-)
drivers/net/can/flexcan/flexcan-core.c +1 -1
@@ -2113,7 +2113,7 @@ static int flexcan_probe(struct platform_device *pdev)SET_NETDEV_DEV (dev, &pdev->dev); dev->netdev_ops = &flexcan_netdev_ops; -flexcan_set_ethtool_ops (dev); + dev->ethtool_ops = &flexcan_ethtool_ops; dev->irq = irq; dev->flags |=IFF_ECHO ;
drivers/net/can/flexcan/flexcan-ethtool.c +1 -6
@@ -100,15 +100,10 @@ static int flexcan_get_sset_count(struct net_device *netdev, int sset) } } -static const struct ethtool_ops flexcan_ethtool_ops = { +const struct ethtool_ops flexcan_ethtool_ops = { .get_ringparam = flexcan_get_ringparam, .get_strings = flexcan_get_strings, .get_priv_flags = flexcan_get_priv_flags, .set_priv_flags = flexcan_set_priv_flags, .get_sset_count = flexcan_get_sset_count, }; - -void flexcan_set_ethtool_ops (struct net_device *netdev) -{ - netdev->ethtool_ops = &flexcan_ethtool_ops; -}
drivers/net/can/flexcan/flexcan.h +1 -1
@@ -114,7 +114,7 @@ struct flexcan_priv {void (*write)(u32 val,void __iomem *addr); }; -void flexcan_set_ethtool_ops (struct net_device *dev); +extern const struct ethtool_ops flexcan_ethtool_ops;static inline bool flexcan_supports_rx_mailbox (const struct flexcan_priv *priv)
Signature · 1 line
2.35.1
Quoted 9 lines · Vincent Mailhol
The
c_can, flexcan and slcan use a setter function to populatenet_device::ethtool_ops. Using a setter here add one additional function call and add some small bloat in the object file. Exporting the structure allow to remove this setter.The mcp251xfd uses a similar pattern except that it does some additional initialization. As such, this driver is left untouched.
Quoted 5 lines
* Statistics *
For the slcan driver, this patch reduces the object file by 14 bytes (details in the first patch). Although we did not conduct a benchmark for the other drivers but we expect the exact same figures.
Applied to can-next/master.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |