iommu/amd: Replace slab cache allocator with page allocator
Hello Sairaj Kodilkar,
Commit eaf717fa1c3f ("iommu/amd: Replace slab cache allocator with page allocator") from Mar 7, 2025 (linux-next), leads to the following Smatch static checker warning:
drivers/iommu/amd/iommu.c:3200 alloc_irq_table() error: we previously assumed 'iommu' could be null (see line 3195)
drivers/iommu/amd/iommu.c
3186 static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu,
3187 u16 devid, struct pci_dev *pdev,
3188 unsigned int max_irqs)
3189 {
3190 struct irq_remap_table *table = NULL;
3191 struct irq_remap_table *new_table = NULL;
3192 struct amd_iommu_pci_seg *pci_seg;
3193 unsigned long flags;
3194 int order = get_order(get_irq_table_size(max_irqs));
3195 int nid = iommu && iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
^^^^^^^^This check can hopefully be deleted?
3196 u16 alias;
3197
3198 spin_lock_irqsave(&iommu_table_lock, flags);
3199
--> 3200 pci_seg = iommu->pci_seg;
^^^^^^^Otherwise it will crash here.
3201 table = pci_seg->irq_lookup_table[devid];
3202 if (table)
3203 goto out_unlock;
3204
3205 alias = pci_seg->alias_table[devid];regards,
dan carpenter
Quoted 21 lines · Dan Carpenter
Hello Sairaj Kodilkar,
Commit
eaf717fa1c3f("iommu/amd: Replace slab cache allocator with page allocator") from Mar 7, 2025 (linux-next), leads to the following Smatch static checker warning:drivers/iommu/amd/iommu.c:3200 alloc_irq_table() error: we previously assumed 'iommu' could be null (see line 3195)
drivers/iommu/amd/iommu.c3186 static struct irq_remap_table *alloc_irq_table(struct amd_iommu *iommu, 3187 u16 devid, struct pci_dev *pdev, 3188 unsigned int max_irqs) 3189 { 3190 struct irq_remap_table *table = NULL; 3191 struct irq_remap_table *new_table = NULL; 3192 struct amd_iommu_pci_seg *pci_seg; 3193 unsigned long flags; 3194 int order = get_order(get_irq_table_size(max_irqs)); 3195 int nid = iommu && iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE; ^^^^^^^^
Quoted 1 line
This check can hopefully be deleted?
Hi Dan,
Yes, ideally check should be
nid = iommu->dev ? dev_to_node(&iommu->dev->dev)
The caller ensures that alloc_irq_table is called with valid iommu But we need to check if iommu->dev is valid because it may not be set for IOAPIC.
This is not a bug but a redundant check. Please let me know if you want me to send fix for this
Quoted 9 lines
3196 u16 alias; 3197 3198 spin_lock_irqsave(&iommu_table_lock, flags); 3199 --> 3200 pci_seg = iommu->pci_seg; ^^^^^^^Otherwise it will crash here.
Quoted 8 lines
3201 table = pci_seg->irq_lookup_table[devid]; 3202 if (table) 3203 goto out_unlock; 3204 3205 alias = pci_seg->alias_table[devid];regards,
dan carpenter
Regards
Sairaj Kodilkar