From owner-svn-src-all@FreeBSD.ORG Tue May 29 22:28:47 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id EFC891065674; Tue, 29 May 2012 22:28:46 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DBDC38FC14; Tue, 29 May 2012 22:28:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q4TMSki2006808; Tue, 29 May 2012 22:28:46 GMT (envelope-from jkim@svn.freebsd.org) Received: (from jkim@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4TMSknT006806; Tue, 29 May 2012 22:28:46 GMT (envelope-from jkim@svn.freebsd.org) Message-Id: <201205292228.q4TMSknT006806@svn.freebsd.org> From: Jung-uk Kim Date: Tue, 29 May 2012 22:28:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r236262 - head/sys/net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 May 2012 22:28:47 -0000 Author: jkim Date: Tue May 29 22:28:46 2012 New Revision: 236262 URL: http://svn.freebsd.org/changeset/base/236262 Log: Fix style(9) nits, reduce unnecessary type castings, etc., for bpf_setf(). Modified: head/sys/net/bpf.c Modified: head/sys/net/bpf.c ============================================================================== --- head/sys/net/bpf.c Tue May 29 22:21:53 2012 (r236261) +++ head/sys/net/bpf.c Tue May 29 22:28:46 2012 (r236262) @@ -159,7 +159,7 @@ static void catchpacket(struct bpf_d *, void (*)(struct bpf_d *, caddr_t, u_int, void *, u_int), struct bintime *); static void reset_d(struct bpf_d *); -static int bpf_setf(struct bpf_d *, struct bpf_program *, u_long cmd); +static int bpf_setf(struct bpf_d *, struct bpf_program *, u_long cmd); static int bpf_getdltlist(struct bpf_d *, struct bpf_dltlist *); static int bpf_setdlt(struct bpf_d *, u_int); static void filt_bpfdetach(struct knote *); @@ -1708,6 +1708,10 @@ bpfioctl(struct cdev *dev, u_long cmd, c static int bpf_setf(struct bpf_d *d, struct bpf_program *fp, u_long cmd) { +#ifdef COMPAT_FREEBSD32 + struct bpf_program fp_swab; + struct bpf_program32 *fp32; +#endif struct bpf_insn *fcode, *old; #ifdef BPF_JITTER bpf_jit_filter *jfunc, *ofunc; @@ -1715,10 +1719,8 @@ bpf_setf(struct bpf_d *d, struct bpf_pro size_t size; u_int flen; int need_upgrade; -#ifdef COMPAT_FREEBSD32 - struct bpf_program32 *fp32; - struct bpf_program fp_swab; +#ifdef COMPAT_FREEBSD32 switch (cmd) { case BIOCSETF32: case BIOCSETWF32: @@ -1743,36 +1745,35 @@ bpf_setf(struct bpf_d *d, struct bpf_pro #ifdef BPF_JITTER jfunc = ofunc = NULL; #endif + need_upgrade = 0; /* * Check new filter validness before acquiring any locks. * Allocate memory for new filter, if needed. */ flen = fp->bf_len; - if ((flen > bpf_maxinsns) || ((fp->bf_insns == NULL) && (flen != 0))) + if (flen > bpf_maxinsns || (fp->bf_insns == NULL && flen != 0)) return (EINVAL); - - need_upgrade = 0; size = flen * sizeof(*fp->bf_insns); if (size > 0) { - /* We're setting up new filter. Copy and check actual data */ - fcode = (struct bpf_insn *)malloc(size, M_BPF, M_WAITOK); - if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) != 0 || - bpf_validate(fcode, (int)flen) == 0) { + /* We're setting up new filter. Copy and check actual data. */ + fcode = malloc(size, M_BPF, M_WAITOK); + if (copyin(fp->bf_insns, fcode, size) != 0 || + !bpf_validate(fcode, flen)) { free(fcode, M_BPF); return (EINVAL); } #ifdef BPF_JITTER - /* Filter is copied inside fcode and is perfectly valid */ + /* Filter is copied inside fcode and is perfectly valid. */ jfunc = bpf_jitter(fcode, flen); #endif } BPF_LOCK(); - /* + /* * Set up new filter. - * Protect filter change by interface lock + * Protect filter change by interface lock. * Additionally, we are protected by global lock here. */ if (d->bd_bif != NULL) @@ -1794,9 +1795,9 @@ bpf_setf(struct bpf_d *d, struct bpf_pro if (fcode != NULL) { /* * Do not require upgrade by first BIOCSETF - * (used to set snaplen) by pcap_open_live() + * (used to set snaplen) by pcap_open_live(). */ - if ((d->bd_writer != 0) && (--d->bd_writer == 0)) + if (d->bd_writer != 0 && --d->bd_writer == 0) need_upgrade = 1; CTR4(KTR_NET, "%s: filter function set by pid %d, " "bd_writer counter %d, need_upgrade %d", @@ -1807,14 +1808,14 @@ bpf_setf(struct bpf_d *d, struct bpf_pro if (d->bd_bif != NULL) BPFIF_WUNLOCK(d->bd_bif); if (old != NULL) - free((caddr_t)old, M_BPF); + free(old, M_BPF); #ifdef BPF_JITTER if (ofunc != NULL) bpf_destroy_jit_filter(ofunc); #endif - /* Move d to active readers list */ - if (need_upgrade != 0) + /* Move d to active readers list. */ + if (need_upgrade) bpf_upgraded(d); BPF_UNLOCK();