Skip to content

Commit c9c1578

Browse files
Marc Zyngierbjorn-helgaas
authored andcommitted
PCI: xgene-msi: Use device-managed memory allocations
Since the MSI driver is probed as a platform device, there is no reason to not use device-managed allocations. That's including the top-level bookkeeping structure, which is better dynamically allocated than being static. Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0756244 commit c9c1578

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

drivers/pci/controller/pci-xgene-msi.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct xgene_msi {
4040
};
4141

4242
/* Global data */
43-
static struct xgene_msi xgene_msi_ctrl;
43+
static struct xgene_msi *xgene_msi_ctrl;
4444

4545
/*
4646
* X-Gene v1 has 16 groups of MSI termination registers MSInIRx, where
@@ -253,18 +253,18 @@ static void xgene_free_domains(struct xgene_msi *msi)
253253
irq_domain_remove(msi->inner_domain);
254254
}
255255

256-
static int xgene_msi_init_allocator(struct xgene_msi *xgene_msi)
256+
static int xgene_msi_init_allocator(struct device *dev)
257257
{
258-
xgene_msi->bitmap = bitmap_zalloc(NR_MSI_VEC, GFP_KERNEL);
259-
if (!xgene_msi->bitmap)
258+
xgene_msi_ctrl->bitmap = devm_bitmap_zalloc(dev, NR_MSI_VEC, GFP_KERNEL);
259+
if (!xgene_msi_ctrl->bitmap)
260260
return -ENOMEM;
261261

262-
mutex_init(&xgene_msi->bitmap_lock);
262+
mutex_init(&xgene_msi_ctrl->bitmap_lock);
263263

264-
xgene_msi->msi_groups = kcalloc(NR_HW_IRQS,
265-
sizeof(struct xgene_msi_group),
266-
GFP_KERNEL);
267-
if (!xgene_msi->msi_groups)
264+
xgene_msi_ctrl->msi_groups = devm_kcalloc(dev, NR_HW_IRQS,
265+
sizeof(struct xgene_msi_group),
266+
GFP_KERNEL);
267+
if (!xgene_msi_ctrl->msi_groups)
268268
return -ENOMEM;
269269

270270
return 0;
@@ -273,15 +273,14 @@ static int xgene_msi_init_allocator(struct xgene_msi *xgene_msi)
273273
static void xgene_msi_isr(struct irq_desc *desc)
274274
{
275275
struct irq_chip *chip = irq_desc_get_chip(desc);
276+
struct xgene_msi *xgene_msi = xgene_msi_ctrl;
276277
struct xgene_msi_group *msi_groups;
277-
struct xgene_msi *xgene_msi;
278278
int msir_index, msir_val, hw_irq, ret;
279279
u32 intr_index, grp_select, msi_grp;
280280

281281
chained_irq_enter(chip, desc);
282282

283283
msi_groups = irq_desc_get_handler_data(desc);
284-
xgene_msi = msi_groups->msi;
285284
msi_grp = msi_groups->msi_grp;
286285

287286
/*
@@ -344,15 +343,12 @@ static void xgene_msi_remove(struct platform_device *pdev)
344343

345344
kfree(msi->msi_groups);
346345

347-
bitmap_free(msi->bitmap);
348-
msi->bitmap = NULL;
349-
350346
xgene_free_domains(msi);
351347
}
352348

353349
static int xgene_msi_hwirq_alloc(unsigned int cpu)
354350
{
355-
struct xgene_msi *msi = &xgene_msi_ctrl;
351+
struct xgene_msi *msi = xgene_msi_ctrl;
356352
struct xgene_msi_group *msi_group;
357353
int i;
358354
int err;
@@ -381,7 +377,7 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu)
381377

382378
static int xgene_msi_hwirq_free(unsigned int cpu)
383379
{
384-
struct xgene_msi *msi = &xgene_msi_ctrl;
380+
struct xgene_msi *msi = xgene_msi_ctrl;
385381
struct xgene_msi_group *msi_group;
386382
int i;
387383

@@ -406,7 +402,12 @@ static int xgene_msi_probe(struct platform_device *pdev)
406402
int virt_msir;
407403
u32 msi_val, msi_idx;
408404

409-
xgene_msi = &xgene_msi_ctrl;
405+
xgene_msi_ctrl = devm_kzalloc(&pdev->dev, sizeof(*xgene_msi_ctrl),
406+
GFP_KERNEL);
407+
if (!xgene_msi_ctrl)
408+
return -ENOMEM;
409+
410+
xgene_msi = xgene_msi_ctrl;
410411

411412
platform_set_drvdata(pdev, xgene_msi);
412413

@@ -417,7 +418,7 @@ static int xgene_msi_probe(struct platform_device *pdev)
417418
}
418419
xgene_msi->msi_addr = res->start;
419420

420-
rc = xgene_msi_init_allocator(xgene_msi);
421+
rc = xgene_msi_init_allocator(&pdev->dev);
421422
if (rc) {
422423
dev_err(&pdev->dev, "Error allocating MSI bitmap\n");
423424
goto error;

0 commit comments

Comments
 (0)