From nobody@FreeBSD.org  Thu Jan 19 18:20:43 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id CE217106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 19 Jan 2012 18:20:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id BD9D68FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 19 Jan 2012 18:20:43 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0JIKhmo065021
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 19 Jan 2012 18:20:43 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0JIKh6J065020;
	Thu, 19 Jan 2012 18:20:43 GMT
	(envelope-from nobody)
Message-Id: <201201191820.q0JIKh6J065020@red.freebsd.org>
Date: Thu, 19 Jan 2012 18:20:43 GMT
From: Chuck Tuffli <chuck@tuffli.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Fix pci_get_vpd_readonly_method
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         164313
>Category:       kern
>Synopsis:       [pci] [patch] Fix pci_get_vpd_readonly_method
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 19 18:30:10 UTC 2012
>Closed-Date:    Mon Mar 04 18:57:59 UTC 2013
>Last-Modified:  Mon Mar 04 18:57:59 UTC 2013
>Originator:     Chuck Tuffli
>Release:        8-stable
>Organization:
>Environment:
FreeBSD tm4.lab.rv.emulex.com 8.2-STABLE FreeBSD 8.2-STABLE #32 r229528M: Thu Jan 19 09:42:27 PST 2012     ctuffli@rvctuffli.lab.rv.emulex.com:/usr/home/ctuffli/dev/releng_8/obj/usr/home/ctuffli/dev/releng_8/src/sys/DTRACE  amd64

>Description:
The pci_get_vpd_readonly_method function always returns ENXIO because it is missing a break statement if the keyword is found in the VPD read-only section. Without the break statement, the for loop continues checking the remaining keywords even if it discovers the desired key, and it exits with i == cfg->vpd.vpd_rocnt. This indistinguishable from not finding the desired key.
>How-To-Repeat:
Issue pci_get_vpd_readonly(dev, "SN", &str) to any device with a valid VPD
>Fix:
Add a break to the "if" statement

Index: sys/dev/pci/pci.c
===================================================================
--- sys/dev/pci/pci.c	(revision 229528)
+++ sys/dev/pci/pci.c	(working copy)
@@ -1076,6 +1076,7 @@
 		if (memcmp(kw, cfg->vpd.vpd_ros[i].keyword,
 		    sizeof(cfg->vpd.vpd_ros[i].keyword)) == 0) {
 			*vptr = cfg->vpd.vpd_ros[i].value;
+			break;
 		}
 
 	if (i != cfg->vpd.vpd_rocnt)


>Release-Note:
>Audit-Trail:

From: John Baldwin <jhb@FreeBSD.org>
To: bug-followup@FreeBSD.org, chuck@tuffli.net
Cc:  
Subject: Re: kern/164313: Fix pci_get_vpd_readonly_method
Date: Thu, 19 Jan 2012 14:41:45 -0500

 Huh.  Might be even simpler to just return instead of breaking out of 
 the loop once vptr is found.
 
 Index: pci.c
 ===================================================================
 --- pci.c	(revision 230331)
 +++ pci.c	(working copy)
 @@ -1136,11 +1136,9 @@ pci_get_vpd_readonly_method(device_t dev, device_t
   		if (memcmp(kw, cfg->vpd.vpd_ros[i].keyword,
   		    sizeof(cfg->vpd.vpd_ros[i].keyword)) == 0) {
   			*vptr = cfg->vpd.vpd_ros[i].value;
 +			return (0);
   		}
 
 -	if (i != cfg->vpd.vpd_rocnt)
 -		return (0);
 -
   	*vptr = NULL;
   	return (ENXIO);
   }
 
 Does this work for you as well?
 
 -- 
 John Baldwin
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Thu Jan 19 21:38:27 UTC 2012 
State-Changed-Why:  
Fix committed to HEAD. 


Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Thu Jan 19 21:38:27 UTC 2012 
Responsible-Changed-Why:  
Fix committed to HEAD. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/164313: commit references a PR
Date: Thu, 19 Jan 2012 21:38:29 +0000 (UTC)

 Author: jhb
 Date: Thu Jan 19 21:38:19 2012
 New Revision: 230340
 URL: http://svn.freebsd.org/changeset/base/230340
 
 Log:
   Properly return success once a matching VPD entry is found in
   pci_get_vpd_readonly_method().  Previously the loop was always running
   to completion and falling through to failing with ENXIO.
   
   PR:		kern/164313
   Submitted by:	Chuck Tuffli  chuck tuffli net
   MFC after:	1 week
 
 Modified:
   head/sys/dev/pci/pci.c
 
 Modified: head/sys/dev/pci/pci.c
 ==============================================================================
 --- head/sys/dev/pci/pci.c	Thu Jan 19 20:31:29 2012	(r230339)
 +++ head/sys/dev/pci/pci.c	Thu Jan 19 21:38:19 2012	(r230340)
 @@ -1136,11 +1136,9 @@ pci_get_vpd_readonly_method(device_t dev
  		if (memcmp(kw, cfg->vpd.vpd_ros[i].keyword,
  		    sizeof(cfg->vpd.vpd_ros[i].keyword)) == 0) {
  			*vptr = cfg->vpd.vpd_ros[i].value;
 +			return (0);
  		}
  
 -	if (i != cfg->vpd.vpd_rocnt)
 -		return (0);
 -
  	*vptr = NULL;
  	return (ENXIO);
  }
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Mon Mar 4 18:57:47 UTC 2013 
State-Changed-Why:  
Fix merged to 8 and 9 a while ago. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164313 
>Unformatted:
