mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: Meghana Madhyastha <meghana.madhyastha@gmail.com>,
	Lee Jones <lee.jones@linaro.org>,
	Daniel Thompson <daniel.thompson@linaro.org>,
	Jingoo Han <jingoohan1@gmail.com>,
	Thierry Reding <thierry.reding@gmail.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Sean Paul <seanpaul@chromium.org>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v16 09/10] drm/panel: Use of_find_backlight helper
Date: Thu, 18 Jan 2018 15:51:12 +0100	[thread overview]
Message-ID: <938045f6-e404-b26e-138b-7eb5ef456975@tronnes.org> (raw)
In-Reply-To: <20180118120732.GC4864@meghana-HP-Pavilion-Notebook>


Den 18.01.2018 13.07, skrev Meghana Madhyastha:
> On Tue, Jan 16, 2018 at 06:08:53PM +0100, Noralf Trønnes wrote:
>> Den 16.01.2018 11.36, skrev Meghana Madhyastha:
>>> Replace of_find_backlight_by_node and of the code around it
>>> with of_find_backlight helper to avoid repetition of code.
>>>
>>> Signed-off-by: Meghana Madhyastha <meghana.madhyastha@gmail.com>
>>> ---
>>>   drivers/gpu/drm/panel/panel-innolux-p079zca.c   | 10 +++-------
>>>   drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c | 10 +++-------
>>>   drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c | 10 +++-------
>>>   3 files changed, 9 insertions(+), 21 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/panel/panel-innolux-p079zca.c b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
>>> index 4c1b29eec..a69b0530f 100644
>>> --- a/drivers/gpu/drm/panel/panel-innolux-p079zca.c
>>> +++ b/drivers/gpu/drm/panel/panel-innolux-p079zca.c
>>> @@ -230,14 +230,10 @@ static int innolux_panel_add(struct innolux_panel *innolux)
>>>   		innolux->enable_gpio = NULL;
>>>   	}
>>> -	np = of_parse_phandle(dev->of_node, "backlight", 0);
>>> -	if (np) {
>>> -		innolux->backlight = of_find_backlight_by_node(np);
>>> -		of_node_put(np);
>>> +	innolux->backlight = devm_of_find_backlight(np);
>> This driver isn't broken like tinydrm was, so it does put the backlight
>> device on cleanup like it should. So when you're using the devm_ version,
>> the result is a double put. Just remove the put_device() in
>> innolux_panel_add/del() and you're good.
> I have a quick question here. So devm_of_find_backlight automatically
> does a put_device on detachment of the driver. However in this case,
> put_device is called when panel_add is not successful (i.e when it
> returns a negative value here). So is devm's release mechanism still
> invoked here ?

As long as the error is propagated back up the chain, which it is in this
case, devres_release_all() is called and the resources are released.

Driver callchain passing up the error:
innolux_panel_driver.probe = innolux_panel_probe <- innolux_panel_add <- 
devm_of_find_backlight

This is mipi_dsi setting up the probe hook and calling into it's own 
version:

drivers/gpu/drm/drm_mipi_dsi.c:
int mipi_dsi_driver_register_full(struct mipi_dsi_driver *drv,
                   struct module *owner)
{
...
     if (drv->probe)
         drv->driver.probe = mipi_dsi_drv_probe;
...
}

static int mipi_dsi_drv_probe(struct device *dev)
{
     struct mipi_dsi_driver *drv = to_mipi_dsi_driver(dev->driver);
     struct mipi_dsi_device *dsi = to_mipi_dsi_device(dev);

     return drv->probe(dsi);
}

This is the device-driver core that initiates the probing:

drivers/base/dd.c
static int really_probe(struct device *dev, struct device_driver *drv)
{
...
     } else if (drv->probe) {
         ret = drv->probe(dev);
         if (ret)
             goto probe_failed;
     }
...
probe_failed:
...
     devres_release_all(dev);
...
}

> 	err = drm_panel_add(&innolux->base);
> 	if (err < 0)
> 		goto put_backlight;
>
> 	return 0;
>
> 	put_backlight:
> 		put_device(&innolux->backlight->dev);
> 	return err;
>
> If so then I should change this to
> 	err = drm_panel_add(&innolux->base)
> 	return err;

Yes, and you can drop the variable:

         return drm_panel_add(&innolux->base);

Noralf.

>
> Thanks and regards,
> Meghana
>
>> I haven't checked the other drivers.
>>
>> Noralf.
>>
>> PS:
>> Give people a few days (one week?) to respond before respinning a new
>> version, so we avoid a fragmented discussion.
>>
>>> -		if (!innolux->backlight)
>>> -			return -EPROBE_DEFER;
>>> -	}
>>> +	if (IS_ERR(innolux->backlight))
>>> +		return PTR_ERR(innolux->backlight);
>>>   	drm_panel_init(&innolux->base);
>>>   	innolux->base.funcs = &innolux_panel_funcs;
>>> diff --git a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
>>> index 1512ec4f3..d5450c9d9 100644
>>> --- a/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
>>> +++ b/drivers/gpu/drm/panel/panel-sharp-lq101r1sx01.c
>>> @@ -329,14 +329,10 @@ static int sharp_panel_add(struct sharp_panel *sharp)
>>>   	if (IS_ERR(sharp->supply))
>>>   		return PTR_ERR(sharp->supply);
>>> -	np = of_parse_phandle(sharp->link1->dev.of_node, "backlight", 0);
>>> -	if (np) {
>>> -		sharp->backlight = of_find_backlight_by_node(np);
>>> -		of_node_put(np);
>>> +	sharp->backlight = devm_of_find_backlight(np);
>>> -		if (!sharp->backlight)
>>> -			return -EPROBE_DEFER;
>>> -	}
>>> +	if (IS_ERR(sharp->backlight))
>>> +		return PTR_ERR(sharp->backlight);
>>>   	drm_panel_init(&sharp->base);
>>>   	sharp->base.funcs = &sharp_panel_funcs;
>>> diff --git a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
>>> index a6af3257f..db31d8268 100644
>>> --- a/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
>>> +++ b/drivers/gpu/drm/panel/panel-sharp-ls043t1le01.c
>>> @@ -273,14 +273,10 @@ static int sharp_nt_panel_add(struct sharp_nt_panel *sharp_nt)
>>>   		gpiod_set_value(sharp_nt->reset_gpio, 0);
>>>   	}
>>> -	np = of_parse_phandle(dev->of_node, "backlight", 0);
>>> -	if (np) {
>>> -		sharp_nt->backlight = of_find_backlight_by_node(np);
>>> -		of_node_put(np);
>>> +	sharp_nt->backlight = devm_of_find_backlight(np);
>>> -		if (!sharp_nt->backlight)
>>> -			return -EPROBE_DEFER;
>>> -	}
>>> +	if (IS_ERR(sharp_nt->backlight))
>>> +		return PTR_ERR(sharp_nt->backlight);
>>>   	drm_panel_init(&sharp_nt->base);
>>>   	sharp_nt->base.funcs = &sharp_nt_panel_funcs;

  reply	other threads:[~2018-01-18 14:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-16 10:31 [PATCH v16 00/10] Add backlight helper functions Meghana Madhyastha
2018-01-16 10:31 ` [PATCH v16 01/10] video: backlight: Add helpers to enable and disable backlight Meghana Madhyastha
2018-01-16 16:50   ` Noralf Trønnes
2018-01-17 17:00   ` Daniel Thompson
2018-01-17 21:24     ` Daniel Vetter
2018-01-17 22:03     ` Noralf Trønnes
2018-01-18 10:59       ` Meghana Madhyastha
2018-01-18 12:02         ` Daniel Thompson
2018-01-16 10:32 ` [PATCH v16 02/10] drm/tinydrm: Convert tinydrm_enable/disable_backlight to backlight_enable/disable Meghana Madhyastha
2018-01-16 16:51   ` Noralf Trønnes
2018-01-16 10:33 ` [PATCH v16 03/10] video: backlight: Add of_find_backlight helper in backlight.c Meghana Madhyastha
2018-01-16 16:56   ` Noralf Trønnes
2018-01-17 17:01   ` Daniel Thompson
2018-01-16 10:34 ` [PATCH v16 04/10] drm/tinydrm: Replace tinydrm_of_find_backlight with of_find_backlight Meghana Madhyastha
2018-01-16 16:59   ` Noralf Trønnes
2018-01-16 10:34 ` [PATCH v16 05/10] video: backlight: Add devres versions of of_find_backlight Meghana Madhyastha
2018-01-16 17:02   ` Noralf Trønnes
2018-01-17 17:09   ` Daniel Thompson
2018-01-18 11:02     ` Meghana Madhyastha
2018-01-18 11:50       ` Daniel Thompson
2018-01-16 10:34 ` [PATCH v16 06/10] drm/tinydrm: Call devres version " Meghana Madhyastha
2018-01-16 17:03   ` Noralf Trønnes
2018-01-16 10:35 ` [PATCH v16 07/10] drm/panel: Use backlight_enable/disable helpers Meghana Madhyastha
2018-01-16 17:11   ` Noralf Trønnes
2018-01-16 10:35 ` [PATCH v16 08/10] drm/omapdrm: " Meghana Madhyastha
2018-01-16 10:36 ` [PATCH v16 09/10] drm/panel: Use of_find_backlight helper Meghana Madhyastha
2018-01-16 17:08   ` Noralf Trønnes
2018-01-18 12:07     ` Meghana Madhyastha
2018-01-18 14:51       ` Noralf Trønnes [this message]
2018-01-16 10:36 ` [PATCH v16 10/10] drm/omapdrm: " Meghana Madhyastha
2018-01-16 21:46 ` [PATCH v16 00/10] Add backlight helper functions Sean Paul

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=938045f6-e404-b26e-138b-7eb5ef456975@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=daniel.thompson@linaro.org \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jingoohan1@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=meghana.madhyastha@gmail.com \
    --cc=seanpaul@chromium.org \
    --cc=thierry.reding@gmail.com \
    --cc=tomi.valkeinen@ti.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

all inboxes | Powered by JetHome®