isci: fix oem parameter validation on single controller skus
[linux/fpc-iii.git] / drivers / pci / vpd.c
blob39b79070335db7f0a5ae040b083bdc457c2f0f44
1 /*
2 * File: vpd.c
3 * Purpose: Provide PCI VPD support
5 * Copyright (C) 2010 Broadcom Corporation.
6 */
8 #include <linux/pci.h>
9 #include <linux/export.h>
11 int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
13 int i;
15 for (i = off; i < len; ) {
16 u8 val = buf[i];
18 if (val & PCI_VPD_LRDT) {
19 /* Don't return success of the tag isn't complete */
20 if (i + PCI_VPD_LRDT_TAG_SIZE > len)
21 break;
23 if (val == rdt)
24 return i;
26 i += PCI_VPD_LRDT_TAG_SIZE +
27 pci_vpd_lrdt_size(&buf[i]);
28 } else {
29 u8 tag = val & ~PCI_VPD_SRDT_LEN_MASK;
31 if (tag == rdt)
32 return i;
34 if (tag == PCI_VPD_SRDT_END)
35 break;
37 i += PCI_VPD_SRDT_TAG_SIZE +
38 pci_vpd_srdt_size(&buf[i]);
42 return -ENOENT;
44 EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
46 int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
47 unsigned int len, const char *kw)
49 int i;
51 for (i = off; i + PCI_VPD_INFO_FLD_HDR_SIZE <= off + len;) {
52 if (buf[i + 0] == kw[0] &&
53 buf[i + 1] == kw[1])
54 return i;
56 i += PCI_VPD_INFO_FLD_HDR_SIZE +
57 pci_vpd_info_field_size(&buf[i]);
60 return -ENOENT;
62 EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);