Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 May 2012 22:28:46 +0000 (UTC)
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r236262 - head/sys/net
Message-ID:  <201205292228.q4TMSknT006806@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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();



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201205292228.q4TMSknT006806>