From nobody@FreeBSD.org  Wed May 29 18:32:13 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id CB6141C9
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 May 2013 18:32:13 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.FreeBSD.org (oldred.freebsd.org [8.8.178.121])
	by mx1.freebsd.org (Postfix) with ESMTP id BEA27F5B
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 May 2013 18:32:13 +0000 (UTC)
Received: from oldred.FreeBSD.org ([127.0.1.6])
	by oldred.FreeBSD.org (8.14.5/8.14.5) with ESMTP id r4TIWDBt008128
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 29 May 2013 18:32:13 GMT
	(envelope-from nobody@oldred.FreeBSD.org)
Received: (from nobody@localhost)
	by oldred.FreeBSD.org (8.14.5/8.14.5/Submit) id r4TIWDiv008127;
	Wed, 29 May 2013 18:32:13 GMT
	(envelope-from nobody)
Message-Id: <201305291832.r4TIWDiv008127@oldred.FreeBSD.org>
Date: Wed, 29 May 2013 18:32:13 GMT
From: hardik mehta <rometoroam@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Invalid index calucation in netmap macro expansion 
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         179083
>Category:       kern
>Synopsis:       [netmap] [patch] Invalid index calucation in netmap macro expansion
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 29 18:40:00 UTC 2013
>Closed-Date:    Thu May 30 07:58:41 UTC 2013
>Last-Modified:  Thu May 30 08:00:01 UTC 2013
>Originator:     hardik mehta
>Release:        9.1
>Organization:
nik
>Environment:
FreeBSD pcthw21 9.1-RELEASE FreeBSD 9.1-RELEASE
[hmehta@pcthw21 ~]$ sysctl kern.osreldate
kern.osreldate: 901000
>Description:

#define NETMAP_BUF(ring, index)				\
	((char *)(ring) + (ring)->buf_ofs + ((index)*(ring)->nr_buf_size))

In this macro index passed on should be the same as buf_idx from slot structure pointed by ring->cur. As shown in example code instead of using buf_idx pointed of slot structure pointed by ring->cur it uses direct index. Macro should be then expanded as 
#define NETMAP_BUF(ring, index)				\
	((char *)(ring) + (ring)->buf_ofs + ((ring)->slot[index].buf_idx*(ring)->nr_buf_size))
>How-To-Repeat:

>Fix:
define 
#define NETMAP_BUF(ring, index)				\
	((char *)(ring) + (ring)->buf_ofs + ((ring)->slot[index].buf_idx*(ring)->nr_buf_size))

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu May 30 07:43:27 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=179083 
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Thu May 30 07:58:15 UTC 2013 
State-Changed-Why:  
apparently the code is correct and the comments are wrong.  The 
comments will be fixed soon. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=179083 

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/179083: [netmap] [patch] Invalid index calucation in netmap
 macro expansion
Date: Thu, 30 May 2013 02:58:04 -0500

 ----- Forwarded message from Luigi Rizzo <rizzo@iet.unipi.it> -----
 
 Date: Thu, 30 May 2013 09:57:15 +0200
 From: Luigi Rizzo <rizzo@iet.unipi.it>
 To: freebsd-bugs@freebsd.org, freebsd-net@freebsd.org
 Subject: Re: kern/179083: [netmap] [patch] Invalid index calucation in netmap macro expansion
 User-Agent: Mutt/1.5.20 (2009-06-14)
 
 Thanks for the report.
 
 The macro is correct as implemented.
 The problem, in case, is in the description in netmap_user.h which
 is confusing and should be improved as follows:
 
 -*      char *buf = NETMAP_BUF(ring, index) returns a pointer to
 -*              the i-th buffer
 +*      char *buf = NETMAP_BUF(ring, x) returns a pointer to
 +*              the buffer numbered 'x'
 
 This will be committed soon, so please close the PR
 
 cheers
 luigi
 
 ----- End forwarded message -----
>Unformatted:
