mbox series

[0/5] Convert to use devm_*() for amba attached modules

Message ID 1490539314-9681-1-git-send-email-leo.yan@linaro.org
Headers show
Series Convert to use devm_*() for amba attached modules | expand

Message

Leo Yan March 26, 2017, 2:41 p.m. UTC
When review device driver modules which attach to amba bus, found
several modules are not using devm_*() apis to manage resource. As
result, some drivers have memory leakage or missing iomem unmapping
when rmmod module. And the code has many "goto" tags to handle
different failures.

So this patch series is to convert to use devm_*() for moudules which
are attached to amba bus to manage resource and get more robust and
neat code.

Patch 0003 "drivers/rtc/rtc-pl031.c: Convert to use devm_*()" has been
verified on 96boards Hikey. Other patches can pass building but have
not really tested on hardware.


Leo Yan (5):
  Input: ambakmi - Convert to use devm_*()
  drivers/rtc/rtc-pl030.c: Convert to use devm_*()
  drivers/rtc/rtc-pl031.c: Convert to use devm_*()
  vfio: platform: Convert to use devm_*()
  ALSA: AACI: Convert to use devm_ioremap_resource()

 drivers/input/serio/ambakmi.c     | 44 +++++++----------------------
 drivers/rtc/rtc-pl030.c           | 49 ++++++++------------------------
 drivers/rtc/rtc-pl031.c           | 59 ++++++++++-----------------------------
 drivers/vfio/platform/vfio_amba.c | 25 ++++++-----------
 sound/arm/aaci.c                  | 21 ++++----------
 5 files changed, 51 insertions(+), 147 deletions(-)

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Russell King (Oracle) March 26, 2017, 2:50 p.m. UTC | #1
On Sun, Mar 26, 2017 at 10:41:50PM +0800, Leo Yan wrote:
> Convert driver to use devm_*() APIs so rely on driver model core layer

> to manage resources. This eliminates error path boilerplate and makes

> code neat.

> 

> This patch also fixes the memory leakage for 'kmi->io' when remove

> module.


No, it is not leaked, in fact, your patch introduces a use-after-free
bug.

kmi->io is of type "struct serio", and this structure has an embedded
"struct device".  The lifetime of any structure containing a "struct
device" is controlled by the lifetime of the struct device.

Once serio_register_port() has been called on it, it is up to the
serio layer to free this structure.

Therefore, your patch creates a bug, and so it gets a NAK.  There is no
resource leakage here.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Leo Yan March 26, 2017, 3:23 p.m. UTC | #2
On Sun, Mar 26, 2017 at 03:50:24PM +0100, Russell King - ARM Linux wrote:
> On Sun, Mar 26, 2017 at 10:41:50PM +0800, Leo Yan wrote:

> > Convert driver to use devm_*() APIs so rely on driver model core layer

> > to manage resources. This eliminates error path boilerplate and makes

> > code neat.

> > 

> > This patch also fixes the memory leakage for 'kmi->io' when remove

> > module.

> 

> No, it is not leaked, in fact, your patch introduces a use-after-free

> bug.

> 

> kmi->io is of type "struct serio", and this structure has an embedded

> "struct device".  The lifetime of any structure containing a "struct

> device" is controlled by the lifetime of the struct device.

> 

> Once serio_register_port() has been called on it, it is up to the

> serio layer to free this structure.

> 

> Therefore, your patch creates a bug, and so it gets a NAK.  There is no

> resource leakage here.


Thanks for reviewing. Now I understood and please ignore this patch
and patch 0005.

Thanks,
Leo Yan
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij March 29, 2017, 1:46 a.m. UTC | #3
On Sun, Mar 26, 2017 at 4:41 PM, Leo Yan <leo.yan@linaro.org> wrote:

> Convert driver to use devm_*() APIs so rely on driver model core layer

> to manage resources. This eliminates error path boilerplate and makes

> code neat.

>

> Signed-off-by: Leo Yan <leo.yan@linaro.org>


Acked-by: Linus Walleij <linus.walleij@linaro.org>


Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html