Skip to contentSkip to conversation

net: get rid of unused static inlines

PATCH Applied Jakub Kicinski 8 participants 23 messages Jan 26, 2022 – Jan 28, 2022

Subsystems (9)
lore
Share & tools
lore
author maintainer
#8 lore raw

PATCH 6/15 net: ax25: remove route refcount

In reply to Jakub Kicinski

Nothing takes the refcount since v4.9.

---
CC: [email protected]
CC: [email protected]

---
 include/net/ax25.h    | 12 ------------
 net/ax25/ax25_route.c |  5 ++---
 2 files changed, 2 insertions(+), 15 deletions(-)
include/net/ax25.h +0 -12
index 526e49589197..cb628c5d7c5b 100644
@@ -187,18 +187,12 @@ typedef struct {
 
 typedef struct ax25_route {
 	struct ax25_route	*next;
-	refcount_t		refcount;
 	ax25_address		callsign;
 	struct net_device	*dev;
 	ax25_digi		*digipeat;
 	char			ip_mode;
 } ax25_route;
 
-static inline void ax25_hold_route(ax25_route *ax25_rt)
-{
-	refcount_inc(&ax25_rt->refcount);
-}
-
 void __ax25_put_route(ax25_route *ax25_rt);
 
 extern rwlock_t ax25_route_lock;
@@ -213,12 +207,6 @@ static inline void ax25_route_lock_unuse(void)
 	read_unlock(&ax25_route_lock);
 }
 
-static inline void ax25_put_route(ax25_route *ax25_rt)
-{
-	if (refcount_dec_and_test(&ax25_rt->refcount))
-		__ax25_put_route(ax25_rt);
-}
-
 typedef struct {
 	char			slave;			/* slave_mode?   */
 	struct timer_list	slave_timer;		/* timeout timer */
net/ax25/ax25_route.c +2 -3
index d0b2e094bd55..be97dc6a53cb 100644
@@ -111,7 +111,6 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
 		return -ENOMEM;
 	}
 
-	refcount_set(&ax25_rt->refcount, 1);
 	ax25_rt->callsign     = route->dest_addr;
 	ax25_rt->dev          = ax25_dev->dev;
 	ax25_rt->digipeat     = NULL;
@@ -160,12 +159,12 @@ static int ax25_rt_del(struct ax25_routes_struct *route)
 		    ax25cmp(&route->dest_addr, &s->callsign) == 0) {
 			if (ax25_route_list == s) {
 				ax25_route_list = s->next;
-				ax25_put_route(s);
+				__ax25_put_route(s);
 			} else {
 				for (t = ax25_route_list; t != NULL; t = t->next) {
 					if (t->next == s) {
 						t->next = s->next;
-						ax25_put_route(s);
+						__ax25_put_route(s);
 						break;
 					}
 				}
Signature · 1 line
2.34.1
author maintainer
#14 lore raw

PATCH 9/15 dccp: remove max48()

In reply to Jakub Kicinski

Not used since v2.6.37.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/dccp/dccp.h | 5 -----
 1 file changed, 5 deletions(-)
net/dccp/dccp.h +0 -5
index 5183e627468d..671c377f0889 100644
@@ -136,11 +136,6 @@ static inline int between48(const u64 seq1, const u64 seq2, const u64 seq3)
 	return (seq3 << 16) - (seq2 << 16) >= (seq1 << 16) - (seq2 << 16);
 }
 
-static inline u64 max48(const u64 seq1, const u64 seq2)
-{
-	return after48(seq1, seq2) ? seq1 : seq2;
-}
-
 /**
  * dccp_loss_count - Approximate the number of lost data packets in a burst loss
  * @s1:  last known sequence number before the loss ('hole')
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/15 mii: remove mii_lpa_to_linkmode_lpa_sgmii()

In reply to Jakub Kicinski

The only caller of mii_lpa_to_linkmode_lpa_sgmii() disappeared in v5.10.

--
CC: Vladimir Oltean <[email protected]>
CC: Andrew Lunn <[email protected]>
CC: Heiner Kallweit <[email protected]>
CC: Russell King <[email protected]>

---
 include/linux/mii.h | 17 -----------------
 1 file changed, 17 deletions(-)
include/linux/mii.h +0 -17
index 12ea29e04293..b8a1a17a87dd 100644
@@ -387,23 +387,6 @@ mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa)
 			 speed_duplex == LPA_SGMII_10FULL);
 }
 
-/**
- * mii_lpa_to_linkmode_adv_sgmii
- * @advertising: pointer to destination link mode.
- * @lpa: value of the MII_LPA register
- *
- * A small helper function that translates MII_ADVERTISE bits
- * to linkmode advertisement settings when in SGMII mode.
- * Clears the old value of advertising.
- */
-static inline void mii_lpa_to_linkmode_lpa_sgmii(unsigned long *lp_advertising,
-						 u32 lpa)
-{
-	linkmode_zero(lp_advertising);
-
-	mii_lpa_mod_linkmode_lpa_sgmii(lp_advertising, lpa);
-}
-
 /**
  * mii_adv_mod_linkmode_adv_t
  * @advertising:pointer to destination link mode.
Signature · 1 line
2.34.1
author maintainer
#5 lore raw

PATCH 3/15 net: remove net_invalid_timestamp()

In reply to Jakub Kicinski

No callers since v3.15.

---
 include/linux/skbuff.h | 5 -----
 1 file changed, 5 deletions(-)
include/linux/skbuff.h +0 -5
index 8131d0de7559..60bd2347708c 100644
@@ -3899,11 +3899,6 @@ static inline ktime_t net_timedelta(ktime_t t)
 	return ktime_sub(ktime_get_real(), t);
 }
 
-static inline ktime_t net_invalid_timestamp(void)
-{
-	return 0;
-}
-
 static inline u8 skb_metadata_len(const struct sk_buff *skb)
 {
 	return skb_shinfo(skb)->meta_len;
Signature · 1 line
2.34.1

Jakub Kicinski

author maintainer
#0 lore raw

cover net: get rid of unused static inlines

I noticed a couple of unused static inline functions reviewing net/sched patches so I run a grep thru all of include/ and net/ to catch other cases. This set removes the cases which look like obvious dead code.

Jakub Kicinski (15):
mii: remove mii_lpa_to_linkmode_lpa_sgmii()
nfc: use *_set_vendor_cmds() helpers
net: remove net_invalid_timestamp()
net: remove linkmode_change_bit()
net: remove bond_slave_has_mac_rcu()
net: ax25: remove route refcount
hsr: remove get_prp_lan_id()
ipv6: remove inet6_rsk() and tcp_twsk_ipv6only()
dccp: remove max48()
udp: remove inner_udp_hdr()
udplite: remove udplite_csum_outgoing()
netlink: remove nl_set_extack_cookie_u32()
net: sched: remove psched_tdiff_bounded()
net: sched: remove qdisc_qlen_cpu()
net: tipc: remove unused static inlines

 drivers/nfc/st-nci/vendor_cmds.c   |  2 +-
 drivers/nfc/st21nfca/vendor_cmds.c |  4 +--
 include/linux/ipv6.h               |  7 -----
 include/linux/linkmode.h           |  5 ----
 include/linux/mii.h                | 17 ------------
 include/linux/netlink.h            |  9 -------
 include/linux/skbuff.h             |  5 ----
 include/linux/udp.h                |  5 ----
 include/net/ax25.h                 | 12 ---------
 include/net/bonding.h              | 14 ----------
 include/net/pkt_sched.h            |  6 -----
 include/net/sch_generic.h          |  5 ----
 include/net/udplite.h              | 43 ------------------------------
 net/ax25/ax25_route.c              |  5 ++--
 net/dccp/dccp.h                    |  5 ----
 net/hsr/hsr_main.h                 |  5 ----
 net/tipc/msg.h                     | 23 ----------------
 17 files changed, 5 insertions(+), 167 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#7 lore raw

PATCH 5/15 net: remove bond_slave_has_mac_rcu()

No caller since v3.16.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 include/net/bonding.h | 14 --------------
 1 file changed, 14 deletions(-)
include/net/bonding.h +0 -14
index 83cfd2d70247..7dead855a72d 100644
@@ -698,20 +698,6 @@ static inline struct slave *bond_slave_has_mac(struct bonding *bond,
 	return NULL;
 }
 
-/* Caller must hold rcu_read_lock() for read */
-static inline struct slave *bond_slave_has_mac_rcu(struct bonding *bond,
-					       const u8 *mac)
-{
-	struct list_head *iter;
-	struct slave *tmp;
-
-	bond_for_each_slave_rcu(bond, tmp, iter)
-		if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
-			return tmp;
-
-	return NULL;
-}
-
 /* Caller must hold rcu_read_lock() for read */
 static inline bool bond_slave_has_mac_rx(struct bonding *bond, const u8 *mac)
 {
Signature · 1 line
2.34.1
author maintainer
#12 lore raw

PATCH 7/15 hsr: remove get_prp_lan_id()

In reply to Jakub Kicinski

get_prp_lan_id() has never been used.

---
CC: [email protected]
CC: [email protected]

---
 net/hsr/hsr_main.h | 5 -----
 1 file changed, 5 deletions(-)
net/hsr/hsr_main.h +0 -5
index 043e4e9a1694..ff9ec7634218 100644
@@ -259,11 +259,6 @@ static inline u16 prp_get_skb_sequence_nr(struct prp_rct *rct)
 	return ntohs(rct->sequence_nr);
 }
 
-static inline u16 get_prp_lan_id(struct prp_rct *rct)
-{
-	return ntohs(rct->lan_id_and_LSDU_size) >> 12;
-}
-
 /* assume there is a valid rct */
 static inline bool prp_check_lsdu_size(struct sk_buff *skb,
 				       struct prp_rct *rct,
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 2/15 nfc: use *_set_vendor_cmds() helpers

In reply to Jakub Kicinski

NCI and HCI wrappers for nfc_set_vendor_cmds() exist, use them. We could also remove the helpers. It's a coin toss.

---
CC: [email protected]
CC: [email protected]

---
 drivers/nfc/st-nci/vendor_cmds.c   | 2 +-
 drivers/nfc/st21nfca/vendor_cmds.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/nfc/st-nci/vendor_cmds.c +1 -1
index 30d2912d1a05..6335d7afca24 100644
@@ -456,7 +456,7 @@ static const struct nfc_vendor_cmd st_nci_vendor_cmds[] = {
 
 int st_nci_vendor_cmds_init(struct nci_dev *ndev)
 {
-	return nfc_set_vendor_cmds(ndev->nfc_dev, st_nci_vendor_cmds,
+	return nci_set_vendor_cmds(ndev, st_nci_vendor_cmds,
 				   sizeof(st_nci_vendor_cmds));
 }
 EXPORT_SYMBOL(st_nci_vendor_cmds_init);
drivers/nfc/st21nfca/vendor_cmds.c +2 -2
index 74882866dbaf..bfa418d4c6b0 100644
@@ -358,7 +358,7 @@ int st21nfca_vendor_cmds_init(struct nfc_hci_dev *hdev)
 	struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
 
 	init_completion(&info->vendor_info.req_completion);
-	return nfc_set_vendor_cmds(hdev->ndev, st21nfca_vendor_cmds,
-				   sizeof(st21nfca_vendor_cmds));
+	return nfc_hci_set_vendor_cmds(hdev, st21nfca_vendor_cmds,
+				       sizeof(st21nfca_vendor_cmds));
 }
 EXPORT_SYMBOL(st21nfca_vendor_cmds_init);
Signature · 1 line
2.34.1
author maintainer
#6 lore raw

PATCH 4/15 net: remove linkmode_change_bit()

In reply to Jakub Kicinski

No callers since v5.7, the initial use case seems pretty esoteric so removing this should not harm the completeness of the API.

---
CC: Andrew Lunn <[email protected]>
CC: Heiner Kallweit <[email protected]>
CC: Russell King <[email protected]>

---
 include/linux/linkmode.h | 5 -----
 1 file changed, 5 deletions(-)
include/linux/linkmode.h +0 -5
index f8397f300fcd..15e0e0209da4 100644
@@ -66,11 +66,6 @@ static inline void linkmode_mod_bit(int nr, volatile unsigned long *addr,
 		linkmode_clear_bit(nr, addr);
 }
 
-static inline void linkmode_change_bit(int nr, volatile unsigned long *addr)
-{
-	__change_bit(nr, addr);
-}
-
 static inline int linkmode_test_bit(int nr, const volatile unsigned long *addr)
 {
 	return test_bit(nr, addr);
Signature · 1 line
2.34.1
author maintainer
#13 lore raw

PATCH 8/15 ipv6: remove inet6_rsk() and tcp_twsk_ipv6only()

In reply to Jakub Kicinski

The stubs under !CONFIG_IPV6 were missed when real functions got deleted ca. v3.13.

---
CC: [email protected]
CC: [email protected]

---
 include/linux/ipv6.h | 7 -------
 1 file changed, 7 deletions(-)
include/linux/ipv6.h +0 -7
index a59d25f19385..1e0f8a31f3de 100644
@@ -371,19 +371,12 @@ static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
 	return NULL;
 }
 
-static inline struct inet6_request_sock *
-			inet6_rsk(const struct request_sock *rsk)
-{
-	return NULL;
-}
-
 static inline struct raw6_sock *raw6_sk(const struct sock *sk)
 {
 	return NULL;
 }
 
 #define inet6_rcv_saddr(__sk)	NULL
-#define tcp_twsk_ipv6only(__sk)		0
 #define inet_v6_ipv6only(__sk)		0
 #endif /* IS_ENABLED(CONFIG_IPV6) */
 #endif /* _IPV6_H */
Signature · 1 line
2.34.1
author maintainer
#15 lore raw

PATCH 10/15 udp: remove inner_udp_hdr()

In reply to Jakub Kicinski

Not used since added in v3.8.

---
CC: [email protected]
CC: [email protected]

---
 include/linux/udp.h | 5 -----
 1 file changed, 5 deletions(-)
include/linux/udp.h +0 -5
index ae66dadd8543..254a2654400f 100644
@@ -23,11 +23,6 @@ static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
 	return (struct udphdr *)skb_transport_header(skb);
 }
 
-static inline struct udphdr *inner_udp_hdr(const struct sk_buff *skb)
-{
-	return (struct udphdr *)skb_inner_transport_header(skb);
-}
-
 #define UDP_HTABLE_SIZE_MIN		(CONFIG_BASE_SMALL ? 128 : 256)
 
 static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask)
Signature · 1 line
2.34.1
author maintainer
#18 lore raw

PATCH 12/15 netlink: remove nl_set_extack_cookie_u32()

In reply to Jakub Kicinski

Not used since v5.10.

---
 include/linux/netlink.h | 9 ---------
 1 file changed, 9 deletions(-)
include/linux/netlink.h +0 -9
index 1ec631838af9..bda1c385cffb 100644
@@ -135,15 +135,6 @@ static inline void nl_set_extack_cookie_u64(struct netlink_ext_ack *extack,
 	extack->cookie_len = sizeof(cookie);
 }
 
-static inline void nl_set_extack_cookie_u32(struct netlink_ext_ack *extack,
-					    u32 cookie)
-{
-	if (!extack)
-		return;
-	memcpy(extack->cookie, &cookie, sizeof(cookie));
-	extack->cookie_len = sizeof(cookie);
-}
-
 void netlink_kernel_release(struct sock *sk);
 int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
 int netlink_change_ngroups(struct sock *sk, unsigned int groups);
Signature · 1 line
2.34.1
author maintainer
#19 lore raw

PATCH 13/15 net: sched: remove psched_tdiff_bounded()

In reply to Jakub Kicinski

Not used since v3.9.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 include/net/pkt_sched.h | 6 ------
 1 file changed, 6 deletions(-)
include/net/pkt_sched.h +0 -6
index 9e7b21c0b3a6..44a35531952e 100644
@@ -63,12 +63,6 @@ static inline psched_time_t psched_get_time(void)
 	return PSCHED_NS2TICKS(ktime_get_ns());
 }
 
-static inline psched_tdiff_t
-psched_tdiff_bounded(psched_time_t tv1, psched_time_t tv2, psched_time_t bound)
-{
-	return min(tv1 - tv2, bound);
-}
-
 struct qdisc_watchdog {
 	u64		last_expires;
 	struct hrtimer	timer;
Signature · 1 line
2.34.1
author maintainer
#17 lore raw

PATCH 11/15 udplite: remove udplite_csum_outgoing()

In reply to Jakub Kicinski

Not used since v4.0.

---
 include/net/udplite.h | 43 -------------------------------------------
 1 file changed, 43 deletions(-)
include/net/udplite.h +0 -43
index 9185e45b997f..a3c53110d30b 100644
@@ -70,49 +70,6 @@ static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh)
 	return 0;
 }
 
-/* Slow-path computation of checksum. Socket is locked. */
-static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)
-{
-	const struct udp_sock *up = udp_sk(skb->sk);
-	int cscov = up->len;
-	__wsum csum = 0;
-
-	if (up->pcflag & UDPLITE_SEND_CC) {
-		/*
-		 * Sender has set `partial coverage' option on UDP-Lite socket.
-		 * The special case "up->pcslen == 0" signifies full coverage.
-		 */
-		if (up->pcslen < up->len) {
-			if (0 < up->pcslen)
-				cscov = up->pcslen;
-			udp_hdr(skb)->len = htons(up->pcslen);
-		}
-		/*
-		 * NOTE: Causes for the error case  `up->pcslen > up->len':
-		 *        (i)  Application error (will not be penalized).
-		 *       (ii)  Payload too big for send buffer: data is split
-		 *             into several packets, each with its own header.
-		 *             In this case (e.g. last segment), coverage may
-		 *             exceed packet length.
-		 *       Since packets with coverage length > packet length are
-		 *       illegal, we fall back to the defaults here.
-		 */
-	}
-
-	skb->ip_summed = CHECKSUM_NONE;     /* no HW support for checksumming */
-
-	skb_queue_walk(&sk->sk_write_queue, skb) {
-		const int off = skb_transport_offset(skb);
-		const int len = skb->len - off;
-
-		csum = skb_checksum(skb, off, (cscov > len)? len : cscov, csum);
-
-		if ((cscov -= len) <= 0)
-			break;
-	}
-	return csum;
-}
-
 /* Fast-path computation of checksum. Socket may not be locked. */
 static inline __wsum udplite_csum(struct sk_buff *skb)
 {
Signature · 1 line
2.34.1
author maintainer
#21 lore raw

PATCH 15/15 net: tipc: remove unused static inlines

In reply to Jakub Kicinski

IIUC the TIPC msg helpers are not meant to provide and exhaustive API, so remove the unused ones.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/tipc/msg.h | 23 -----------------------
 1 file changed, 23 deletions(-)
net/tipc/msg.h +0 -23
index 64ae4c4c44f8..c5eec16213d7 100644
@@ -226,14 +226,6 @@ static inline void msg_set_bits(struct tipc_msg *m, u32 w,
 	m->hdr[w] |= htonl(val);
 }
 
-static inline void msg_swap_words(struct tipc_msg *msg, u32 a, u32 b)
-{
-	u32 temp = msg->hdr[a];
-
-	msg->hdr[a] = msg->hdr[b];
-	msg->hdr[b] = temp;
-}
-
 /*
  * Word 0
  */
@@ -480,11 +472,6 @@ static inline void msg_incr_reroute_cnt(struct tipc_msg *m)
 	msg_set_bits(m, 1, 21, 0xf, msg_reroute_cnt(m) + 1);
 }
 
-static inline void msg_reset_reroute_cnt(struct tipc_msg *m)
-{
-	msg_set_bits(m, 1, 21, 0xf, 0);
-}
-
 static inline u32 msg_lookup_scope(struct tipc_msg *m)
 {
 	return msg_bits(m, 1, 19, 0x3);
@@ -800,11 +787,6 @@ static inline void msg_set_dest_domain(struct tipc_msg *m, u32 n)
 	msg_set_word(m, 2, n);
 }
 
-static inline u32 msg_bcgap_after(struct tipc_msg *m)
-{
-	return msg_bits(m, 2, 16, 0xffff);
-}
-
 static inline void msg_set_bcgap_after(struct tipc_msg *m, u32 n)
 {
 	msg_set_bits(m, 2, 16, 0xffff, n);
@@ -868,11 +850,6 @@ static inline void msg_set_next_sent(struct tipc_msg *m, u16 n)
 	msg_set_bits(m, 4, 0, 0xffff, n);
 }
 
-static inline void msg_set_long_msgno(struct tipc_msg *m, u32 n)
-{
-	msg_set_bits(m, 4, 0, 0xffff, n);
-}
-
 static inline u32 msg_bc_netid(struct tipc_msg *m)
 {
 	return msg_word(m, 4);
Signature · 1 line
2.34.1
author maintainer
#20 lore raw

PATCH 14/15 net: sched: remove qdisc_qlen_cpu()

In reply to Jakub Kicinski

Never used since it was added in v5.2.

---
 include/net/sch_generic.h | 5 -----
 1 file changed, 5 deletions(-)
include/net/sch_generic.h +0 -5
index 472843eedbae..9bab396c1f3b 100644
@@ -518,11 +518,6 @@ static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz)
 	BUILD_BUG_ON(sizeof(qcb->data) < sz);
 }
 
-static inline int qdisc_qlen_cpu(const struct Qdisc *q)
-{
-	return this_cpu_ptr(q->cpu_qstats)->qlen;
-}
-
 static inline int qdisc_qlen(const struct Qdisc *q)
 {
 	return q->q.qlen;
Signature · 1 line
2.34.1
Reviewed-by on v1 2/15
#4 lore raw

Re: [PATCH net-next 02/15] nfc: use *_set_vendor_cmds() helpers

In reply to Jakub Kicinski
Quoted 4 lines · Jakub Kicinski

NCI and HCI wrappers for nfc_set_vendor_cmds() exist, use them. We could also remove the helpers. It's a coin toss.

Quoted 9 lines

---
CC: [email protected]
CC: [email protected]

---
 drivers/nfc/st-nci/vendor_cmds.c   | 2 +-
 drivers/nfc/st21nfca/vendor_cmds.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH net-next 06/15] net: ax25: remove route refcount

In reply to Jakub Kicinski

Hello,

think it's absolutely correct to state
"Nothing takes the refcount since v4.9."
because in ax25_rt_add(),
refcount_set(&ax25_rt->refcount, 1);
is used (for every new ax25_rt entry).

But nothing does an increment.
There's one function in include/net/ax25.h ,
ax25_hold_route() which would refcount_inc(&ax25_rt->refcount)
but it's not called from anywhere.

=> It's value is always 1, and the deleting function ax25_put_route() decrements it again before freeing.
I also see no sense in this (anymore).

Every struct ax25_route_list operation is assured with either
write_lock_bh(&ax25_route_lock);
write_unlock_bh(&ax25_route_lock);
or
the struct ax25_route returned from functions is assured by calling read_lock(&ax25_route_lock).

-> No refcount is needed.

=> It's good to tidy up stuff that's needed anymore.

But keep in mind:
The code has strong similarities with include/net/x25.h and x25/x25_route.c , especially in the parts of ax25_hold_route() and ax25_rt_add(). This will get lost.

But there a things a bot does not know: human readable senteces. ax25_get_route() is introduced with:

/*
* Find AX.25 route
*
* Only routes with a reference count of zero can be destroyed.
* Must be called with ax25_route_lock read locked.
*/

The first sentence informs: ax25_rt entries may be freed during the ax25_route_list operation.
It mentiones reference count (which will exist anymore).
The conclusion of the first sentence is "Must be called with ax25_route_lock read locked.". This is still true and assured. I don't think it has to explain why the read lock is necessary (it's obvious, that routes could be deleted or added to the list). ->

/*
* Find AX.25 route
*
* Must be called with ax25_route_lock read locked.
*/

should be enough.

ff-topic:
=========

About read_lock)(): Inconsistent use.
It's
directly called,
and by
ax25_route_lock_use(), which calls read_lock():

  {
          read_lock(&ax25_route_lock);

}

This makes the code harder to read.
There's also a function ax25_rt_seq_stop() that calls read_unlock() instead of calling ax25_route_lock_unuse(), which does the same.

vy 73,
- Thomas dl9sau

Quoted 77 lines · Jakub Kicinski

Nothing takes the refcount since v4.9.

---
CC: [email protected]
CC: [email protected]

---
 include/net/ax25.h    | 12 ------------
 net/ax25/ax25_route.c |  5 ++---
 2 files changed, 2 insertions(+), 15 deletions(-)
include/net/ax25.h +0 -12
index 526e49589197..cb628c5d7c5b 100644
@@ -187,18 +187,12 @@ typedef struct {
 
 typedef struct ax25_route {
 	struct ax25_route	*next;
-	refcount_t		refcount;
 	ax25_address		callsign;
 	struct net_device	*dev;
 	ax25_digi		*digipeat;
 	char			ip_mode;
 } ax25_route;
 
-static inline void ax25_hold_route(ax25_route *ax25_rt)
-{
-	refcount_inc(&ax25_rt->refcount);
-}
-
 void __ax25_put_route(ax25_route *ax25_rt);
 
 extern rwlock_t ax25_route_lock;
@@ -213,12 +207,6 @@ static inline void ax25_route_lock_unuse(void)
 	read_unlock(&ax25_route_lock);
 }
 
-static inline void ax25_put_route(ax25_route *ax25_rt)
-{
-	if (refcount_dec_and_test(&ax25_rt->refcount))
-		__ax25_put_route(ax25_rt);
-}
-
 typedef struct {
 	char			slave;			/* slave_mode?   */
 	struct timer_list	slave_timer;		/* timeout timer */
net/ax25/ax25_route.c +2 -3
index d0b2e094bd55..be97dc6a53cb 100644
@@ -111,7 +111,6 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
 		return -ENOMEM;
 	}
 
-	refcount_set(&ax25_rt->refcount, 1);
 	ax25_rt->callsign     = route->dest_addr;
 	ax25_rt->dev          = ax25_dev->dev;
 	ax25_rt->digipeat     = NULL;
@@ -160,12 +159,12 @@ static int ax25_rt_del(struct ax25_routes_struct *route)
 		    ax25cmp(&route->dest_addr, &s->callsign) == 0) {
 			if (ax25_route_list == s) {
 				ax25_route_list = s->next;
-				ax25_put_route(s);
+				__ax25_put_route(s);
 			} else {
 				for (t = ax25_route_list; t != NULL; t = t->next) {
 					if (t->next == s) {
 						t->next = s->next;
-						ax25_put_route(s);
+						__ax25_put_route(s);
 						break;
 					}
 				}
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH net-next 01/15] mii: remove mii_lpa_to_linkmode_lpa_sgmii()

In reply to Jakub Kicinski
Quoted 28 lines · Jakub Kicinski

The only caller of mii_lpa_to_linkmode_lpa_sgmii() disappeared in v5.10.

--
CC: Vladimir Oltean <[email protected]>
CC: Andrew Lunn <[email protected]>
CC: Heiner Kallweit <[email protected]>
CC: Russell King <[email protected]>

---
 include/linux/mii.h | 17 -----------------
 1 file changed, 17 deletions(-)
include/linux/mii.h +0 -7
index 12ea29e04293..b8a1a17a87dd 100644
@@ -387,23 +387,6 @@ mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa)
 			 speed_duplex == LPA_SGMII_10FULL);
 }
 
-/**
- * mii_lpa_to_linkmode_adv_sgmii
- * @advertising: pointer to destination link mode.
- * @lpa: value of the MII_LPA register
- *
- * A small helper function that translates MII_ADVERTISE bits
- * to linkmode advertisement settings when in SGMII mode.

include/linux/mii.h mii_lpa_mod_linkmode_lpa_sgmii(unsigned long *lp_advertising, u32 lpa) · line 406

Quoted 10 lines
include/linux/mii.h +0 -10
- * Clears the old value of advertising.
- */
-static inline void mii_lpa_to_linkmode_lpa_sgmii(unsigned long *lp_advertising,
-						 u32 lpa)
-{
-	linkmode_zero(lp_advertising);
-
-	mii_lpa_mod_linkmode_lpa_sgmii(lp_advertising, lpa);
-}
-

This is also the only caller of mii_lpa_mod_linkmode_lpa_sgmii(), so that function can be deleted too.

Quoted 6 lines
include/linux/mii.h +0 -0
 /**
  * mii_adv_mod_linkmode_adv_t
  * @advertising:pointer to destination link mode.
Signature · 1 line
2.34.1
#22 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 22 lines · On Wed, 26 Jan 2022 11:10:54 -0800 you wrote:

I noticed a couple of unused static inline functions reviewing net/sched patches so I run a grep thru all of include/ and net/ to catch other cases. This set removes the cases which look like obvious dead code.

Jakub Kicinski (15):
mii: remove mii_lpa_to_linkmode_lpa_sgmii()
nfc: use *_set_vendor_cmds() helpers
net: remove net_invalid_timestamp()
net: remove linkmode_change_bit()
net: remove bond_slave_has_mac_rcu()
net: ax25: remove route refcount
hsr: remove get_prp_lan_id()
ipv6: remove inet6_rsk() and tcp_twsk_ipv6only()
dccp: remove max48()
udp: remove inner_udp_hdr()
udplite: remove udplite_csum_outgoing()
netlink: remove nl_set_extack_cookie_u32()
net: sched: remove psched_tdiff_bounded()
net: sched: remove qdisc_qlen_cpu()
net: tipc: remove unused static inlines

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,01/15] mii: remove mii_lpa_to_linkmode_lpa_sgmii()

    https://git.kernel.org/netdev/net-next/c/bd5daba2d024
  - [net-next,02/15] nfc: use *_set_vendor_cmds() helpers
    https://git.kernel.org/netdev/net-next/c/f7bfd110f168
  - [net-next,03/15] net: remove net_invalid_timestamp()
    https://git.kernel.org/netdev/net-next/c/b1755400b4be
  - [net-next,04/15] net: remove linkmode_change_bit()
    https://git.kernel.org/netdev/net-next/c/08dfa5a19e1f
  - [net-next,05/15] net: remove bond_slave_has_mac_rcu()
    https://git.kernel.org/netdev/net-next/c/8b0fdcdc3a7d
  - [net-next,06/15] net: ax25: remove route refcount
    https://git.kernel.org/netdev/net-next/c/560e08eda796
  - [net-next,07/15] hsr: remove get_prp_lan_id()
    https://git.kernel.org/netdev/net-next/c/0ab1e6d9a453
  - [net-next,08/15] ipv6: remove inet6_rsk() and tcp_twsk_ipv6only()
    https://git.kernel.org/netdev/net-next/c/8b2d546e23bb
  - [net-next,09/15] dccp: remove max48()
    https://git.kernel.org/netdev/net-next/c/1303f8f0df24
  - [net-next,10/15] udp: remove inner_udp_hdr()
    https://git.kernel.org/netdev/net-next/c/cc81df835c25
  - [net-next,11/15] udplite: remove udplite_csum_outgoing()
    https://git.kernel.org/netdev/net-next/c/937fca918aac
  - [net-next,12/15] netlink: remove nl_set_extack_cookie_u32()
    https://git.kernel.org/netdev/net-next/c/d59a67f2f3f3
  - [net-next,13/15] net: sched: remove psched_tdiff_bounded()
    https://git.kernel.org/netdev/net-next/c/98b608629746
  - [net-next,14/15] net: sched: remove qdisc_qlen_cpu()
    https://git.kernel.org/netdev/net-next/c/a459bc9a3a68
  - [net-next,15/15] net: tipc: remove unused static inlines
    https://git.kernel.org/netdev/net-next/c/5e4eca5d929a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#10 lore raw

Re: [PATCH net-next 06/15] net: ax25: remove route refcount

In reply to Thomas Osterried

Curious, has this change been tested with an actual testbed to confirm it doesn't break anything? We *have* to stop allowing good intentioned but naive developers from submitting patches when they've never tested the resulting change.

--David
KI6ZHD

Quoted 154 lines · Thomas Osterried

Hello,

think it's absolutely correct to state
"Nothing takes the refcount since v4.9."
because in ax25_rt_add(),
refcount_set(&ax25_rt->refcount, 1);
is used (for every new ax25_rt entry).

But nothing does an increment.
There's one function in include/net/ax25.h ,
ax25_hold_route() which would refcount_inc(&ax25_rt->refcount)
but it's not called from anywhere.

=> It's value is always 1, and the deleting function ax25_put_route() decrements it again before freeing.
I also see no sense in this (anymore).

Every struct ax25_route_list operation is assured with either

   write_lock_bh(&ax25_route_lock);
   write_unlock_bh(&ax25_route_lock);

or
the struct ax25_route returned from functions is assured by calling read_lock(&ax25_route_lock).

-> No refcount is needed.

=> It's good to tidy up stuff that's needed anymore.

But keep in mind:
The code has strong similarities with include/net/x25.h and x25/x25_route.c , especially in the parts of ax25_hold_route() and ax25_rt_add(). This will get lost.

But there a things a bot does not know: human readable senteces. ax25_get_route() is introduced with:

/*
* Find AX.25 route
*
* Only routes with a reference count of zero can be destroyed.
* Must be called with ax25_route_lock read locked.
*/

The first sentence informs: ax25_rt entries may be freed during the ax25_route_list operation.
It mentiones reference count (which will exist anymore).
The conclusion of the first sentence is "Must be called with ax25_route_lock read locked.". This is still true and assured. I don't think it has to explain why the read lock is necessary (it's obvious, that routes could be deleted or added to the list). ->

   /*
    *      Find AX.25 route
    *
    *      Must be called with ax25_route_lock read locked.
    */

should be enough.

ff-topic:
=========

About read_lock)(): Inconsistent use.
It's
directly called,
and by
ax25_route_lock_use(), which calls read_lock():

   {
           read_lock(&ax25_route_lock);
   }

This makes the code harder to read.
There's also a function ax25_rt_seq_stop() that calls read_unlock() instead of calling ax25_route_lock_unuse(), which does the same.

vy 73,
- Thomas dl9sau

Quoted 77 lines · Jakub Kicinski

Nothing takes the refcount since v4.9.

---
CC:[email protected]
CC:[email protected]

---
  include/net/ax25.h    | 12 ------------
  net/ax25/ax25_route.c |  5 ++---
  2 files changed, 2 insertions(+), 15 deletions(-)
include/net/ax25.h +0 -12
index 526e49589197..cb628c5d7c5b 100644
@@ -187,18 +187,12 @@ typedef struct {
 
  typedef struct ax25_route {
  	struct ax25_route	*next;
-	refcount_t		refcount;
  	ax25_address		callsign;
  	struct net_device	*dev;
  	ax25_digi		*digipeat;
  	char			ip_mode;
  } ax25_route;
 
-static inline void ax25_hold_route(ax25_route *ax25_rt)
-{
-	refcount_inc(&ax25_rt->refcount);
-}
-
  void __ax25_put_route(ax25_route *ax25_rt);
 
  extern rwlock_t ax25_route_lock;
@@ -213,12 +207,6 @@ static inline void ax25_route_lock_unuse(void)
  	read_unlock(&ax25_route_lock);
  }
 
-static inline void ax25_put_route(ax25_route *ax25_rt)
-{
-	if (refcount_dec_and_test(&ax25_rt->refcount))
-		__ax25_put_route(ax25_rt);
-}
-
  typedef struct {
  	char			slave;			/* slave_mode?   */
  	struct timer_list	slave_timer;		/* timeout timer */
net/ax25/ax25_route.c +2 -3
index d0b2e094bd55..be97dc6a53cb 100644
@@ -111,7 +111,6 @@ static int __must_check ax25_rt_add(struct ax25_routes_struct *route)
  		return -ENOMEM;
  	}
 
-	refcount_set(&ax25_rt->refcount, 1);
  	ax25_rt->callsign     = route->dest_addr;
  	ax25_rt->dev          = ax25_dev->dev;
  	ax25_rt->digipeat     = NULL;
@@ -160,12 +159,12 @@ static int ax25_rt_del(struct ax25_routes_struct *route)
  		    ax25cmp(&route->dest_addr, &s->callsign) == 0) {
  			if (ax25_route_list == s) {
  				ax25_route_list = s->next;
-				ax25_put_route(s);
+				__ax25_put_route(s);
  			} else {
  				for (t = ax25_route_list; t != NULL; t = t->next) {
  					if (t->next == s) {
  						t->next = s->next;
-						ax25_put_route(s);
+						__ax25_put_route(s);
  						break;
  					}
  				}
Signature · 1 line
2.34.1
Reviewed-by
#11 lore raw

Re: [PATCH net-next 06/15] net: ax25: remove route refcount

Quoted 5 lines · David Ranch

Curious, has this change been tested with an actual testbed to confirm it doesn't break anything? We *have* to stop allowing good intentioned but naive developers from submitting patches when they've never tested the resulting change.

Hopefully Jakub is not *too* naive, given that he (along with Dave Miller) have final say over everything networking related in the Linux kernel. :P

Plus, we all reviewed the patch and it's fine.

regards,
dan carpenter