From: Daniel Thompson <daniel.thompson@linaro.org>
To: Johan Hovold <johan@kernel.org>, Lee Jones <lee.jones@linaro.org>
Cc: Jingoo Han <jingoohan1@gmail.com>,
dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable <stable@vger.kernel.org>,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Subject: Re: [PATCH 1/3] backlight: as3711_bl: fix device-tree node lookup
Date: Mon, 13 Nov 2017 14:16:09 +0000 [thread overview]
Message-ID: <94c3debe-17f6-9151-eefe-129f2bd1cfd4@linaro.org> (raw)
In-Reply-To: <20171113102049.9342-1-johan@kernel.org>
On 13/11/17 10:20, Johan Hovold wrote:
> Fix child-node lookup during probe, which ended up searching the whole
> device tree depth-first starting at the parent rather than just matching
> on its children.
>
> To make things worse, the parent mfd node was also prematurely freed.
>
> Note that the nodes returned from the two calls to of_parse_phandle()
> are also leaking, but fixing that is a bit more involved as pointers to
> node fields are being stored for later use.
Is using a devm_kstrdup() to remember the full_name sufficient so get
each of the FIXMEs cleaned up as well?
Daniel.
> Fixes: 59eb2b5e57ea ("drivers/video/backlight/as3711_bl.c: add OF support")
> Cc: stable <stable@vger.kernel.org> # 3.10
> Cc: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/video/backlight/as3711_bl.c | 35 +++++++++++++++++++++++++----------
> 1 file changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/video/backlight/as3711_bl.c b/drivers/video/backlight/as3711_bl.c
> index 734a9158946b..21ce56053c88 100644
> --- a/drivers/video/backlight/as3711_bl.c
> +++ b/drivers/video/backlight/as3711_bl.c
> @@ -262,15 +262,16 @@ static int as3711_bl_register(struct platform_device *pdev,
> static int as3711_backlight_parse_dt(struct device *dev)
> {
> struct as3711_bl_pdata *pdata = dev_get_platdata(dev);
> - struct device_node *bl > - of_find_node_by_name(dev->parent->of_node, "backlight"), *fb;
> + struct device_node *bl, *fb;
> int ret;
>
> + bl = of_get_child_by_name(dev->parent->of_node, "backlight");
> if (!bl) {
> dev_dbg(dev, "backlight node not found\n");
> return -ENODEV;
> }
>
> + /* FIXME: need to drop reference to returned node */
> fb = of_parse_phandle(bl, "su1-dev", 0);
> if (fb) {
> pdata->su1_fb = fb->full_name;
> @@ -279,9 +280,10 @@ static int as3711_backlight_parse_dt(struct device *dev)
> if (pdata->su1_max_uA <= 0)
> ret = -EINVAL;
> if (ret < 0)
> - return ret;
> + goto err_put_bl;
> }
>
> + /* FIXME: need to drop reference to returned node */
> fb = of_parse_phandle(bl, "su2-dev", 0);
> if (fb) {
> int count = 0;
> @@ -292,7 +294,7 @@ static int as3711_backlight_parse_dt(struct device *dev)
> if (pdata->su2_max_uA <= 0)
> ret = -EINVAL;
> if (ret < 0)
> - return ret;
> + goto err_put_bl;
>
> if (of_find_property(bl, "su2-feedback-voltage", NULL)) {
> pdata->su2_feedback = AS3711_SU2_VOLTAGE;
> @@ -314,8 +316,10 @@ static int as3711_backlight_parse_dt(struct device *dev)
> pdata->su2_feedback = AS3711_SU2_CURR_AUTO;
> count++;
> }
> - if (count != 1)
> - return -EINVAL;
> + if (count != 1) {
> + ret = -EINVAL;
> + goto err_put_bl;
> + }
>
> count = 0;
> if (of_find_property(bl, "su2-fbprot-lx-sd4", NULL)) {
> @@ -334,8 +338,10 @@ static int as3711_backlight_parse_dt(struct device *dev)
> pdata->su2_fbprot = AS3711_SU2_GPIO4;
> count++;
> }
> - if (count != 1)
> - return -EINVAL;
> + if (count != 1) {
> + ret = -EINVAL;
> + goto err_put_bl;
> + }
>
> count = 0;
> if (of_find_property(bl, "su2-auto-curr1", NULL)) {
> @@ -355,11 +361,20 @@ static int as3711_backlight_parse_dt(struct device *dev)
> * At least one su2-auto-curr* must be specified iff
> * AS3711_SU2_CURR_AUTO is used
> */
> - if (!count ^ (pdata->su2_feedback != AS3711_SU2_CURR_AUTO))
> - return -EINVAL;
> + if (!count ^ (pdata->su2_feedback != AS3711_SU2_CURR_AUTO)) {
> + ret = -EINVAL;
> + goto err_put_bl;
> + }
> }
>
> + of_node_put(bl);
> +
> return 0;
> +
> +err_put_bl:
> + of_node_put(bl);
> +
> + return ret;
> }
>
> static int as3711_backlight_probe(struct platform_device *pdev)
>
next prev parent reply other threads:[~2017-11-13 14:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-13 10:20 [PATCH 1/3] backlight: as3711_bl: fix device-tree node lookup Johan Hovold
2017-11-13 10:20 ` [PATCH 2/3] backlight: max8925_bl: " Johan Hovold
2017-11-13 13:57 ` Daniel Thompson
2017-11-13 10:20 ` [PATCH 3/3] backlight: tps65217_bl: " Johan Hovold
2017-11-13 13:55 ` Daniel Thompson
2017-11-13 14:16 ` Daniel Thompson [this message]
2017-11-14 18:05 ` [PATCH 1/3] backlight: as3711_bl: " Johan Hovold
2017-11-14 19:48 ` Daniel Thompson
2017-11-15 13:49 ` Johan Hovold
2017-11-15 14:32 ` Lee Jones
2017-11-15 14:39 ` Johan Hovold
2017-11-20 10:49 ` Johan Hovold
2017-11-20 13:04 ` Lee Jones
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=94c3debe-17f6-9151-eefe-129f2bd1cfd4@linaro.org \
--to=daniel.thompson@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=g.liakhovetski@gmx.de \
--cc=jingoohan1@gmail.com \
--cc=johan@kernel.org \
--cc=lee.jones@linaro.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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).