From owner-svn-src-all@freebsd.org Sat Jun 4 16:26:26 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E1AE9B6A275; Sat, 4 Jun 2016 16:26:26 +0000 (UTC) (envelope-from arybchik@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 94B8E1FBD; Sat, 4 Jun 2016 16:26:26 +0000 (UTC) (envelope-from arybchik@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u54GQPLv035956; Sat, 4 Jun 2016 16:26:25 GMT (envelope-from arybchik@FreeBSD.org) Received: (from arybchik@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u54GQPTi035955; Sat, 4 Jun 2016 16:26:25 GMT (envelope-from arybchik@FreeBSD.org) Message-Id: <201606041626.u54GQPTi035955@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: arybchik set sender to arybchik@FreeBSD.org using -f From: Andrew Rybchenko Date: Sat, 4 Jun 2016 16:26:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r301364 - stable/10/sys/dev/sfxge/common X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 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: Sat, 04 Jun 2016 16:26:27 -0000 Author: arybchik Date: Sat Jun 4 16:26:25 2016 New Revision: 301364 URL: https://svnweb.freebsd.org/changeset/base/301364 Log: MFC r299903 sfxge(4): cleanup: make TLV scans quieter Find end of segments in a more direct way that avoids an error report at the terminator. Submitted by: Richard Houldsworth Sponsored by: Solarflare Communications, Inc. Modified: stable/10/sys/dev/sfxge/common/ef10_nvram.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/dev/sfxge/common/ef10_nvram.c ============================================================================== --- stable/10/sys/dev/sfxge/common/ef10_nvram.c Sat Jun 4 16:25:18 2016 (r301363) +++ stable/10/sys/dev/sfxge/common/ef10_nvram.c Sat Jun 4 16:26:25 2016 (r301364) @@ -901,6 +901,7 @@ ef10_nvram_buffer_find_end( // Read to end of partition tlv_cursor_t cursor; efx_rc_t rc; + uint32_t *segment_used; if ((rc = tlv_init_cursor_from_size(&cursor, (uint8_t *)bufferp, buffer_size)) != 0) { @@ -908,10 +909,31 @@ ef10_nvram_buffer_find_end( goto fail1; } - if ((rc = tlv_require_end(&cursor)) != 0) - goto fail2; + segment_used = cursor.block; - *endp = byte_offset(tlv_last_segment_end(&cursor)+1, cursor.block); + /* + * Go through each segment and check that it has an end tag. If there + * is no end tag then the previous segment was the last valid one, + * so return the used space including that end tag. + */ + while (tlv_tag(&cursor) == TLV_TAG_PARTITION_HEADER) { + if (tlv_require_end(&cursor) != 0) { + if (segment_used == cursor.block) { + /* + * First segment is corrupt, so there is + * no valid data in partition. + */ + rc = EINVAL; + goto fail2; + } + break; + } + segment_used = cursor.end + 1; + + cursor.current = segment_used; + } + /* Return space used (including the END tag) */ + *endp = (segment_used - cursor.block) * sizeof (uint32_t); return (0);