Skip to content

Commit 188ec77

Browse files
Takamitsu Iwaigregkh
authored andcommitted
net: rose: split remove and free operations in rose_remove_neigh()
[ Upstream commit dcb3465 ] The current rose_remove_neigh() performs two distinct operations: 1. Removes rose_neigh from rose_neigh_list 2. Frees the rose_neigh structure Split these operations into separate functions to improve maintainability and prepare for upcoming refcount_t conversion. The timer cleanup remains in rose_remove_neigh() because free operations can be called from timer itself. This patch introduce rose_neigh_put() to handle the freeing of rose_neigh structures and modify rose_remove_neigh() to handle removal only. Signed-off-by: Takamitsu Iwai <takamitz@amazon.co.jp> Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com> Link: https://patch.msgid.link/20250823085857.47674-2-takamitz@amazon.co.jp Signed-off-by: Jakub Kicinski <kuba@kernel.org> Stable-dep-of: d860d1f ("net: rose: convert 'use' field to refcount_t") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f4f411c commit 188ec77

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/net/rose.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ struct rose_sock {
151151

152152
#define rose_sk(sk) ((struct rose_sock *)(sk))
153153

154+
static inline void rose_neigh_put(struct rose_neigh *rose_neigh)
155+
{
156+
if (rose_neigh->ax25)
157+
ax25_cb_put(rose_neigh->ax25);
158+
kfree(rose_neigh->digipeat);
159+
kfree(rose_neigh);
160+
}
161+
154162
/* af_rose.c */
155163
extern ax25_address rose_callsign;
156164
extern int sysctl_rose_restart_request_timeout;

net/rose/rose_route.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,12 @@ static void rose_remove_neigh(struct rose_neigh *rose_neigh)
234234

235235
if ((s = rose_neigh_list) == rose_neigh) {
236236
rose_neigh_list = rose_neigh->next;
237-
if (rose_neigh->ax25)
238-
ax25_cb_put(rose_neigh->ax25);
239-
kfree(rose_neigh->digipeat);
240-
kfree(rose_neigh);
241237
return;
242238
}
243239

244240
while (s != NULL && s->next != NULL) {
245241
if (s->next == rose_neigh) {
246242
s->next = rose_neigh->next;
247-
if (rose_neigh->ax25)
248-
ax25_cb_put(rose_neigh->ax25);
249-
kfree(rose_neigh->digipeat);
250-
kfree(rose_neigh);
251243
return;
252244
}
253245

@@ -331,8 +323,10 @@ static int rose_del_node(struct rose_route_struct *rose_route,
331323
if (rose_node->neighbour[i] == rose_neigh) {
332324
rose_neigh->count--;
333325

334-
if (rose_neigh->count == 0 && rose_neigh->use == 0)
326+
if (rose_neigh->count == 0 && rose_neigh->use == 0) {
335327
rose_remove_neigh(rose_neigh);
328+
rose_neigh_put(rose_neigh);
329+
}
336330

337331
rose_node->count--;
338332

@@ -513,6 +507,7 @@ void rose_rt_device_down(struct net_device *dev)
513507
}
514508

515509
rose_remove_neigh(s);
510+
rose_neigh_put(s);
516511
}
517512
spin_unlock_bh(&rose_neigh_list_lock);
518513
spin_unlock_bh(&rose_node_list_lock);
@@ -569,6 +564,7 @@ static int rose_clear_routes(void)
569564
if (s->use == 0 && !s->loopback) {
570565
s->count = 0;
571566
rose_remove_neigh(s);
567+
rose_neigh_put(s);
572568
}
573569
}
574570

@@ -1301,6 +1297,7 @@ void __exit rose_rt_free(void)
13011297
rose_neigh = rose_neigh->next;
13021298

13031299
rose_remove_neigh(s);
1300+
rose_neigh_put(s);
13041301
}
13051302

13061303
while (rose_node != NULL) {

0 commit comments

Comments
 (0)