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

Configure Feed

Select the types of activity you want to include in your feed.

ppp: consolidate refcount decrements

ppp_destroy_{channel,interface} are always called after
refcount_dec_and_test().

To reduce boilerplate code, consolidate the decrements by moving them
into the two functions. To reflect this change in semantics, rename the
functions to ppp_release_*.

Signed-off-by: Qingfang Deng <qingfang.deng@linux.dev>
Link: https://patch.msgid.link/20260407094058.257246-1-qingfang.deng@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Qingfang Deng and committed by
Jakub Kicinski
5ecbebc9 84c5a3f0

+28 -33
+28 -33
drivers/net/ppp/ppp_generic.c
··· 286 286 static void ppp_get_stats(struct ppp *ppp, struct ppp_stats *st); 287 287 static int ppp_create_interface(struct net *net, struct file *file, int *unit); 288 288 static void init_ppp_file(struct ppp_file *pf, int kind); 289 - static void ppp_destroy_interface(struct ppp *ppp); 289 + static void ppp_release_interface(struct ppp *ppp); 290 290 static struct ppp *ppp_find_unit(struct ppp_net *pn, int unit); 291 291 static struct channel *ppp_find_channel(struct ppp_net *pn, int unit); 292 292 static int ppp_connect_channel(struct channel *pch, int unit); 293 293 static int ppp_disconnect_channel(struct channel *pch); 294 - static void ppp_destroy_channel(struct channel *pch); 294 + static void ppp_release_channel(struct channel *pch); 295 295 static int unit_get(struct idr *p, void *ptr, int min); 296 296 static int unit_set(struct idr *p, void *ptr, int n); 297 297 static void unit_put(struct idr *p, int n); ··· 407 407 408 408 if (pf) { 409 409 file->private_data = NULL; 410 - if (pf->kind == INTERFACE) { 410 + switch (pf->kind) { 411 + case INTERFACE: 411 412 ppp = PF_TO_PPP(pf); 412 413 rtnl_lock(); 413 414 if (file == ppp->owner) 414 415 unregister_netdevice(ppp->dev); 415 416 rtnl_unlock(); 416 - } 417 - if (refcount_dec_and_test(&pf->refcnt)) { 418 - switch (pf->kind) { 419 - case INTERFACE: 420 - ppp_destroy_interface(PF_TO_PPP(pf)); 421 - break; 422 - case CHANNEL: 423 - ppp_destroy_channel(PF_TO_CHANNEL(pf)); 424 - break; 425 - } 417 + ppp_release_interface(ppp); 418 + break; 419 + case CHANNEL: 420 + ppp_release_channel(PF_TO_CHANNEL(pf)); 421 + break; 426 422 } 427 423 } 428 424 return 0; ··· 671 675 synchronize_rcu(); 672 676 673 677 if (pchb) 674 - if (refcount_dec_and_test(&pchb->file.refcnt)) 675 - ppp_destroy_channel(pchb); 678 + ppp_release_channel(pchb); 676 679 677 680 return -EALREADY; 678 681 } ··· 703 708 synchronize_rcu(); 704 709 705 710 if (pchbb == pch) 706 - if (refcount_dec_and_test(&pch->file.refcnt)) 707 - ppp_destroy_channel(pch); 711 + ppp_release_channel(pch); 708 712 709 - if (refcount_dec_and_test(&pchb->file.refcnt)) 710 - ppp_destroy_channel(pchb); 713 + ppp_release_channel(pchb); 711 714 712 715 return 0; 713 716 } ··· 779 786 break; 780 787 err = ppp_bridge_channels(pch, pchb); 781 788 /* Drop earlier refcount now bridge establishment is complete */ 782 - if (refcount_dec_and_test(&pchb->file.refcnt)) 783 - ppp_destroy_channel(pchb); 789 + ppp_release_channel(pchb); 784 790 break; 785 791 786 792 case PPPIOCUNBRIDGECHAN: ··· 1576 1584 struct ppp *ppp; 1577 1585 1578 1586 ppp = netdev_priv(dev); 1579 - if (refcount_dec_and_test(&ppp->file.refcnt)) 1580 - ppp_destroy_interface(ppp); 1587 + ppp_release_interface(ppp); 1581 1588 } 1582 1589 1583 1590 static int ppp_fill_forward_path(struct net_device_path_ctx *ctx, ··· 3013 3022 pch->file.dead = 1; 3014 3023 wake_up_interruptible(&pch->file.rwait); 3015 3024 3016 - if (refcount_dec_and_test(&pch->file.refcnt)) 3017 - ppp_destroy_channel(pch); 3025 + ppp_release_channel(pch); 3018 3026 } 3019 3027 3020 3028 /* ··· 3394 3404 } 3395 3405 3396 3406 /* 3397 - * Free the memory used by a ppp unit. This is only called once 3398 - * there are no channels connected to the unit and no file structs 3399 - * that reference the unit. 3407 + * Drop a reference to a ppp unit and free its memory if the refcount reaches 3408 + * zero. 3400 3409 */ 3401 - static void ppp_destroy_interface(struct ppp *ppp) 3410 + static void ppp_release_interface(struct ppp *ppp) 3402 3411 { 3412 + if (!refcount_dec_and_test(&ppp->file.refcnt)) 3413 + return; 3414 + 3403 3415 atomic_dec(&ppp_unit_count); 3404 3416 3405 3417 if (!ppp->file.dead || ppp->n_channels) { ··· 3553 3561 wake_up_interruptible(&ppp->file.rwait); 3554 3562 ppp_unlock(ppp); 3555 3563 synchronize_net(); 3556 - if (refcount_dec_and_test(&ppp->file.refcnt)) 3557 - ppp_destroy_interface(ppp); 3564 + ppp_release_interface(ppp); 3558 3565 err = 0; 3559 3566 } 3560 3567 return err; 3561 3568 } 3562 3569 3563 3570 /* 3564 - * Free up the resources used by a ppp channel. 3571 + * Drop a reference to a ppp channel and free its memory if the refcount reaches 3572 + * zero. 3565 3573 */ 3566 - static void ppp_destroy_channel(struct channel *pch) 3574 + static void ppp_release_channel(struct channel *pch) 3567 3575 { 3576 + if (!refcount_dec_and_test(&pch->file.refcnt)) 3577 + return; 3578 + 3568 3579 put_net_track(pch->chan_net, &pch->ns_tracker); 3569 3580 pch->chan_net = NULL; 3570 3581