All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Yufen <wangyufen@huaweicloud.com>
To: Wei Yongjun <weiyongjun@huaweicloud.com>,
	Oleh Kravchenko <oleg@kaa.org.ua>
Cc: linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	Pavel Machek <pavel@ucw.cz>
Subject: Re: [PATCH 02/13] leds: el15203000: Fix devm vs. non-devm ordering
Date: Tue, 22 Nov 2022 09:10:12 +0800	[thread overview]
Message-ID: <f5969fbb-bdbb-6841-e1db-3c32a7a27061@huaweicloud.com> (raw)
In-Reply-To: <d509ee79-e73a-b236-bed9-8d40b8f6d460@huaweicloud.com>



在 2022/11/15 10:06, Wei Yongjun 写道:
> Hi Oleh,
> 
> On 2022/11/11 18:39, Oleh Kravchenko wrote:
>> Hello Wang,
>>
>>> 11 лист. 2022 р. о 11:21 wangyufen <wangyufen@huawei.com> написав(ла):
>>>
>>>
>>> 在 2022/11/9 18:43, Oleh Kravchenko 写道:
>>>>
>>>>
>>>>> 9 лист. 2022 р. о 12:25 wangyufen <wangyufen@huawei.com> написав(ла):
>>>>>
>>>>>
>>>>> 在 2022/11/9 17:39, Oleh Kravchenko 写道:
>>>>>
>>>>>>> -static void el15203000_remove(struct spi_device *spi)
>>>>>>>
>>>>>> Is remove() callback from struct spi_driver deprecated?
>>>>>>
>>>>> It is not that remove() callback is deprecated,
>>>>> it's that after wrapping mutex_destroy() call with devm_add_action_or_reset(),
>>>>> remove() callback is unnecessary here.
>>>>>
>>>> When remove() is called, the memory allocated by devm_*() is valid.
>>>> So what you try to fix here?
>>>
>>> Fix the &priv->lock used after destroy, for details, please see patch #0
>>> LKML: Wang Yufen: [PATCH 00/13] leds: Fix devm vs. non-devm ordering
>>
>> It doesn’t make any sense for me.
>> You saying that remove() called before devm_* allocation
>> if it true then set_brightness_delayed() will crash the system in anyway.
>>
>> LED device has a parent SPI device; LED device can’t exist without SPI device.
>>
>> So deallocation order should be next:
>> 1. LED device devm_*()
>> 2. SPI device remove()
> 
> The allocation order is as follows:
> 
> el15203000_probe()
>    mutex_init(&priv->lock);
>    el15203000_probe_dt(priv)
>      device_for_each_child_node(priv->dev, child) {
>        ...
>        led->ldev.brightness_set_blocking = el15203000_set_blocking;
>        ...
>        devm_led_classdev_register_ext(priv->dev, &led->ldev, &init_data);
>           dr = devres_alloc(devm_led_classdev_release, sizeof(*dr), GFP_KERNEL);
>           <-- dr->node.release = devm_led_classdev_release()
>           ...
>           devres_add(parent, dr);
>           <-- add dr->node to &priv->dev->devres_head
> 
> And the full deallocation order should be this:
> 
> 1. SPI device .remove callback
> 2. LED device devm_*()
> 3. SPI device deallocation
> 
> spi_unregister_device()
>    device_del()
>      bus_remove_device()
>        device_release_driver_internal()
>          __device_release_driver()
>            ...
> 	  device_remove()
> 	    spi_remove()   <-- call el15203000_remove() here, mutex_destroy(&priv->lock), lock destroy
>            ...
>            device_unbind_cleanup()
>              devres_release_all()
>                release_nodes()
>                <-- traverse spi->dev->devres_head list and call dr->node.release in sequence.
>                     devm_led_classdev_release()
>                       led_classdev_unregister()
>                       <-- flush set_brightness_work here, before the work flush, set_brightness_work may be sched.
>                       <-- that is el15203000_set_blocking()..-> mutex_lock(&led->priv->lock) is called,
>                       <-- this leads to the priv->lock use after destroy.
>   put_device(&spi->dev) <-- spi device is deallocation in here
> 
>
Hi Oleh,

Judging from the deallocation order above, there is a issue that the 
&priv->lock used after destroy, right?

And thanks Wei for the detailed explanation.

Thanks,
Wang


> Regards,
> Wei Yongjun
> 


  reply	other threads:[~2022-11-22  1:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  8:48 [PATCH 00/13] leds: Fix devm vs. non-devm ordering Wang Yufen
2022-11-09  8:48 ` [PATCH 01/13] leds: cr0014114: " Wang Yufen
2022-11-09  8:48 ` [PATCH 02/13] leds: el15203000: " Wang Yufen
2022-11-09  9:39   ` Oleh Kravchenko
2022-11-09 10:25     ` wangyufen
2022-11-09 10:43       ` Oleh Kravchenko
     [not found]         ` <c53e4614-eb06-cda8-f9da-2ca58396df54@huawei.com>
2022-11-11 10:39           ` Oleh Kravchenko
2022-11-15  2:06             ` Wei Yongjun
2022-11-22  1:10               ` Wang Yufen [this message]
2022-11-25 22:21                 ` Oleh Kravchenko
2022-11-09  8:48 ` [PATCH 03/13] leds: lm3532: " Wang Yufen
2022-11-09  8:48 ` [PATCH 04/13] leds: lm3692x: " Wang Yufen
2022-11-09  8:48 ` [PATCH 05/13] leds: lm3697: " Wang Yufen
2022-11-09  8:48 ` [PATCH 06/13] leds: lp50xx: " Wang Yufen
2022-11-09  8:48 ` [PATCH 07/13] leds: lp8860: " Wang Yufen
2022-11-09  8:48 ` [PATCH 08/13] leds: mlxreg: " Wang Yufen
2022-11-09  8:48 ` [PATCH 09/13] leds: mt6323: " Wang Yufen
2022-11-09  8:48 ` [PATCH 10/13] leds: powernv: " Wang Yufen
2022-11-09  8:48 ` [PATCH 11/13] leds: sc27xx: " Wang Yufen
2022-11-09  8:48 ` [PATCH 12/13] leds: spi-byte: " Wang Yufen
2022-11-09  8:48 ` [PATCH 13/13] leds: rt8515: " Wang Yufen
2022-12-07 20:20 ` [PATCH 00/13] leds: " Pavel Machek
2022-12-08  2:23   ` wangyufen

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=f5969fbb-bdbb-6841-e1db-3c32a7a27061@huaweicloud.com \
    --to=wangyufen@huaweicloud.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=oleg@kaa.org.ua \
    --cc=pavel@ucw.cz \
    --cc=weiyongjun@huaweicloud.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.