[v2,0/3] drivers: base: Add tests showing devm handling inconsistencies

Message ID 20230329-kunit-devm-inconsistencies-test-v2-0-19feb71e864b@kernel.org
Headers
Series drivers: base: Add tests showing devm handling inconsistencies |

Message

Maxime Ripard June 28, 2023, 9:49 a.m. UTC
  Hi,

This follows the discussion here:
https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/

This shows a couple of inconsistencies with regard to how device-managed
resources are cleaned up. Basically, devm resources will only be cleaned up
if the device is attached to a bus and bound to a driver. Failing any of
these cases, a call to device_unregister will not end up in the devm
resources being released.

We had to work around it in DRM to provide helpers to create a device for
kunit tests, but the current discussion around creating similar, generic,
helpers for kunit resumed interest in fixing this.

This can be tested using the command:
./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/

I added the fix David suggested back in that discussion which does fix
the tests. The SoB is missing, since David didn't provide it back then.

Let me know what you think,
Maxime

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
Changes in v2:
- Use an init function
- Document the tests
- Add a fix for the bugs
- Link to v1: https://lore.kernel.org/r/20230329-kunit-devm-inconsistencies-test-v1-0-c33127048375@cerno.tech

---
David Gow (1):
      drivers: base: Free devm resources when unregistering a device

Maxime Ripard (2):
      drivers: base: Add basic devm tests for root devices
      drivers: base: Add basic devm tests for platform devices

 drivers/base/core.c                      |  11 ++
 drivers/base/test/.kunitconfig           |   2 +
 drivers/base/test/Kconfig                |   4 +
 drivers/base/test/Makefile               |   3 +
 drivers/base/test/platform-device-test.c | 220 +++++++++++++++++++++++++++++++
 drivers/base/test/root-device-test.c     | 108 +++++++++++++++
 6 files changed, 348 insertions(+)
---
base-commit: 53cdf865f90ba922a854c65ed05b519f9d728424
change-id: 20230329-kunit-devm-inconsistencies-test-5e5a7d01e60d

Best regards,
  

Comments

Maxime Ripard July 18, 2023, 2:35 p.m. UTC | #1
On Wed, Jun 28, 2023 at 11:49:20AM +0200, Maxime Ripard wrote:
> Hi,
> 
> This follows the discussion here:
> https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
> 
> This shows a couple of inconsistencies with regard to how device-managed
> resources are cleaned up. Basically, devm resources will only be cleaned up
> if the device is attached to a bus and bound to a driver. Failing any of
> these cases, a call to device_unregister will not end up in the devm
> resources being released.
> 
> We had to work around it in DRM to provide helpers to create a device for
> kunit tests, but the current discussion around creating similar, generic,
> helpers for kunit resumed interest in fixing this.
> 
> This can be tested using the command:
> ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
> 
> I added the fix David suggested back in that discussion which does fix
> the tests. The SoB is missing, since David didn't provide it back then.

Ping?

Maxime
  
David Gow July 19, 2023, 9:13 a.m. UTC | #2
On Wed, 28 Jun 2023 at 17:50, Maxime Ripard <mripard@kernel.org> wrote:
>
> Hi,
>
> This follows the discussion here:
> https://lore.kernel.org/linux-kselftest/20230324123157.bbwvfq4gsxnlnfwb@houat/
>
> This shows a couple of inconsistencies with regard to how device-managed
> resources are cleaned up. Basically, devm resources will only be cleaned up
> if the device is attached to a bus and bound to a driver. Failing any of
> these cases, a call to device_unregister will not end up in the devm
> resources being released.
>
> We had to work around it in DRM to provide helpers to create a device for
> kunit tests, but the current discussion around creating similar, generic,
> helpers for kunit resumed interest in fixing this.
>
> This can be tested using the command:
> ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/base/test/
>
> I added the fix David suggested back in that discussion which does fix
> the tests. The SoB is missing, since David didn't provide it back then.
>
> Let me know what you think,
> Maxime
>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>
> ---

Whoops, sorry. This managed to hide in my inbox. I think it looks
good, and am happy for you to add by SoB to the patch.

I've sent out reviews to the others with some small nitpicky things.

Thanks a bunch,
-- David

> Changes in v2:
> - Use an init function
> - Document the tests
> - Add a fix for the bugs
> - Link to v1: https://lore.kernel.org/r/20230329-kunit-devm-inconsistencies-test-v1-0-c33127048375@cerno.tech
>
> ---
> David Gow (1):
>       drivers: base: Free devm resources when unregistering a device
>
> Maxime Ripard (2):
>       drivers: base: Add basic devm tests for root devices
>       drivers: base: Add basic devm tests for platform devices
>
>  drivers/base/core.c                      |  11 ++
>  drivers/base/test/.kunitconfig           |   2 +
>  drivers/base/test/Kconfig                |   4 +
>  drivers/base/test/Makefile               |   3 +
>  drivers/base/test/platform-device-test.c | 220 +++++++++++++++++++++++++++++++
>  drivers/base/test/root-device-test.c     | 108 +++++++++++++++
>  6 files changed, 348 insertions(+)
> ---
> base-commit: 53cdf865f90ba922a854c65ed05b519f9d728424
> change-id: 20230329-kunit-devm-inconsistencies-test-5e5a7d01e60d
>
> Best regards,
> --
> Maxime Ripard <mripard@kernel.org>
>