The format of the PCI/PCIe Vital Product Data has been standardized in the PCI-2.2 standard. This format is quite strict and easy to parse.
The parser currently used in the PCI driver is based on a state machine, with tags and parsed data controlling the state changes.
The flexibility of this parser is actually not required. It can lead to the acceptance of non-conformant data as valid VPD, unless restrictions are applied on the permitted sequence of states. It does not detect issues like multiple ident tags, R/O data following the checksum, multiple or unordered R/O and R/W tags, etc.
The reason for the rewrite was a panic reported due to bogus/invalid VPD data provided by an Intel X520 LAN adapter.
Analysis of the VPD code to make it more robust lead me to believe that it was easier to write a "narrow" parser than to restrict the flexible state machine to detect and reject non-well-formed data. A number of restrictions have already been added, but they make the state machine ever more complex and harder to understand.
This patch provides a rewrite of the VPD parser based on the valid structure of the VPD data (ident, R/O data, optional R/W data, end tag). It has been verified to return identical parsed data as the current implementation for the example VPD data in the PCI standard.
It is strict in the sense that it detects and rejects any deviation from a well-formed VPD structure.
The dummy test data contained in this patch is only meant to ease review and verification of the patch.
This version of the patch is not meant to be committed. If it is accepted I'll clean-up the patch to remove the dummy code and a few commented out debug printf()s, for example. The diagnostics could be further improved, but they do already catch more cases than the currently committed code does.