diff options
author | rwatson <rwatson@FreeBSD.org> | 2006-08-09 16:30:26 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2006-08-09 16:30:26 +0000 |
commit | 440c15fc675beadbaf4ffa12a4932478fa2c5e4b (patch) | |
tree | cff92c843e25a88a2844041014d06fb78c73f218 /sys/net/bpf.c | |
parent | 7f9e892ea9ffc1021556a11a2be7eae73baeafe9 (diff) | |
download | FreeBSD-src-440c15fc675beadbaf4ffa12a4932478fa2c5e4b.zip FreeBSD-src-440c15fc675beadbaf4ffa12a4932478fa2c5e4b.tar.gz |
Since bpf_allocbufs() uses malloc() with M_WAITOK, don't check return
values for NULL or return an error state. Assert that all three bpf
buffer pointers are NULL before starting.
MFC after: 1 week
Diffstat (limited to 'sys/net/bpf.c')
-rw-r--r-- | sys/net/bpf.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 9a2f104..12c3052 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -93,7 +93,7 @@ static LIST_HEAD(, bpf_if) bpf_iflist; static struct mtx bpf_mtx; /* bpf global lock */ static int bpf_bpfd_cnt; -static int bpf_allocbufs(struct bpf_d *); +static void bpf_allocbufs(struct bpf_d *); static void bpf_attachd(struct bpf_d *, struct bpf_if *); static void bpf_detachd(struct bpf_d *); static void bpf_freed(struct bpf_d *); @@ -1093,7 +1093,6 @@ static int bpf_setif(struct bpf_d *d, struct ifreq *ifr) { struct bpf_if *bp; - int error; struct ifnet *theywant; theywant = ifunit(ifr->ifr_name); @@ -1106,11 +1105,8 @@ bpf_setif(struct bpf_d *d, struct ifreq *ifr) * If we're already attached to requested interface, * just flush the buffer. */ - if (d->bd_sbuf == NULL) { - error = bpf_allocbufs(d); - if (error != 0) - return (error); - } + if (d->bd_sbuf == NULL) + bpf_allocbufs(d); if (bp != d->bd_bif) { if (d->bd_bif) /* @@ -1459,21 +1455,18 @@ catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, /* * Initialize all nonzero fields of a descriptor. */ -static int +static void bpf_allocbufs(struct bpf_d *d) { - d->bd_fbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, M_WAITOK); - if (d->bd_fbuf == NULL) - return (ENOBUFS); + KASSERT(d->bd_fbuf == NULL, ("bpf_allocbufs: bd_fbuf != NULL")); + KASSERT(d->bd_sbuf == NULL, ("bpf_allocbufs: bd_sbuf != NULL")); + KASSERT(d->bd_hbuf == NULL, ("bpf_allocbufs: bd_hbuf != NULL")); + + d->bd_fbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, M_WAITOK); d->bd_sbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, M_WAITOK); - if (d->bd_sbuf == NULL) { - free(d->bd_fbuf, M_BPF); - return (ENOBUFS); - } d->bd_slen = 0; d->bd_hlen = 0; - return (0); } /* |