power: sequencing: add kunit test cases
Subsystems (2)
v2 cover power: sequencing: add kunit test cases
Add a set of kunit test cases for the power sequencing subsystem. Also fix issues noticed when writing the tests.
---
Changes in v2:
- Add more fixes to bugs pointed out by sashiko
- Link to v1: https://patch.msgid.link/[email protected]
---
Bartosz Golaszewski (4):
power: sequencing: don't call .post_enable() if pwrseq_unit_enable() failed
power: sequencing: fix NULL-pointer dereference in pwrseq_unit_new()
power: sequencing: fix NULL-pointer dereference in pwrseq_device_register()
power: sequencing: add kunit test cases
drivers/power/sequencing/Kconfig | 10 + drivers/power/sequencing/Makefile | 1 + drivers/power/sequencing/core.c | 11 +- drivers/power/sequencing/pwrseq-kunit.c | 1497 +++++++++++++++++++++++++++++++ 4 files changed, 1515 insertions(+), 4 deletions(-)
---
base-commit: df2908090cda368b01ff43709f51890076c56157
change-id: 20260629-pwrseq-kunit-367029f9b446
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
PATCH v2 1/4 power: sequencing: don't call .post_enable() if pwrseq_unit_enable() failed
If the call to pwrseq_unit_enable() failed in pwrseq_enable(), bail out instead of calling target->post_enable() which assumes the target was successfully enabled.
--- drivers/power/sequencing/core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/power/sequencing/core.c +2 -0
@@ -912,6 +912,8 @@ int pwrseq_enable(struct pwrseq_desc *desc)if (!ret) desc->powered_on = true; } +if (ret) +return ret;if (target->post_enable) { ret = target->post_enable (pwrseq);
Signature · 1 line
2.47.3
PATCH v2 2/4 power: sequencing: fix NULL-pointer dereference in pwrseq_unit_new()
In reply to Bartosz GolaszewskiIf memory allocation fails in pwrseq_unit_setup_deps(), pwrseq_unit_put() is called to release the partially initialized unit. However, we've never initialized unit->list and pwrseq_unit_release() will unconditionally call list_del() on it. Initialize unit->list right after allocating the unit struct.
--- drivers/power/sequencing/core.c | 1 + 1 file changed, 1 insertion(+)
drivers/power/sequencing/core.c +1 -0
@@ -101,6 +101,7 @@ static struct pwrseq_unit *pwrseq_unit_new(const struct pwrseq_unit_data *data) }kref_init (&unit->ref); +INIT_LIST_HEAD (&unit->list);INIT_LIST_HEAD (&unit->deps); unit->enable = data->enable; unit->disable = data->disable;
Signature · 1 line
2.47.3
PATCH v2 3/4 power: sequencing: fix NULL-pointer dereference in pwrseq_device_register()
In reply to Bartosz GolaszewskiIf dev_set_name() fails in pwrseq_device_register(), we jump to the err_put_pwrseq label before initializing pwrseq->targets. pwrseq_release() will try to iterate over targets unconditionally and subsequently dereference an invalid pointer. Move the call to dev_set_name() after the list head is initialized.
--- drivers/power/sequencing/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/power/sequencing/core.c +4 -4
@@ -505,10 +505,6 @@ pwrseq_device_register(const struct pwrseq_config *config)*/ device_initialize (&pwrseq->dev); - ret =dev_set_name (&pwrseq->dev,"pwrseq.%d" , pwrseq->id); -if (ret) - goto err_put_pwrseq; - pwrseq->owner = config->owner ?:THIS_MODULE ; pwrseq->match = config->match;
@@ -517,6 +513,10 @@ pwrseq_device_register(const struct pwrseq_config *config)INIT_LIST_HEAD (&pwrseq->targets);INIT_LIST_HEAD (&pwrseq->units); + ret =dev_set_name (&pwrseq->dev,"pwrseq.%d" , pwrseq->id); +if (ret) + goto err_put_pwrseq; + ret =pwrseq_setup_targets (config->targets, pwrseq);if (ret) goto err_put_pwrseq;
Signature · 1 line
2.47.3
PATCH v2 4/4 power: sequencing: add kunit test cases
In reply to Bartosz GolaszewskiAdd a set of kunit test-cases for the power sequencing subsystem. Verify several use-cases such as detecting circural dependencies, tracking of the enable-count, shared dependencies, swnode lookup, missing target on matching provider, etc.
--- drivers/power/sequencing/Kconfig | 10 + drivers/power/sequencing/Makefile | 1 + drivers/power/sequencing/pwrseq-kunit.c | 1497 +++++++++++++++++++++++++++++++ 3 files changed, 1508 insertions(+)
drivers/power/sequencing/Kconfig +10 -0
@@ -46,4 +46,14 @@ config POWER_SEQUENCING_PCIE_M2 connectors. This driver handles the power sequencing for the M.2 connectors exposing multiple interfaces like PCIe, SATA, UART, etc... +config POWER_SEQUENCING_KUNIT + tristate "Build power sequencing KUnit test cases" + depends on KUNIT + default KUNIT_ALL_TESTS + help + Say Y here to build the module containing KUnit test cases for the + power sequencing subsystem. + + If unsure, say N. + endif
drivers/power/sequencing/Makefile +1 -0
@@ -6,3 +6,4 @@ pwrseq-core-y := core.o obj-$(CONFIG_POWER_SEQUENCING_QCOM_WCN) += pwrseq-qcom-wcn.o obj-$(CONFIG_POWER_SEQUENCING_TH1520_GPU) += pwrseq-thead-gpu.o obj-$(CONFIG_POWER_SEQUENCING_PCIE_M2) += pwrseq-pcie-m2.o +obj-$(CONFIG_POWER_SEQUENCING_KUNIT) += pwrseq-kunit.o
drivers/power/sequencing/pwrseq-kunit.c new file +1497 -0
1,497 lines not on this page · raw message
Signature · 1 line
2.47.3
Re: (subset) [PATCH v2 0/4] power: sequencing: add kunit test cases
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
Add a set of kunit test cases for the power sequencing subsystem. Also fix issues noticed when writing the tests.
I'm queueing these for fixes, kunit tests will be queued separately for v7.4.
[1/4] power: sequencing: don't call .post_enable() if pwrseq_unit_enable() failed
https://git.kernel.org/brgl/c/5f90f85eae4e9d2e9628b2019870994ba830b533 [2/4] power: sequencing: fix NULL-pointer dereference in pwrseq_unit_new() https://git.kernel.org/brgl/c/115b303e8e093d964089ec6f3c40d984d77b33d0 [3/4] power: sequencing: fix NULL-pointer dereference in pwrseq_device_register() https://git.kernel.org/brgl/c/242da4318d97380741516b595af3920207b2f0f1
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
Bartosz Golaszewski
AppliedRe: (subset) [PATCH v2 0/4] power: sequencing: add kunit test cases
In reply to Bartosz GolaszewskiQuoted 4 lines · Bartosz Golaszewski
Add a set of kunit test cases for the power sequencing subsystem. Also fix issues noticed when writing the tests.
Applied, thanks!
[4/4] power: sequencing: add kunit test cases
https://git.kernel.org/brgl/c/c42e50314a7629ada42a605666b18e22867a6b44
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>