From: Zijun Hu <zijun_hu@icloud.com>
To: Rob Herring <robh@kernel.org>
Cc: Saravana Kannan <saravanak@google.com>,
Leif Lindholm <leif.lindholm@linaro.org>,
Stephen Boyd <stephen.boyd@linaro.org>,
Maxime Ripard <mripard@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Grant Likely <grant.likely@secretlab.ca>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Zijun Hu <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH 05/10] of: Fix available buffer size calculating error in API of_device_uevent_modalias()
Date: Tue, 10 Dec 2024 20:39:27 +0800 [thread overview]
Message-ID: <14fe473e-5f56-4a61-899c-bbb79e2aed3b@icloud.com> (raw)
In-Reply-To: <CAL_JsqL+CRmCQMzcF4-A-PRBrCsfK8nduJtOO=RrsDtCUUR7og@mail.gmail.com>
On 2024/12/10 04:34, Rob Herring wrote:
> On Thu, Dec 5, 2024 at 6:53 PM Zijun Hu <zijun_hu@icloud.com> wrote:
>>
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> of_device_uevent_modalias() saves MODALIAS value from offset
>> (@env->buflen - 1), so the available buffer size should be
>> (sizeof(@env->buf) - @env->buflen + 1), but it uses the wrong
>> size (sizeof(@env->buf) - @env->buflen).
>>
>> Fix by using right size (sizeof(@env->buf) - @env->buflen + 1).
>
> Just writing what the diff says already is not that useful. The key
> part you need to know is why we back up by 1 character to begin with.
>
will correct commit message in v2.
>>
>> Fixes: dd27dcda37f0 ("of/device: merge of_device_uevent")
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
>> ---
>> drivers/of/device.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/of/device.c b/drivers/of/device.c
>> index edf3be1972658f6dc165f577da53b10c7eebc116..ee29c07c83b9e6abd9b1c7747dd341026bc79eb0 100644
>> --- a/drivers/of/device.c
>> +++ b/drivers/of/device.c
>> @@ -266,10 +266,10 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *
>> return -ENOMEM;
>>
>> sl = of_modalias(dev->of_node, &env->buf[env->buflen-1],
>
> This could use a comment why we back up by 1. Better to put it in a
> variable than add/subtract 1 everywhere:
>
> /* After add_uevent_event(), buflen is at character after the nul char
> which needs to be overwritten */
> buflen = env->buflen - 1;
>
> And then use 'buflen' throughout.
>
good proposal. may use it for v2 after discussion done.
>> - sizeof(env->buf) - env->buflen);
>> + sizeof(env->buf) - env->buflen + 1);
>> if (sl < 0)
>> return sl;
>> - if (sl >= (sizeof(env->buf) - env->buflen))
>> + if (sl >= (sizeof(env->buf) - env->buflen + 1))
>> return -ENOMEM;
>
> There's another potential problem. If we return before here, we end up
> with "OF_MODALIAS=\0" or "OF_MODALIAS=some-non-nul-terminated-str".
> Maybe that doesn't matter? I haven't looked at the caller.
>
that does not matter since current logic follows below 2 rules
1) all strings in @env->buf always terminated with '\0'.
2) both env->buflen and env->envp_idx are not updated once @env->buf
does not enough spaces then failed.
current logic has no difference with normal add_uevent_var() usage.
> I think a better solution to all this would be making add_uevent_var
> work to construct the full value. We could add "%pOFm" format that
> calls of_mod_alias(). Then this function becomes just:
>
of_modalias() ?
agree with you.
for good practice, users should only use uevent APIs and should not
depend on uevent's internal implementation.
> return add_uevent_var(env, "MODALIAS=%pOFm");
>
> And of_device_modalias() can be:
>
> sl = snprintf(str, len, "%pOFm\n", dev->of_node);
> if (sl >= len)
> return -ENOMEM;
> return sl;
>
looks good.
of_request_module() provides another solution.
> Rob
next prev parent reply other threads:[~2024-12-10 12:39 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 0:52 [PATCH 00/10] of: fix bugs and improve codes Zijun Hu
2024-12-06 0:52 ` [PATCH 01/10] of: Fix alias name length calculating error in API of_find_node_opts_by_path() Zijun Hu
2024-12-09 13:24 ` Rob Herring
2024-12-09 13:31 ` Zijun Hu
2024-12-06 0:52 ` [PATCH 02/10] of: Correct return value for API of_parse_phandle_with_args_map() Zijun Hu
2024-12-09 13:26 ` Rob Herring
2024-12-06 0:52 ` [PATCH 03/10] of: Correct child specifier used as input of the 2nd nexus node Zijun Hu
2024-12-06 0:52 ` [PATCH 04/10] of: Fix refcount leakage for OF node returned by __of_get_dma_parent() Zijun Hu
2024-12-09 20:32 ` Rob Herring
2024-12-06 0:52 ` [PATCH 05/10] of: Fix available buffer size calculating error in API of_device_uevent_modalias() Zijun Hu
2024-12-09 20:34 ` Rob Herring
2024-12-10 12:39 ` Zijun Hu [this message]
2024-12-10 14:10 ` Rob Herring
2024-12-11 11:44 ` Zijun Hu
2024-12-06 0:52 ` [PATCH 06/10] of/fdt: Dump __be32 array in CPU type order in of_dump_addr() Zijun Hu
2024-12-09 20:37 ` Rob Herring
2024-12-06 0:52 ` [PATCH 07/10] of: Correct comments for of_alias_scan() Zijun Hu
2024-12-09 13:20 ` Rob Herring
2024-12-09 13:41 ` Zijun Hu
2024-12-06 0:52 ` [PATCH 08/10] of: Swap implementation between of_property_present() and of_property_read_bool() Zijun Hu
2024-12-06 0:52 ` [PATCH 09/10] of: property: Implement of_fwnode_property_present() by of_property_present() Zijun Hu
2024-12-09 16:48 ` Rob Herring
2024-12-10 12:44 ` Zijun Hu
2024-12-10 13:37 ` Robin Murphy
2024-12-06 0:52 ` [PATCH 10/10] of: Simplify API of_find_node_with_property() implementation Zijun Hu
2024-12-09 20:38 ` Rob Herring
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=14fe473e-5f56-4a61-899c-bbb79e2aed3b@icloud.com \
--to=zijun_hu@icloud.com \
--cc=devicetree@vger.kernel.org \
--cc=grant.likely@secretlab.ca \
--cc=leif.lindholm@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mripard@kernel.org \
--cc=quic_zijuhu@quicinc.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=saravanak@google.com \
--cc=stephen.boyd@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
all inboxes | Powered by JetHome®