Date: Tue, 2 Apr 2019 09:33:31 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r345795 - stable/11/sys/net Message-ID: <201904020933.x329XVxV054337@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ae Date: Tue Apr 2 09:33:30 2019 New Revision: 345795 URL: https://svnweb.freebsd.org/changeset/base/345795 Log: MFC r345292: Convert allocation of bpf_if in bpfattach2 from M_NOWAIT to M_WAITOK and remove possible panic condition. It is already allowed to sleep in bpfattach[2], since BPF_LOCK was converted to SX lock in r332388. Also move KASSERT() to the top of function and make full initialization before bpf_if will be linked to BPF's list of interfaces. Modified: stable/11/sys/net/bpf.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/net/bpf.c ============================================================================== --- stable/11/sys/net/bpf.c Tue Apr 2 09:31:38 2019 (r345794) +++ stable/11/sys/net/bpf.c Tue Apr 2 09:33:30 2019 (r345795) @@ -2561,24 +2561,22 @@ bpfattach2(struct ifnet *ifp, u_int dlt, u_int hdrlen, { struct bpf_if *bp; - bp = malloc(sizeof(*bp), M_BPF, M_NOWAIT | M_ZERO); - if (bp == NULL) - panic("bpfattach"); + KASSERT(*driverp == NULL, ("bpfattach2: driverp already initialized")); + bp = malloc(sizeof(*bp), M_BPF, M_WAITOK | M_ZERO); + + rw_init(&bp->bif_lock, "bpf interface lock"); LIST_INIT(&bp->bif_dlist); LIST_INIT(&bp->bif_wlist); bp->bif_ifp = ifp; bp->bif_dlt = dlt; - rw_init(&bp->bif_lock, "bpf interface lock"); - KASSERT(*driverp == NULL, ("bpfattach2: driverp already initialized")); + bp->bif_hdrlen = hdrlen; bp->bif_bpf = driverp; *driverp = bp; BPF_LOCK(); LIST_INSERT_HEAD(&bpf_iflist, bp, bif_next); BPF_UNLOCK(); - - bp->bif_hdrlen = hdrlen; if (bootverbose && IS_DEFAULT_VNET(curvnet)) if_printf(ifp, "bpf attached\n");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904020933.x329XVxV054337>