From fe18d4a75a7c5281188bff42c2bdbc53f1ec9ee8 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Mon, 9 Nov 2009 10:42:10 +0100 Subject: pci: Prevent kernel modules to be listed twice Impact: Prevent duplicated modules If both get_module_name_from_pcimap() & get_module_name_from_alias() are called, we didn't checked if the module we are detecting already got detected. This leads to a situation where modules got listed twice. This patch add a test to insure that we aren't adding an already detected module. --- com32/lib/pci/scan.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'com32/lib/pci/scan.c') diff --git a/com32/lib/pci/scan.c b/com32/lib/pci/scan.c index 82a7c844..55b178dd 100644 --- a/com32/lib/pci/scan.c +++ b/com32/lib/pci/scan.c @@ -154,8 +154,22 @@ int get_module_name_from_pcimap(struct pci_domain *domain, == dev->sub_product && (int_sub_vendor_id & dev->sub_vendor) == dev->sub_vendor) { - strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name); - dev->dev_info->linux_kernel_module_count++; + bool found=false; + + /* Scan all known kernel modules for this pci device */ + for (int i=0; idev_info->linux_kernel_module_count; i++) { + + /* Try to detect if we already knew the same kernel module*/ + if (strstr(dev->dev_info->linux_kernel_module[i], module_name)) { + found=true; + break; + } + } + /* If we don't have this kernel module, let's add it */ + if (!found) { + strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name); + dev->dev_info->linux_kernel_module_count++; + } } } } @@ -702,8 +716,22 @@ int get_module_name_from_alias(struct pci_domain *domain, char *modules_alias_pa == dev->sub_product && (int_sub_vendor_id & dev->sub_vendor) == dev->sub_vendor) { - strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name); - dev->dev_info->linux_kernel_module_count++; + bool found=false; + + /* Scan all known kernel modules for this pci device */ + for (int i=0; idev_info->linux_kernel_module_count; i++) { + + /* Try to detect if we already knew the same kernel module*/ + if (strstr(dev->dev_info->linux_kernel_module[i], module_name)) { + found=true; + break; + } + } + /* If we don't have this kernel module, let's add it */ + if (!found) { + strcpy(dev->dev_info->linux_kernel_module[dev->dev_info->linux_kernel_module_count], module_name); + dev->dev_info->linux_kernel_module_count++; + } } } } -- cgit v1.2.1