Date: Mon, 16 May 2016 06:32:06 +0000 (UTC) From: Andrew Rybchenko <arybchik@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299903 - head/sys/dev/sfxge/common Message-ID: <201605160632.u4G6W6Y5062741@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: arybchik Date: Mon May 16 06:32:06 2016 New Revision: 299903 URL: https://svnweb.freebsd.org/changeset/base/299903 Log: 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 <rhouldsworth at solarflare.com> Sponsored by: Solarflare Communications, Inc. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D6367 Modified: head/sys/dev/sfxge/common/ef10_nvram.c Modified: head/sys/dev/sfxge/common/ef10_nvram.c ============================================================================== --- head/sys/dev/sfxge/common/ef10_nvram.c Mon May 16 06:30:25 2016 (r299902) +++ head/sys/dev/sfxge/common/ef10_nvram.c Mon May 16 06:32:06 2016 (r299903) @@ -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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605160632.u4G6W6Y5062741>