From bbdda93be2f0bfefe91466b398fe42700a6ea284 Mon Sep 17 00:00:00 2001 From: riastradh Date: Wed, 16 Jun 2021 00:21:17 +0000 Subject: if_attach and if_initialize cannot fail, don't test return value These were originally made failable back in 2017 when if_initialize allocated a softint in every interface for link state changes, so that it could fail gracefully instead of panicking: https://mail-index.NetBSD.org/source-changes/2017/10/23/msg089053.html However, this spawned many seldom- or never-tested error branches, which are risky to have around. And that softint in every interface has since been replaced by a single global workqueue, because link state changes require thread context but not low latency or high throughput: https://mail-index.NetBSD.org/source-changes/2020/02/06/msg113759.html So there is no longer any reason for if_initialize to fail. (The subroutine if_stats_init can't fail because percpu_alloc can't fail either.) There is a snag: the softint_establish in if_percpuq_create could fail, potentially leading to bad consequences later on trying to use the softint. This change doesn't introduce any new bugs because of the snag -- if_percpuq_attach was already broken. However, the snag can be better addressed without spawning error branches, either by using a single softint or making softints less scarce. (Separate commit will change the signatures of if_attach and if_initialize to return void, scheduled to ride whatever is the next convenient kernel bump.) Patch and testing on amd64 and evbmips64-eb by maya@; commit message soliloquy, and compile-testing on evbppc/i386/earmv7hf, by me. --- sys/net/if_loop.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'sys/net/if_loop.c') diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index 6e4c8dcf484..ff2a401d53a 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -1,4 +1,4 @@ -/* $NetBSD: if_loop.c,v 1.112 2020/10/14 16:10:32 roy Exp $ */ +/* $NetBSD: if_loop.c,v 1.113 2021/06/16 00:21:19 riastradh Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.112 2020/10/14 16:10:32 roy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.113 2021/06/16 00:21:19 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -175,7 +175,6 @@ static int loop_clone_create(struct if_clone *ifc, int unit) { struct ifnet *ifp; - int rv; ifp = if_alloc(IFT_LOOP); @@ -198,11 +197,7 @@ loop_clone_create(struct if_clone *ifc, int unit) IFQ_SET_READY(&ifp->if_snd); if (unit == 0) lo0ifp = ifp; - rv = if_initialize(ifp); - if (rv != 0) { - if_free(ifp); - return rv; - } + if_initialize(ifp); ifp->if_link_state = LINK_STATE_UP; if_alloc_sadl(ifp); bpf_attach(ifp, DLT_NULL, sizeof(u_int)); -- cgit