From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Mark Rutland <mark.rutland@arm.com>,
heiko@sntech.de, airlied@linux.ie,
dri-devel@lists.freedesktop.org, ykk@rock-chips.com,
devel@driverdev.osuosl.org, Pawel Moll <pawel.moll@arm.com>,
linux-rockchip@lists.infradead.org,
Grant Likely <grant.likely@linaro.org>,
Dave Airlie <airlied@redhat.com>,
jay.xu@rock-chips.com, devicetree@vger.kernel.org,
Zubair.Kakakhel@imgtec.com, Arnd Bergmann <arnd@arndb.de>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Inki Dae <inki.dae@samsung.com>, Rob Herring <robh+dt@kernel.org>,
Sean Paul <seanpaul@chromium.org>,
mark.yao@rock-chips.com, fabio.estevam@freescale.com,
Josh Boyer <jwboyer@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, djkurtz@google.com,
Kumar Gala <galak@codeaurora.org>,
Andy Yan <andy.yan@rock-chips.com>,
Shawn Guo <shawn.guo@linaro.org>,
vladimir_zapolskiy@mentor.com, Lucas
Subject: Re: [PATCH v16 03/12] drm: imx: imx-hdmi: convert imx-hdmi to drm_bridge mode
Date: Thu, 4 Dec 2014 10:09:27 +0000 [thread overview]
Message-ID: <20141204100927.GL11285@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <1417682410.3744.1.camel@pengutronix.de>
On Thu, Dec 04, 2014 at 09:40:10AM +0100, Philipp Zabel wrote:
> You are right, no I don't want this. When I initially wrote this patch I
> was under the impression that the memory allocated by devm_kzalloc in
> bind() wouldn't be freed on unbind().
Resources claimed inside bind() will be freed in unbind(). Resources
claimed in the driver's probe() will be freed in driver's remove().
They nest, and each is properly dealt with at the appropriate time due
to...
> I remember I stopped pursuing this
> patch when I got aware of the devres_open/close/remove_group dance in
> the component framework code, but somehow forgot to drop it altogether
> locally.
... the use of devres grouping.
So, if you use devm_kzalloc() in the driver's probe() function, then
that memory will be freed after the driver's remove() function is
called. That's fine.
The point I was making is:
probe()
mem = devm_kzalloc();
mem->mmio = ...;
...
bind()
mem->mmio is set
other members of mem are zero
...
unbind()
...
bind()
mem->mmio is set
other members of mem are indeterminant
...
unbind()
...
remove()
mem will be freed automatically
That's where the problem happens - the second time the bind() function
gets called: you might as well not use devm_k*z*alloc() initially,
because having the structure initialised to zero _could_ very well
hide bugs.
When you consider that it's not just the driver code which you have
to audit, but also any code the driver calls (eg, because you've embedded
some subsystem's struct in your driver private data) it quickly becomes
very easy for a bug to creep in here.
If we want to go down the route of having the probe function deal with
resources etc, then I would recommend against using devm_kzalloc() to
allocate the private structure: use devm_kmalloc() instead, which will
leave the memory uninitialised. That means you get the same condition
on each bind(), which means you have to think more about how to ensure
that the initial state of members is dealt with throughout your driver.
Alternatively, separate the struct into two sections: one which contains
everything initialised by the probe() function, and everything else, and
arrange for everything else to get memset() on entry to bind().
--
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
next prev parent reply other threads:[~2014-12-04 10:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-03 15:26 [PATCH v16 0/12] dw-hdmi: convert imx hdmi to bridge/dw_hdmi Andy Yan
2014-12-03 15:27 ` [PATCH v16 01/12] drm: imx: imx-hdmi: make checkpatch happy Andy Yan
2014-12-03 15:28 ` [PATCH v16 02/12] drm: imx: imx-hdmi: return defer if can't get ddc i2c adapter Andy Yan
2014-12-03 15:29 ` [PATCH v16 03/12] drm: imx: imx-hdmi: convert imx-hdmi to drm_bridge mode Andy Yan
2014-12-03 15:38 ` Russell King - ARM Linux
2014-12-03 16:04 ` Andy Yan
2014-12-03 16:11 ` Russell King - ARM Linux
2014-12-03 16:30 ` Andy Yan
2014-12-03 16:33 ` Russell King - ARM Linux
2014-12-03 16:56 ` Andy Yan
2014-12-03 23:40 ` Russell King - ARM Linux
2014-12-04 0:51 ` Andy Yan
2014-12-03 16:20 ` Philipp Zabel
2014-12-03 16:30 ` Russell King - ARM Linux
2014-12-04 8:40 ` Philipp Zabel
2014-12-04 10:09 ` Russell King - ARM Linux [this message]
2014-12-03 15:30 ` [PATCH v16 04/12] drm: imx: imx-hdmi: split phy configuration to platform driver Andy Yan
2014-12-03 15:32 ` [PATCH v16 05/12] drm: imx: imx-hdmi: move imx-hdmi to bridge/dw_hdmi Andy Yan
2014-12-03 15:45 ` Russell King - ARM Linux
2014-12-03 16:01 ` Andy Yan
2014-12-03 16:10 ` Russell King - ARM Linux
2014-12-03 15:32 ` [PATCH v16 06/12] dt-bindings: add document for dw_hdmi Andy Yan
2014-12-03 15:33 ` [PATCH v16 07/12] drm: bridge/dw_hdmi: add support for multi-byte register width access Andy Yan
2014-12-03 15:34 ` [PATCH v16 08/12] drm: bridge/dw_hdmi: add mode_valid support Andy Yan
2014-12-03 15:34 ` [PATCH v16 09/12] drm: bridge/dw_hdmi: clear i2cmphy_stat0 reg in hdmi_phy_wait_i2c_done Andy Yan
2014-12-03 15:35 ` [PATCH v16 10/12] drm: bridge/dw_hdmi: add function dw_hdmi_phy_enable_spare Andy Yan
2014-12-03 15:36 ` [PATCH v16 11/12] dt-bindings: Add documentation for rockchip dw hdmi Andy Yan
[not found] ` <1417620408-30354-1-git-send-email-andy.yan-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2014-12-03 15:37 ` [PATCH v16 12/12] drm: bridge/dw_hdmi: add rockchip rk3288 support Andy Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141204100927.GL11285@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=Zubair.Kakakhel@imgtec.com \
--cc=airlied@linux.ie \
--cc=airlied@redhat.com \
--cc=andy.yan@rock-chips.com \
--cc=arnd@arndb.de \
--cc=devel@driverdev.osuosl.org \
--cc=devicetree@vger.kernel.org \
--cc=djkurtz@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=fabio.estevam@freescale.com \
--cc=galak@codeaurora.org \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=heiko@sntech.de \
--cc=ijc+devicetree@hellion.org.uk \
--cc=inki.dae@samsung.com \
--cc=jay.xu@rock-chips.com \
--cc=jwboyer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mark.yao@rock-chips.com \
--cc=p.zabel@pengutronix.de \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
--cc=seanpaul@chromium.org \
--cc=shawn.guo@linaro.org \
--cc=vladimir_zapolskiy@mentor.com \
--cc=ykk@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).