From patchwork Tue Jan 12 14:42:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 8017981 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C43759F6FA for ; Tue, 12 Jan 2016 14:43:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECFBD203C2 for ; Tue, 12 Jan 2016 14:43:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE933203E1 for ; Tue, 12 Jan 2016 14:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965048AbcALOmi (ORCPT ); Tue, 12 Jan 2016 09:42:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:60796 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964929AbcALOme (ORCPT ); Tue, 12 Jan 2016 09:42:34 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 74237AC50; Tue, 12 Jan 2016 14:42:31 +0000 (UTC) From: Hannes Reinecke To: Bjorn Helgaas Cc: Alexander Duyck , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Babu Moger , Hannes Reinecke , Hannes Reinecke Subject: [PATCH 3/3] pci: set VPD size to '0' if PCI_VPD_FLAGS_VPD_REF_F0 is set Date: Tue, 12 Jan 2016 15:42:30 +0100 Message-Id: <1452609750-90760-4-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1452609750-90760-1-git-send-email-hare@suse.de> References: <1452609750-90760-1-git-send-email-hare@suse.de> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the VPD data is accessed via another PCI function than 0 the access is redirected to function 0. However, we shouldn't calculate the actual size as we did for function 0, as there is no guarantee that function 0 is already initialized and VPD access is very costly and error prone. So to avoid all this we set the size to '0' in sysfs, but only return the valid bytes from the underlying function 0. Cc: Alexander Duyck Cc: Bjorn Helgaas Signed-off-by: Hannes Reinecke --- drivers/pci/access.c | 11 ++++++++++- drivers/pci/pci-sysfs.c | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/drivers/pci/access.c b/drivers/pci/access.c index ce1b0cb..9fe19be 100644 --- a/drivers/pci/access.c +++ b/drivers/pci/access.c @@ -337,9 +337,16 @@ static ssize_t pci_vpd_pci22_read(struct pci_dev *dev, loff_t pos, size_t count, loff_t end = pos + count; u8 *buf = arg; - if (pos < 0 || pos > vpd->base.len || end > vpd->base.len) + if (pos < 0) return -EINVAL; + if (end > vpd->base.len) { + if (pos > vpd->base.len) + return 0; + end = vpd->base.len; + count = end - pos; + } + if (mutex_lock_killable(&vpd->lock)) return -EINTR; @@ -554,6 +561,8 @@ int pci_vpd_pci22_init(struct pci_dev *dev) dev->vpd = &vpd->base; if (!(dev->dev_flags & PCI_DEV_FLAGS_VPD_REF_F0)) vpd->base.len = pci_vpd_pci22_size(dev); + else + vpd->base.len = 0; return 0; } diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index eead54c..de327c3 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -772,10 +772,12 @@ static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj, struct pci_dev *dev = to_pci_dev(container_of(kobj, struct device, kobj)); - if (off > bin_attr->size) - count = 0; - else if (count > bin_attr->size - off) - count = bin_attr->size - off; + if (bin_attr->size > 0) { + if (off > bin_attr->size) + count = 0; + else if (count > bin_attr->size - off) + count = bin_attr->size - off; + } return pci_read_vpd(dev, off, count, buf); } @@ -787,10 +789,12 @@ static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj, struct pci_dev *dev = to_pci_dev(container_of(kobj, struct device, kobj)); - if (off > bin_attr->size) - count = 0; - else if (count > bin_attr->size - off) - count = bin_attr->size - off; + if (bin_attr->size > 0) { + if (off > bin_attr->size) + count = 0; + else if (count > bin_attr->size - off) + count = bin_attr->size - off; + } return pci_write_vpd(dev, off, count, buf); }