From patchwork Thu Jul 15 21:59:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1505927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Qo+O7sF/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GQpFy4gcKz9sWq for ; Fri, 16 Jul 2021 08:00:22 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbhGOWDN (ORCPT ); Thu, 15 Jul 2021 18:03:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:49196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbhGOWDI (ORCPT ); Thu, 15 Jul 2021 18:03:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E8C706117A; Thu, 15 Jul 2021 22:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626386415; bh=VUyVyFpC1GhZ1oTojiMVCfJ51v4Scqb1UgexiQO2eqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qo+O7sF/JuPIvfZZr6FZigvTFJ20HZCid/8TkyIdk03wkOo/A4ZARV9H67FicBJg/ W3B6JvOr1UJF0OaYJifXCQFDoTLpmbg0npQbuZa7VJiSXf4Ly3Wfa2oOgnyKYsxham z6CURXh72qCm4BnBwKbiPyxEGbgdzeKy9DBh6C8ESNqL2nXV0UA4dm4A1pvJo/unI7 natCIzZ8DaCuILm2axUo0FLFrFXihM/O92lPXTfucqb2NJTYDC8MYmwsetES++r/dH v9JyNwqUffvCq7xMkbtaV4/3YdhTyh+oGN2/zrXO1o0bAyUvys4E3b8n44/O2SIygT a2jrdH4cM+jSQ== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 1/5] PCI/VPD: Correct diagnostic for VPD read failure Date: Thu, 15 Jul 2021 16:59:55 -0500 Message-Id: <20210715215959.2014576-2-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210715215959.2014576-1-helgaas@kernel.org> References: <20210715215959.2014576-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously, when a VPD read failed, we warned about an "invalid large VPD tag". Warn about the VPD read failure instead. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 26bf7c877de5..7bfb8fc4251b 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -92,8 +92,8 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) (tag == PCI_VPD_LTIN_RW_DATA)) { if (pci_read_vpd(dev, off+1, 2, &header[1]) != 2) { - pci_warn(dev, "invalid large VPD tag %02x size at offset %zu", - tag, off + 1); + pci_warn(dev, "failed VPD read at offset %zu", + off + 1); return 0; } off += PCI_VPD_LRDT_TAG_SIZE + From patchwork Thu Jul 15 21:59:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1505929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=eDmjtrEH; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GQpFz0C8Lz9sWw for ; Fri, 16 Jul 2021 08:00:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231462AbhGOWDO (ORCPT ); Thu, 15 Jul 2021 18:03:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:49278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbhGOWDK (ORCPT ); Thu, 15 Jul 2021 18:03:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 953A0610C7; Thu, 15 Jul 2021 22:00:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626386416; bh=7ik2o5DzC87ePSGVyDb14Q44TcV8OQwmLXrv0d+tdfc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eDmjtrEHE9Rq6vzvDNNwSWbXhht3guH2k0aK6Tzw5TO18CodMzfOqHCprGmIf3U0z ee5u7+bd7+7vM1D8oWmtm2Y+sTXGvZnTExmLOrQL29ALoH0hrIzQTFOKASndXhujBo ECEQAGOkQFIXNFpidNlwXEhgzKbLz7E6iE9Juh2bjHqliNjISSMICP6wVruPQD8jtb bvXQHX7HlWhAOuprVyYk5ckse7/9nDWKvK7n7mRsW3gtMXH2qw+hrDIAGldnLhS/cw T9wAGyznvoIzKRqhBpQjMjcvi6+msl7MRmrBWWyQwJrEqYM4j5oIP7vykRKVVrGaz8 6zhALQluaI/6A== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 2/5] PCI/VPD: Check Resource tags against those valid for type Date: Thu, 15 Jul 2021 16:59:56 -0500 Message-Id: <20210715215959.2014576-3-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210715215959.2014576-1-helgaas@kernel.org> References: <20210715215959.2014576-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously, we checked for PCI_VPD_STIN_END, PCI_VPD_LTIN_ID_STRING, etc., outside the Large and Small Resource cases, so we checked Large Resource tags against a Small Resource name and vice versa. Move these tests into the Large and Small Resource cases, so we only check PCI_VPD_STIN_END for Small Resources and PCI_VPD_LTIN_* for Large Resources. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 7bfb8fc4251b..9b54dd95e42c 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -98,24 +98,18 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) } off += PCI_VPD_LRDT_TAG_SIZE + pci_vpd_lrdt_size(header); + } else { + pci_warn(dev, "invalid large VPD tag %02x at offset %zu", + tag, off); + return 0; } } else { /* Short Resource Data Type Tag */ off += PCI_VPD_SRDT_TAG_SIZE + pci_vpd_srdt_size(header); tag = pci_vpd_srdt_tag(header); - } - - if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ - return off; - - if ((tag != PCI_VPD_LTIN_ID_STRING) && - (tag != PCI_VPD_LTIN_RO_DATA) && - (tag != PCI_VPD_LTIN_RW_DATA)) { - pci_warn(dev, "invalid %s VPD tag %02x at offset %zu", - (header[0] & PCI_VPD_LRDT) ? "large" : "short", - tag, off); - return 0; + if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ + return off; } } return 0; From patchwork Thu Jul 15 21:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1505930 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=frF1Rl49; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GQpFz2l9fz9sX3 for ; Fri, 16 Jul 2021 08:00:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231342AbhGOWDO (ORCPT ); Thu, 15 Jul 2021 18:03:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:49298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231631AbhGOWDM (ORCPT ); Thu, 15 Jul 2021 18:03:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2967A613CF; Thu, 15 Jul 2021 22:00:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626386418; bh=uuqbgYsdR09711D4OQRZWd0so/Mh3lkDLC8k/5VKZYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=frF1Rl49DC1bxW4jo6t7Zqy0v4cEXAMcfgZJ7Yy3XDLE/NunwuRLtKzvNSSNQ2BVV 3hnpkrb6D9h+zxncKwpIeG245Gc5cxPSDFn4VnEInWHsdWBfOZnELi4xP/XYjBcK0H 7MDYuRKpKyHHwI1HiL2ca2U/bNzIcwuyoz+8Ms2NmzRy7BG2DVsUg0rnSYu67cCnzy iQnIxLn2IBqGVfCKWspQ17nQImmFougbdvj5GrGWS4OeQefH7d3IqXMZ7CoeNkJlHI ASzPd/2gj4GwNT324ZALpyT4+VG8velgVS8gSKfPPWDaxXwP2lW4FazIGIFpc9QVSA 8i+cUwMVz1NIw== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 3/5] PCI/VPD: Consolidate missing EEPROM checks Date: Thu, 15 Jul 2021 16:59:57 -0500 Message-Id: <20210715215959.2014576-4-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210715215959.2014576-1-helgaas@kernel.org> References: <20210715215959.2014576-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas A missing VPD EEPROM typically reads as either all 0xff or all zeroes. Both cases lead to invalid VPD resource items. A 0xff tag would be a Large Resource with length 0xffff (65535). That's invalid because VPD can only be 32768 bytes, limited by the size of the address register in the VPD Capability. A VPD that reads as all zeroes is also invalid because a 0x00 tag is a Small Resource with length 0, which would result in an item of length 1. This isn't explicitly illegal in PCIe r5.0, sec 6.28, but the format is derived from PNP ISA, which *does* say "a small resource data type may be 2-8 bytes in size" (Plug and Play ISA v1.0a, sec 6.2.2. Check for these invalid tags and return VPD size of zero if we find them. If they occur at the beginning of VPD, assume it's the result of a missing EEPROM. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 9b54dd95e42c..9c2744d79b53 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -77,11 +77,7 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) while (off < old_size && pci_read_vpd(dev, off, 1, header) == 1) { unsigned char tag; - - if (!header[0] && !off) { - pci_info(dev, "Invalid VPD tag 00, assume missing optional VPD EPROM\n"); - return 0; - } + size_t size; if (header[0] & PCI_VPD_LRDT) { /* Large Resource Data Type Tag */ @@ -96,8 +92,16 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) off + 1); return 0; } - off += PCI_VPD_LRDT_TAG_SIZE + - pci_vpd_lrdt_size(header); + size = pci_vpd_lrdt_size(header); + + /* + * Missing EEPROM may read as 0xff. + * Length of 0xffff (65535) cannot be valid + * because VPD can't be that large. + */ + if (size > PCI_VPD_MAX_SIZE) + goto error; + off += PCI_VPD_LRDT_TAG_SIZE + size; } else { pci_warn(dev, "invalid large VPD tag %02x at offset %zu", tag, off); @@ -105,14 +109,28 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) } } else { /* Short Resource Data Type Tag */ - off += PCI_VPD_SRDT_TAG_SIZE + - pci_vpd_srdt_size(header); tag = pci_vpd_srdt_tag(header); + size = pci_vpd_srdt_size(header); + + /* + * Missing EEPROM may read as 0x00. A small item + * must be at least 2 bytes. + */ + if (size == 0) + goto error; + + off += PCI_VPD_SRDT_TAG_SIZE + size; if (tag == PCI_VPD_STIN_END) /* End tag descriptor */ return off; } } return 0; + +error: + pci_info(dev, "invalid VPD tag %#04x at offset %zu%s\n", + header[0], off, off == 0 ? + "; assume missing optional EEPROM" : ""); + return 0; } /* From patchwork Thu Jul 15 21:59:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1505931 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=fhLANE8h; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GQpFz5jkFz9sX5 for ; Fri, 16 Jul 2021 08:00:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231624AbhGOWDO (ORCPT ); Thu, 15 Jul 2021 18:03:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:49322 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231685AbhGOWDN (ORCPT ); Thu, 15 Jul 2021 18:03:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD94560FE7; Thu, 15 Jul 2021 22:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626386420; bh=7GX89LyvSQPClxnegp6N1W9nDIfrwiEDYQISro10bos=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fhLANE8hEbxYfivzMrReud/kBGHjRBwqNSyA621Q5ERlu9GY0VyZamUdiRr8gNbvc FD/ue5QAPgZiyK+ITUyhErDE/nirB6+wGGffdL4gnmngIORWHRA8IYN3ITB8cSBbK1 7k8IzddVyzRFVgHqX/SG7Ym9mLHJg4sgExZPtpGQ7ffGuchUxoddPJSt06fnMsZfbh ka3+wws6Hheqq9UvxbSexAEPxbubyU+cy8kC3NAlTQ9hELp4QskCcKDdJpHXJNv5HT oDt6qyr+kDQV3NGnJdawtxlDZRi6nxcGYsI7e27TWN/knTVRrOjFtCAxnxekBRbPIL 5dqbp49Bwtm6w== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 4/5] PCI/VPD: Don't check Large Resource types for validity Date: Thu, 15 Jul 2021 16:59:58 -0500 Message-Id: <20210715215959.2014576-5-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210715215959.2014576-1-helgaas@kernel.org> References: <20210715215959.2014576-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas VPD consists of a series of Small and Large Resources. Computing the size of VPD requires only the length of each, which is specified in the generic tag of each resource. We only expect to see ID_STRING, RO_DATA, and RW_DATA in VPD, but it's not a problem if it contains other resource types. Drop the validity checking of Large Resource items. Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index 9c2744d79b53..d7a4a9f05bd6 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -82,31 +82,22 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) if (header[0] & PCI_VPD_LRDT) { /* Large Resource Data Type Tag */ tag = pci_vpd_lrdt_tag(header); - /* Only read length from known tag items */ - if ((tag == PCI_VPD_LTIN_ID_STRING) || - (tag == PCI_VPD_LTIN_RO_DATA) || - (tag == PCI_VPD_LTIN_RW_DATA)) { - if (pci_read_vpd(dev, off+1, 2, - &header[1]) != 2) { - pci_warn(dev, "failed VPD read at offset %zu", - off + 1); - return 0; - } - size = pci_vpd_lrdt_size(header); - - /* - * Missing EEPROM may read as 0xff. - * Length of 0xffff (65535) cannot be valid - * because VPD can't be that large. - */ - if (size > PCI_VPD_MAX_SIZE) - goto error; - off += PCI_VPD_LRDT_TAG_SIZE + size; - } else { - pci_warn(dev, "invalid large VPD tag %02x at offset %zu", - tag, off); + if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) { + pci_warn(dev, "failed VPD read at offset %zu", + off + 1); return 0; } + size = pci_vpd_lrdt_size(header); + + /* + * Missing EEPROM may read as 0xff. Length of + * 0xffff (65535) cannot be valid because VPD can't + * be that large. + */ + if (size > PCI_VPD_MAX_SIZE) + goto error; + + off += PCI_VPD_LRDT_TAG_SIZE + size; } else { /* Short Resource Data Type Tag */ tag = pci_vpd_srdt_tag(header); From patchwork Thu Jul 15 21:59:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1505932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=lFUDQEkv; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4GQpG01knnz9sWc for ; Fri, 16 Jul 2021 08:00:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231459AbhGOWDP (ORCPT ); Thu, 15 Jul 2021 18:03:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:49404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231247AbhGOWDP (ORCPT ); Thu, 15 Jul 2021 18:03:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 559A1610C7; Thu, 15 Jul 2021 22:00:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626386421; bh=2277Bu4KNEpmiIPbnq6vMfKjJ0AKuRTGi1urAIdLul0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lFUDQEkvMxuvKaz4RBDmT1SfztVwhzpSZYWTUvuCnFPjfG87uSRfejJS9gg6Q8WYJ 3kLYZSgBJ37gnTqBc+4DR8lyGrcAJ5l6NT4mPQ1nFtM2oe8jzFHAm0qydGL0ZueuzR vLAfoGPjdWS8MSrSiJ5Cfm6W2s1fVQ4HVxL9/b9RT58YpfpF82hoGBuwwYtO69K7uW tG/bTlu1sg6iT04Ru6zlPf+GZf3n+mL5zna71QXduLjtoqppgwdHkuL4uIV7S0JngQ n2X9b4MoNjD8RRijVzmeCpA6aJuSEXV1Aun8HN65/w2hpLtb9VNuZ1WHZwEHA21A+7 dwXTCQWWZ4gvw== From: Bjorn Helgaas To: Heiner Kallweit Cc: Hannes Reinecke , linux-pci@vger.kernel.org, Bjorn Helgaas Subject: [PATCH 5/5] PCI/VPD: Allow access to valid parts of VPD if some is invalid Date: Thu, 15 Jul 2021 16:59:59 -0500 Message-Id: <20210715215959.2014576-6-helgaas@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210715215959.2014576-1-helgaas@kernel.org> References: <20210715215959.2014576-1-helgaas@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Bjorn Helgaas Previously, if we found any error in the VPD, we returned size 0, which prevents access to all of VPD. But there may be valid resources in VPD before the error, and there's no reason to prevent access to those. "off" covers only VPD resources known to have valid header tags. In case of error, return "off" (which may be zero if we haven't found any valid header tags at all). Signed-off-by: Bjorn Helgaas Reviewed-by: Hannes Reinecke --- drivers/pci/vpd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c index d7a4a9f05bd6..92acbbcc8059 100644 --- a/drivers/pci/vpd.c +++ b/drivers/pci/vpd.c @@ -85,7 +85,7 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) if (pci_read_vpd(dev, off + 1, 2, &header[1]) != 2) { pci_warn(dev, "failed VPD read at offset %zu", off + 1); - return 0; + return off; } size = pci_vpd_lrdt_size(header); @@ -115,13 +115,13 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size) return off; } } - return 0; + return off; error: pci_info(dev, "invalid VPD tag %#04x at offset %zu%s\n", header[0], off, off == 0 ? "; assume missing optional EEPROM" : ""); - return 0; + return off; } /*