pci: Prevent kernel modules to be listed twice
authorErwan Velu <erwan.velu@free.fr>
Mon, 9 Nov 2009 09:42:10 +0000 (10:42 +0100)
committerErwan Velu <erwan.velu@free.fr>
Mon, 9 Nov 2009 09:42:10 +0000 (10:42 +0100)
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

index 82a7c84..55b178d 100644 (file)
@@ -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; i<dev->dev_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; i<dev->dev_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++;
+             }
       }
     }
   }