From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: rjw@rjwysocki.net, lukasz.luba@arm.com, robh@kernel.org,
heiko@sntech.de, arnd@linaro.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>
Subject: Re: [PATCH v5 2/6] powercap/drivers/dtpm: Add hierarchy creation
Date: Wed, 5 Jan 2022 17:00:16 +0100 [thread overview]
Message-ID: <8fcc0ef8-b0c7-da73-434f-31c88896aed5@linaro.org> (raw)
In-Reply-To: <CAPDyKFrLTsUxG8JHdK33h2BT8pxeHk6kiU-4uGrvxUhcQKg3Sw@mail.gmail.com>
On 31/12/2021 14:45, Ulf Hansson wrote:
[ ... ]
>> +static struct dtpm *dtpm_setup_dt(const struct dtpm_node *hierarchy,
>> + struct dtpm *parent)
>> +{
>> + struct dtpm_descr *dtpm_descr;
>> + struct device_node *np;
>> + int ret;
>> +
>> + np = of_find_node_by_path(hierarchy->name);
>> + if (!np) {
>> + pr_err("Failed to find '%s'\n", hierarchy->name);
>> + return ERR_PTR(-ENXIO);
>> + }
>> +
>> + for_each_dtpm_table(dtpm_descr) {
>> +
>> + ret = dtpm_descr->setup(parent, np);
>
> This will unconditionally call the ->setup callback() for each dtpm
> desc in the dtpm table. At this point the ->setup() callback has not
> been assigned by anyone that uses DTPM_DECLARE(), so if this would be
> called, it would trigger a NULL pointer dereference error.
>
> On the other hand, we don't have someone calling
> dtpm_create_hierarchy() yet, so this code doesn't get exercised, but
Yes, that is the reason why the test is not here.
> it still looks a bit odd to me. Maybe squashing patch2 and patch3 is
> an option?
Sure
>> + if (ret) {
>> + pr_err("Failed to setup '%s': %d\n", hierarchy->name, ret);
>> + of_node_put(np);
>> + return ERR_PTR(ret);
>> + }
>> +
>> + of_node_put(np);
>
> This will be called for every loop in the dtpm table. This is wrong,
> you only want to call it once, outside the loop.
Right, good catch
>> + }
>> +
>> + /*
>> + * By returning a NULL pointer, we let know the caller there
>> + * is no child for us as we are a leaf of the tree
>> + */
>> + return NULL;
>> +}
>> +
>> +typedef struct dtpm * (*dtpm_node_callback_t)(const struct dtpm_node *, struct dtpm *);
>> +
>> +dtpm_node_callback_t dtpm_node_callback[] = {
>> + [DTPM_NODE_VIRTUAL] = dtpm_setup_virtual,
>> + [DTPM_NODE_DT] = dtpm_setup_dt,
>> +};
>> +
>> +static int dtpm_for_each_child(const struct dtpm_node *hierarchy,
>> + const struct dtpm_node *it, struct dtpm *parent)
>> +{
>> + struct dtpm *dtpm;
>> + int i, ret;
>> +
>> + for (i = 0; hierarchy[i].name; i++) {
>> +
>> + if (hierarchy[i].parent != it)
>> + continue;
>> +
>> + dtpm = dtpm_node_callback[hierarchy[i].type](&hierarchy[i], parent);
>> + if (!dtpm || IS_ERR(dtpm))
>> + continue;
>> +
>> + ret = dtpm_for_each_child(hierarchy, &hierarchy[i], dtpm);
>
> Why do you need to recursively call dtpm_for_each_child() here?
>
> Is there a restriction on how the dtpm core code manages adding
> children/parents?
[ ... ]
The recursive call is needed given the structure of the tree in an array
in order to connect with the parent.
>> + *
>> + * struct dtpm_node hierarchy[] = {
>> + * [0] { .name = "topmost" },
>
> For clarity, I think we should also specify DTPM_NODE_VIRTUAL here.
>
>> + * [1] { .name = "package", .parent = &hierarchy[0] },
>
> Ditto.
Sure
[ ... ]
>> +static int __init init_dtpm(void)
>> +{
>> pct = powercap_register_control_type(NULL, "dtpm", NULL);
>> if (IS_ERR(pct)) {
>> pr_err("Failed to register control type\n");
>> return PTR_ERR(pct);
>> }
>
> It looks like powercap_register_control_type() should be able to be
> called from dtpm_create_hierarchy(). In this way we can simply drop
> the initcall below, altogether.
>
> Of course, that assumes that dtpm_create_hierachy() is being called
> from a regular module_platform_driver() path - or at least from a
> later initcall than fs_initcall(), which is when the "powercap_class"
> is being registered. But that sounds like a reasonable assumption we
> should be able to make, no?
Yes, agree. Good suggestion, I will do the change.
[ ... ]
>> int dtpm_register(const char *name, struct dtpm *dtpm, struct dtpm *parent);
>>
>> +int dtpm_create_hierarchy(struct of_device_id *dtpm_match_table);
>
> To start simple, I think dtpm_create_hiearchy() is the sufficient
> interface to add at this point.
>
> However, it's quite likely that it's going to be called from a regular
> module (SoC specific platform driver), which means it needs to manage
> ->remove() operations too. Anyway, I am fine if we look into that as
> improvements on top of the $subject series.
Yes, ATM, the modules can not be unloaded on purpose. The removal can be
added later
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
next prev parent reply other threads:[~2022-01-05 16:00 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-18 13:00 [PATCH v5 0/6] powercap/drivers/dtpm: Create the dtpm hierarchy Daniel Lezcano
2021-12-18 13:00 ` [PATCH v5 1/6] powercap/drivers/dtpm: Move dtpm table from init to data section Daniel Lezcano
2021-12-31 13:33 ` Ulf Hansson
2022-01-04 8:57 ` Daniel Lezcano
2022-01-07 13:15 ` Daniel Lezcano
2022-01-07 14:49 ` Ulf Hansson
2022-01-10 13:33 ` Daniel Lezcano
2021-12-18 13:00 ` [PATCH v5 2/6] powercap/drivers/dtpm: Add hierarchy creation Daniel Lezcano
2021-12-31 13:45 ` Ulf Hansson
2022-01-05 16:00 ` Daniel Lezcano [this message]
2022-01-07 15:54 ` Ulf Hansson
2022-01-10 15:55 ` Daniel Lezcano
2022-01-11 8:28 ` Ulf Hansson
2022-01-11 17:52 ` Daniel Lezcano
2022-01-12 12:00 ` Ulf Hansson
2022-01-14 19:15 ` Daniel Lezcano
2021-12-18 13:00 ` [PATCH v5 3/6] powercap/drivers/dtpm: Add CPU DT initialization support Daniel Lezcano
2021-12-31 13:46 ` Ulf Hansson
2021-12-18 13:00 ` [PATCH v5 4/6] powercap/drivers/dtpm: Add dtpm devfreq with energy model support Daniel Lezcano
2021-12-18 13:00 ` [PATCH v5 5/6] rockchip/soc/drivers: Add DTPM description for rk3399 Daniel Lezcano
2021-12-31 13:57 ` Ulf Hansson
2022-01-04 9:29 ` Geert Uytterhoeven
2022-01-05 9:21 ` Daniel Lezcano
2022-01-05 11:25 ` Daniel Lezcano
2021-12-18 13:00 ` [PATCH v5 6/6] qcom/soc/drivers: Add DTPM description for sdm845 Daniel Lezcano
2021-12-18 19:47 ` Steev Klimaszewski
2021-12-18 20:11 ` Daniel Lezcano
2021-12-19 18:44 ` Steev Klimaszewski
2021-12-19 20:27 ` Daniel Lezcano
2022-01-07 19:27 ` Bjorn Andersson
2022-01-07 22:07 ` Daniel Lezcano
2022-01-07 23:51 ` Bjorn Andersson
2021-12-23 13:20 ` [PATCH v5 0/6] powercap/drivers/dtpm: Create the dtpm hierarchy Daniel Lezcano
2021-12-23 13:32 ` Ulf Hansson
2021-12-23 13:42 ` Daniel Lezcano
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=8fcc0ef8-b0c7-da73-434f-31c88896aed5@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=arnd@linaro.org \
--cc=daniel.lezcano@kernel.org \
--cc=heiko@sntech.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
--cc=robh@kernel.org \
--cc=ulf.hansson@linaro.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).