Skip to content

Commit f86319c

Browse files
committed
firewire: ohci: use devres for memory object of ohci structure
The managed device resource (devres) framework is convenient to maintain lifetime of allocated memory object for device. This commit utilizes the framework for the object of ohci structure. The extra operation for power management is required in Apple PowerMac based machines, thus release callback is assigned to the object to call the operation. Link: https://lore.kernel.org/r/20230604054451.161076-2-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent 0258d88 commit f86319c

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

drivers/firewire/ohci.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,6 +3557,15 @@ static inline void pmac_ohci_on(struct pci_dev *dev) {}
35573557
static inline void pmac_ohci_off(struct pci_dev *dev) {}
35583558
#endif /* CONFIG_PPC_PMAC */
35593559

3560+
static void release_ohci(struct device *dev, void *data)
3561+
{
3562+
struct pci_dev *pdev = to_pci_dev(dev);
3563+
3564+
pmac_ohci_off(pdev);
3565+
3566+
dev_notice(dev, "removed fw-ohci device\n");
3567+
}
3568+
35603569
static int pci_probe(struct pci_dev *dev,
35613570
const struct pci_device_id *ent)
35623571
{
@@ -3571,25 +3580,22 @@ static int pci_probe(struct pci_dev *dev,
35713580
return -ENOSYS;
35723581
}
35733582

3574-
ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
3575-
if (ohci == NULL) {
3576-
err = -ENOMEM;
3577-
goto fail;
3578-
}
3579-
3583+
ohci = devres_alloc(release_ohci, sizeof(*ohci), GFP_KERNEL);
3584+
if (ohci == NULL)
3585+
return -ENOMEM;
35803586
fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev);
3581-
3587+
pci_set_drvdata(dev, ohci);
35823588
pmac_ohci_on(dev);
3589+
devres_add(&dev->dev, ohci);
35833590

35843591
err = pci_enable_device(dev);
35853592
if (err) {
35863593
dev_err(&dev->dev, "failed to enable OHCI hardware\n");
3587-
goto fail_free;
3594+
return err;
35883595
}
35893596

35903597
pci_set_master(dev);
35913598
pci_write_config_dword(dev, OHCI1394_PCI_HCI_Control, 0);
3592-
pci_set_drvdata(dev, ohci);
35933599

35943600
spin_lock_init(&ohci->lock);
35953601
mutex_init(&ohci->phy_reg_mutex);
@@ -3748,10 +3754,7 @@ static int pci_probe(struct pci_dev *dev,
37483754
pci_release_region(dev, 0);
37493755
fail_disable:
37503756
pci_disable_device(dev);
3751-
fail_free:
3752-
kfree(ohci);
3753-
pmac_ohci_off(dev);
3754-
fail:
3757+
37553758
return err;
37563759
}
37573760

@@ -3796,10 +3799,8 @@ static void pci_remove(struct pci_dev *dev)
37963799
pci_iounmap(dev, ohci->registers);
37973800
pci_release_region(dev, 0);
37983801
pci_disable_device(dev);
3799-
kfree(ohci);
3800-
pmac_ohci_off(dev);
38013802

3802-
dev_notice(&dev->dev, "removed fw-ohci device\n");
3803+
dev_notice(&dev->dev, "removing fw-ohci device\n");
38033804
}
38043805

38053806
#ifdef CONFIG_PM

0 commit comments

Comments
 (0)