Use devm_ioremap_resource to reserve resource
Peter Huewe
maintainerPATCH 1/1 Use devm_ioremap_resource to reserve resource
Unfortunately the tpm_tis driver did never call request_region for its adress space - now since we've got devm_ioremap_resource we can simply remove all the stuff and do everything in one call.
--- drivers/char/tpm/tpm_tis.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_tis.c +4 -6
@@ -534,13 +534,14 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,u32 vendor, intfcaps, intmask;int rc, i, irq_s, irq_e, probe;struct tpm_chip *chip; +struct resource res =DEFINE_RES_MEM_NAMED (start, len,"tpm_tis" );if (!(chip =tpm_register_hardware (dev, &tpm_tis)))return -ENODEV ; - chip->vendor.iobase =ioremap (start, len); -if (!chip->vendor.iobase) { - rc = -EIO ; + chip->vendor.iobase =devm_ioremap_resource (dev, &res); +if (IS_ERR (chip->vendor.iobase)) { + rc =PTR_ERR (chip->vendor.iobase); goto out_err; }
@@ -727,8 +728,6 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,return 0 ; out_err: -if (chip->vendor.iobase) -iounmap (chip->vendor.iobase);tpm_remove_hardware (chip->dev);return rc; }
@@ -891,7 +890,6 @@ static void __exit cleanup_tis(void)release_locality (chip, chip->vendor.locality,1 );if (chip->vendor.irq)free_irq (chip->vendor.irq, chip); -iounmap (i->iobase);list_del (&i->list); }mutex_unlock (&tis_lock);
Signature · 1 line
1.8.5.5
Quoted 40 lines · Peter Huewe
Unfortunately the
tpm_tisdriver did never callrequest_regionfor its adress space - now since we've gotdevm_ioremap_resourcewe can simply remove all the stuff and do everything in one call.Cc <[email protected]>Signed-off-by Peter Huewe <[email protected]>drivers/char/tpm/tpm_tis.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)drivers/char/tpm/tpm_tis.c +5
-5+++ b/drivers/char/tpm/tpm_tis.c@@ -534,13 +534,14 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,u32 vendor, intfcaps, intmask;int rc, i, irq_s, irq_e, probe;struct tpm_chip *chip; +struct resource res =DEFINE_RES_MEM_NAMED (start, len,"tpm_tis" );if (!(chip =tpm_register_hardware (dev, &tpm_tis)))return -ENODEV ; - chip->vendor.iobase =ioremap (start, len); -if (!chip->vendor.iobase) { - rc = -EIO ; + chip->vendor.iobase =devm_ioremap_resource (dev, &res); +if (IS_ERR (chip->vendor.iobase)) { + rc =PTR_ERR (chip->vendor.iobase); goto out_err; }@@ -727,8 +728,6 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,return 0 ; out_err: -if (chip->vendor.iobase) -iounmap (chip->vendor.iobase);tpm_remove_hardware (chip->dev);return rc; }
drivers/char/tpm/tpm_tis.c static void __exit cleanup_tis(void) · line 894
Quoted 6 lines
drivers/char/tpm/tpm_tis.c +0
-1@@ -891,7 +890,6 @@ static void __exit cleanup_tis(void)release_locality (chip, chip->vendor.locality,1 );if (chip->vendor.irq)free_irq (chip->vendor.irq, chip); -iounmap (i->iobase);list_del (&i->list); }
Hurm, this makes the ordering truely horrible and opaque. Are you completely certain that in every case the devm unwide will happen only after cleanup_tis is called?
Intuitively, I would expect all devices to have been detached and resources freed prior to the module exit function being called...
I'd be much happier with mixing devm into this driver if it had a proper driver remove method and the unnecessary tis_chips list was purged.
Jason
Peter Hüwe
maintainerAm Dienstag, 22. Juli 2014, 01:43:30 schrieb Jason Gunthorpe:
Quoted 10 lines · Peter Huewe
Quoted 4 lines
Unfortunately the
tpm_tisdriver did never callrequest_regionfor its adress space - now since we've gotdevm_ioremap_resourcewe can simply remove all the stuff and do everything in one call.Hurm, this makes the ordering truely horrible and opaque. Are you completely certain that in every case the devm unwide will happen only after
cleanup_tisis called?
Quoted 8 lines
Intuitively, I would expect all devices to have been detached and resources freed prior to the module exit function being called...
I'd be much happier with mixing devm into this driver if it had a proper driver remove method and the unnecessary
tis_chipslist was purged.Jason
Ok, thanks for the review - that's why I post this stuff to the mailing list first ;)
In my tests everything worked fine, but I agree that the TPM code is so horible that there might be a lot of cases not handled correctly.
I think I'll conjure up a "manual" patch, doing the request_region and release_region manually ?
Thanks,
Peter