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

net: rose: split remove and free operations in rose_remove_neigh()

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>

authored by

Takamitsu Iwai and committed by
Jakub Kicinski
dcb34659 9448ccd8

+14 -9
+8
include/net/rose.h
··· 151 151 152 152 #define rose_sk(sk) ((struct rose_sock *)(sk)) 153 153 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 + 154 162 /* af_rose.c */ 155 163 extern ax25_address rose_callsign; 156 164 extern int sysctl_rose_restart_request_timeout;
+6 -9
net/rose/rose_route.c
··· 234 234 235 235 if ((s = rose_neigh_list) == rose_neigh) { 236 236 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); 241 237 return; 242 238 } 243 239 244 240 while (s != NULL && s->next != NULL) { 245 241 if (s->next == rose_neigh) { 246 242 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); 251 243 return; 252 244 } 253 245 ··· 323 331 if (rose_node->neighbour[i] == rose_neigh) { 324 332 rose_neigh->count--; 325 333 326 - if (rose_neigh->count == 0 && rose_neigh->use == 0) 334 + if (rose_neigh->count == 0 && rose_neigh->use == 0) { 327 335 rose_remove_neigh(rose_neigh); 336 + rose_neigh_put(rose_neigh); 337 + } 328 338 329 339 rose_node->count--; 330 340 ··· 507 513 } 508 514 509 515 rose_remove_neigh(s); 516 + rose_neigh_put(s); 510 517 } 511 518 spin_unlock_bh(&rose_neigh_list_lock); 512 519 spin_unlock_bh(&rose_node_list_lock); ··· 564 569 if (s->use == 0 && !s->loopback) { 565 570 s->count = 0; 566 571 rose_remove_neigh(s); 572 + rose_neigh_put(s); 567 573 } 568 574 } 569 575 ··· 1297 1301 rose_neigh = rose_neigh->next; 1298 1302 1299 1303 rose_remove_neigh(s); 1304 + rose_neigh_put(s); 1300 1305 } 1301 1306 1302 1307 while (rose_node != NULL) {