From patchwork Wed Jun 13 06:29:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 928683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HxPys5Qa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 415H1H2hp9z9ry1 for ; Wed, 13 Jun 2018 16:30:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754462AbeFMGaK (ORCPT ); Wed, 13 Jun 2018 02:30:10 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:42253 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754398AbeFMGaJ (ORCPT ); Wed, 13 Jun 2018 02:30:09 -0400 Received: by mail-pl0-f68.google.com with SMTP id w17-v6so916310pll.9 for ; Tue, 12 Jun 2018 23:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ceyoEb2iFnCMsov7WKpqnq3ZQWP48xDSryOo0rw80To=; b=HxPys5QamxPCrR5IF4tW7+PWQpl62Fg2oqe2Jz49De9/qX1g3PIdIEDcqnTMyge15E BK0IIeiQiuTbCRrGPvnPXmNu7DfdGUSgbCjEGvOyXtYojyIrxZno0ciR16qO9UsT7M/Y fOrjK/DS5NoXn/1eWZcQAfep2vUP8YZ9riC4P1VXvuG05OzZWdJMRKvU4z3BIjs0rjC3 KM2dmWy8467TxrYy5EcYj4Vu77wQeV3p5hLvlBrJHLV2S8krB3ZyPNnnGS3xhcxYvuVv so29THCqFcS4V0N0FXNhe8rOb0FhwlMPsNT89FzvpVhsJ+amPQnkANCdMj4LtOliMoa9 7Cng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ceyoEb2iFnCMsov7WKpqnq3ZQWP48xDSryOo0rw80To=; b=eCWuuXA2RsVnfxgG4OYmvT/GJnQ7UmKy3qbITU+5/80YCrJ6KnXQcpKtrLOyltDQqF BKrRRuaK8LcCl6g6N18d2WIdqWsd8E2MeJd6ivKl0/AVWFsrmtdmDLCDiqB+U95g4XKC 0yv2qgCC1cLX70BJuxmvQZwRQfW+TR/0GXMt8jdiVMCf/Wvdbd2Q77hHIvHxxesaGQQ1 E4F2RjrQNJUUENC2WhPQA+UwyBteHOqPBY21Y+ZTEhanvloK/b3tUNhg8RBHIfOGweNS DBcqrIiW/q8V/MQQdLk/l0z2DQ/wTPRXh6xIP3aNIbGTAbYkaHH1g7E97ZfChnJ36RE/ N4BA== X-Gm-Message-State: APt69E1lcRSQ18XRggongyMFb5UssvSx+NBzHLyyqVlHO/OxazQeyVzH HLSiwZLozbQ79Xv2MnKnMwWA X-Google-Smtp-Source: ADUXVKJJCiYSUUXdti88d0nuq+wYNNSsZFczX+/309cWx1ENZeHEkkrspXUydZcbJjBCF7GGwZFjAA== X-Received: by 2002:a17:902:b216:: with SMTP id t22-v6mr3755597plr.199.1528871409399; Tue, 12 Jun 2018 23:30:09 -0700 (PDT) Received: from mylaptop.nay.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id l23-v6sm2126602pgc.61.2018.06.12.23.30.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 23:30:08 -0700 (PDT) From: Pingfan Liu To: linux-pci@vger.kernel.org Cc: Bjorn Helgaas , Christoph Hellwig , linuxppc-dev@lists.ozlabs.org Subject: [patchV2 1/2] pci: introduce an extra method for matching in pci_driver Date: Wed, 13 Jun 2018 14:29:56 +0800 Message-Id: <1528871397-17917-2-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528871397-17917-1-git-send-email-kernelfans@gmail.com> References: <1528871397-17917-1-git-send-email-kernelfans@gmail.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In __driver_attach(), if a driver matches a device, the device will be appended to the tail of devices_kset, no matter what the probing result of the device. Hence in order to prevent a driver to append a probed device to devices_kset, it requires a correct matching. As for pci, pci driver uses pci_device_id to match a device. But it may be not enough, since there is need for extra info such as pcie, which can not be provided in pci_device_id. Such info is driver specific, and this patch introduces a new method "extra_match" in pci_driver. This is used by next patch. Signed-off-by: Pingfan Liu --- drivers/pci/pci-driver.c | 4 ++++ include/linux/pci.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index b9a1311..151865f 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -273,6 +273,10 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv, if (!found_id && dev->driver_override) found_id = &pci_device_id_any; + /* more strictly matching besides id_table */ + if (drv->extra_match && drv->extra_match(dev) < 0) + found_id = NULL; + return found_id; } diff --git a/include/linux/pci.h b/include/linux/pci.h index 73178a2..6ed960d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -738,10 +738,12 @@ struct pci_error_handlers { struct module; +typedef int (*ematch)(struct pci_dev *pdev); struct pci_driver { struct list_head node; const char *name; const struct pci_device_id *id_table; /* Must be non-NULL for probe to be called */ + ematch extra_match; /* more strictly matching besides id_table */ int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */ void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */ int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */