Skip to content

Commit 9a82173

Browse files
committed
Merge branch 'pci/controller/cadence'
- Fix cdns_pcie_host_dma_ranges_cmp() to prevent possible invalid sort order (Ian Rogers) * pci/controller/cadence: PCI: cadence: Avoid signed 64-bit truncation and invalid sort
2 parents a8a811c + 0297dce commit 9a82173

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

drivers/pci/controller/cadence/pcie-cadence-host-common.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,21 @@ int cdns_pcie_host_dma_ranges_cmp(void *priv, const struct list_head *a,
173173
const struct list_head *b)
174174
{
175175
struct resource_entry *entry1, *entry2;
176+
u64 size1, size2;
176177

177178
entry1 = container_of(a, struct resource_entry, node);
178179
entry2 = container_of(b, struct resource_entry, node);
179180

180-
return resource_size(entry2->res) - resource_size(entry1->res);
181+
size1 = resource_size(entry1->res);
182+
size2 = resource_size(entry2->res);
183+
184+
if (size1 > size2)
185+
return -1;
186+
187+
if (size1 < size2)
188+
return 1;
189+
190+
return 0;
181191
}
182192
EXPORT_SYMBOL_GPL(cdns_pcie_host_dma_ranges_cmp);
183193

0 commit comments

Comments
 (0)