misc: pci_endpoint_test: Avoid triggering a BUG()
authorDan Carpenter <dan.carpenter@oracle.com>
Sat, 30 Sep 2017 08:16:51 +0000 (11:16 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Dec 2017 09:10:28 +0000 (10:10 +0100)
[ Upstream commit 846df244ebefbc9f7b91e9ae7a5e5a2e69fb4772 ]

If you call ida_simple_remove(&pci_endpoint_test_ida, id) with a
negative "id" then it triggers an immediate BUG_ON().  Let's not allow
that.

Fixes: 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function device")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/pci_endpoint_test.c

index e787a63a321a76773639a71de1925576cfc336c8..e089bb6dde3a84d208ca90b4a6c06feadb760e32 100644 (file)
@@ -590,6 +590,8 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)
 
        if (sscanf(misc_device->name, DRV_MODULE_NAME ".%d", &id) != 1)
                return;
+       if (id < 0)
+               return;
 
        misc_deregister(&test->miscdev);
        ida_simple_remove(&pci_endpoint_test_ida, id);