Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3619566pxb; Mon, 16 Nov 2020 21:49:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHzExtyLcHomT6f+3XsSiIUs+YliOJTwa1fORXlIxZtLvQEgBTeVda9awMfpRhYJzi/rVL X-Received: by 2002:aa7:ca44:: with SMTP id j4mr19727958edt.354.1605592177225; Mon, 16 Nov 2020 21:49:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605592177; cv=none; d=google.com; s=arc-20160816; b=HR3iRfongcYxkoKLYHRK6oD9DNhvywVMvQssjdaPRTfgtnW8VaRIb7LBQDed/whuLa wc0W9OUN2TGPacL8KiFwSF4iF7b8kEOXH9yI7ExpQw6AoSm61FQmz6+0r7x9movpSGHF 2ECAj1gnPqp/bKRJJPiE0bK2XMWrNUsezHQs1vBhlXS0QABKSDtFCQDy6Sz6E1bq999x OUc6CaxfqLoiQNOXlBxqLRBm62PiAMUMiAlz0CtZYOdCUjDB/z5hQF71DPs70tkmRTjm m96j9O3+VtKOJL5+4pXFEmIg21OzGTYM7dJafJdzPOcVgCpnWtvMS95LPJ31a1oCw1NQ /dVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lLOKhmR08M0B/4atKVerRPzwm0RJuJz/KvTr7deGbiY=; b=UyK7VW3Ut045eAJZxRvyNb1Cx0G9uFXo1YWZqt/qvdZtumwdnAynypvPmP3qHHipUU mSZTcfeM3hJ2dl+Chcs3Vz4nnSu/v0je7uHJZtLoSbcLoBGVK/Dsfs7k6eFLhDnElNSD HtcrVmiYy8ksQDJQGev+lsBmubiO8NBWVicp+lnCE6r2G74Z/r5YbYxrsQgucORIgTT3 C+AUn4MsRuHbrp6FZjAP08aqGpQ10ZeVbgnm1ZiIIbTnSF7mb0VKaVRWjIbGVqkZH+zr wufx5BpTIFSNpIvsxYRscbRx8wi0vibPvZJZUmHLxrbNvA6bZ/gcixnYWOQT1QuQRBGN M6gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TdPQIJxs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si6137352edf.583.2020.11.16.21.49.13; Mon, 16 Nov 2020 21:49:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TdPQIJxs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbgKQFo5 (ORCPT + 99 others); Tue, 17 Nov 2020 00:44:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgKQFo4 (ORCPT ); Tue, 17 Nov 2020 00:44:56 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89DF1C0613CF; Mon, 16 Nov 2020 21:44:56 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id i13so15354562pgm.9; Mon, 16 Nov 2020 21:44:56 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=lLOKhmR08M0B/4atKVerRPzwm0RJuJz/KvTr7deGbiY=; b=TdPQIJxsRBlp9yFp8khc/3gjrU3Rs8c9d2Qtnp7wxpbVCVXB75KctfQTgLpTISwXa7 y6iCySS9lFomqIruA5i1k68TPgFAvmiVGfQy+t1NFZgp8/op8S3pUmmShii8IAKj6Y+m EwgWFl0l9+a74b9AExu4CHf3IbeiTj04fOcl/cEl87nm9RGj6RL9+SvKgGNvthDRHOSz VrxRpgxc65/2j39GldFzQ748O5B4Qg8glAPi+TD4XdvfOcEv7E0GH6P/e7XNI23QVJto wlxvcaUKoHvotGlYpOyOV0ktYu+JP49iU5sH9IsO2BPq/DYBpvPULSaAyE6NrtkmfQLP XRFw== 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:mime-version:content-transfer-encoding; bh=lLOKhmR08M0B/4atKVerRPzwm0RJuJz/KvTr7deGbiY=; b=bUR9TaC11SzPDk0egfNb2K0qdMcmKAQXXIJ3gjAmAO88uLaQsvl3L0+52ORQ2Ioe8M 4sx1A19dng/aJtpbxlD5yTvfj8HX9qsXjuB8TYfesfzCMTk2LKKcAOzkEuitqyPKe1DH 4KXq7stkeIdOcFt2Mad24xMTu0C0xo6lgWRQHX8TqEwJJln6JOQ1SPMJoMYCk08Asrnq FqMwobHht8PPfJ3Fd1GdntIXg4RedYZajvpEe9IMGLESXTPr5dyq03gKpHuVoEbNjwcv eO+fEf8sDxe90eGraDAqpvbQ209hE8PN1crauJjBRyamxmLV4GHoIJXe4rUWh+1rdIMz ImOQ== X-Gm-Message-State: AOAM53320TAJCkz7qKWRMXqqEI7VqJN6p2mQ44RYkSE2D5MW41MgoGcl wdOnIdkzSJeQIzQuNscQL8wyP9Z279A= X-Received: by 2002:a63:5262:: with SMTP id s34mr2239785pgl.382.1605591895853; Mon, 16 Nov 2020 21:44:55 -0800 (PST) Received: from ZB-PF0YQ8ZU.360buyad.local ([137.116.162.235]) by smtp.gmail.com with ESMTPSA id m3sm20392462pfd.217.2020.11.16.21.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 21:44:55 -0800 (PST) From: Zhenzhong Duan To: linux-kernel@vger.kernel.org Cc: linux-pci@vger.kernel.org, bhelgaas@google.com, hch@infradead.org, alex.williamson@redhat.com, cohuck@redhat.com, Zhenzhong Duan Subject: [PATCH v3 2/2] PCI: avoid duplicate IDs in dynamic IDs list Date: Tue, 17 Nov 2020 13:44:09 +0800 Message-Id: <20201117054409.3428-3-zhenzhong.duan@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201117054409.3428-1-zhenzhong.duan@gmail.com> References: <20201117054409.3428-1-zhenzhong.duan@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a device ID data is writen to /sys/bus/pci/drivers/.../new_id, only static ID table is checked for duplicate and multiple dynamic ID entries of same kind are allowed to exist in a dynamic IDs list. This doesn't cause user-visible broken behavior, but not user friendly. remove_id_store() only remove one of the duplicate IDs, so if we add an ID several times, we would have to remove it the same number of times before it's completely gone. Fix it by calling pci_match_device() which checks both dynamic and static IDs to avoid inserting duplicate IDs in dynamic IDs list. After fix, it shows below result which is expected: echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id echo "1af4 1041" > /sys/bus/pci/drivers/vfio-pci/new_id -bash: echo: write error: File exists Signed-off-by: Zhenzhong Duan --- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index e928cfa..c4678d8 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -197,7 +197,7 @@ static ssize_t new_id_store(struct device_driver *driver, const char *buf, pdev->subsystem_device = subdevice; pdev->class = class; - if (pci_match_id(pdrv->id_table, pdev)) + if (pci_match_device(pdrv, pdev)) retval = -EEXIST; kfree(pdev); -- 1.8.3.1