From: Nicholas Mc Guire <hidden> Date: 2018-12-07 08:28:38
devm_kstrdup() may return NULL if internal allocation failed, but
as machine is from the device tree, and thus RO, devm_kstrdup_const()
can be used here, which will only copy the reference.
Signed-off-by: Nicholas Mc Guire <redacted>
Fixes: a6fc3b698130 ("soc: fsl: add GUTS driver for QorIQ platforms")
---
Problem located by experimental coccinelle script
Patch was compile tested with: multi_v7_defconfig (implies FSL_GUTS=y)
Patch is against 4.20-rc5 (localversion-next is next-20181207)
drivers/soc/fsl/guts.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
From: Scott Wood <oss@buserror.net> Date: 2018-12-22 02:30:08
On Fri, 2018-12-07 at 09:22 +0100, Nicholas Mc Guire wrote:
devm_kstrdup() may return NULL if internal allocation failed, but
as machine is from the device tree, and thus RO, devm_kstrdup_const()
can be used here, which will only copy the reference.
Is it really going to only copy the reference? That would require that
is_kernel_rodata(machine) be true, which it shouldn't be since it's not part
of the kernel image.
-Scott
From: Nicholas Mc Guire <hidden> Date: 2018-12-22 16:49:59
On Fri, Dec 21, 2018 at 08:29:56PM -0600, Scott Wood wrote:
On Fri, 2018-12-07 at 09:22 +0100, Nicholas Mc Guire wrote:
quoted
devm_kstrdup() may return NULL if internal allocation failed, but
as machine is from the device tree, and thus RO, devm_kstrdup_const()
can be used here, which will only copy the reference.
Is it really going to only copy the reference? That would require that
is_kernel_rodata(machine) be true, which it shouldn't be since it's not part
of the kernel image.
I had tried to figure out what is RO and what not but was not
able to determine that - from the discussion it seemed that the
assumption of RO is correct though I did not ask if it would
satisfy is_kernel_rodata() so that explains the incorrect assertion.
see https://lkml.org/lkml/2018/12/6/42
So then the only option is to check the return and cleanup
on allocation failure as the orriginal patch proposed.
thanks for clearifying this !
hofrat
On Sat, Dec 22, 2018 at 2:02 AM Nicholas Mc Guire [off-list ref] wrote:
On Fri, Dec 21, 2018 at 08:29:56PM -0600, Scott Wood wrote:
quoted
On Fri, 2018-12-07 at 09:22 +0100, Nicholas Mc Guire wrote:
quoted
devm_kstrdup() may return NULL if internal allocation failed, but
as machine is from the device tree, and thus RO, devm_kstrdup_const()
can be used here, which will only copy the reference.
Is it really going to only copy the reference? That would require that
is_kernel_rodata(machine) be true, which it shouldn't be since it's not part
of the kernel image.
I had tried to figure out what is RO and what not but was not
able to determine that - from the discussion it seemed that the
assumption of RO is correct though I did not ask if it would
satisfy is_kernel_rodata() so that explains the incorrect assertion.
see https://lkml.org/lkml/2018/12/6/42
So then the only option is to check the return and cleanup
on allocation failure as the orriginal patch proposed.
Thanks for the good discussion. I will drop the previous patch. But
would it also be good to just have "soc_dev_attr.machine = machine"
directly?
Regards,
Leo
From: Nicholas Mc Guire <hidden> Date: 2019-01-11 02:43:53
On Thu, Jan 10, 2019 at 01:43:01PM -0600, Li Yang wrote:
On Sat, Dec 22, 2018 at 2:02 AM Nicholas Mc Guire [off-list ref] wrote:
quoted
On Fri, Dec 21, 2018 at 08:29:56PM -0600, Scott Wood wrote:
quoted
On Fri, 2018-12-07 at 09:22 +0100, Nicholas Mc Guire wrote:
quoted
devm_kstrdup() may return NULL if internal allocation failed, but
as machine is from the device tree, and thus RO, devm_kstrdup_const()
can be used here, which will only copy the reference.
Is it really going to only copy the reference? That would require that
is_kernel_rodata(machine) be true, which it shouldn't be since it's not part
of the kernel image.
I had tried to figure out what is RO and what not but was not
able to determine that - from the discussion it seemed that the
assumption of RO is correct though I did not ask if it would
satisfy is_kernel_rodata() so that explains the incorrect assertion.
see https://lkml.org/lkml/2018/12/6/42
So then the only option is to check the return and cleanup
on allocation failure as the orriginal patch proposed.
Thanks for the good discussion. I will drop the previous patch. But
would it also be good to just have "soc_dev_attr.machine = machine"
directly?
I think that the intent is to switch to
managed devm API so that the cleanup is handled properly
currently you would get "machine" from
of_property_read_string_index
-> of_property_read_string_helper
-> of_find_property
which does not do any allocation - so there would actually
not be anything to cleanup here - don´t see why your solution
would not be suitable given the current API. the only advantage
of the devm_kstrdup() is that underlying APIs internal changes
would have no effect.
thx!
hofrat
-----Original Message-----
From: Nicholas Mc Guire <redacted>
Sent: Thursday, January 10, 2019 8:44 PM
To: Leo Li <redacted>
Cc: Scott Wood <oss@buserror.net>; linuxppc-dev <linuxppc-
dev@lists.ozlabs.org>; lkml [off-list ref]; moderated
list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE <linux-arm-
kernel@lists.infradead.org>; Nicholas Mc Guire [off-list ref]
Subject: Re: [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
On Thu, Jan 10, 2019 at 01:43:01PM -0600, Li Yang wrote:
quoted
On Sat, Dec 22, 2018 at 2:02 AM Nicholas Mc Guire [off-list ref]
wrote:
quoted
quoted
On Fri, Dec 21, 2018 at 08:29:56PM -0600, Scott Wood wrote:
quoted
On Fri, 2018-12-07 at 09:22 +0100, Nicholas Mc Guire wrote:
quoted
devm_kstrdup() may return NULL if internal allocation failed,
but as machine is from the device tree, and thus RO,
devm_kstrdup_const() can be used here, which will only copy the
reference.
quoted
quoted
quoted
Is it really going to only copy the reference? That would require
that
is_kernel_rodata(machine) be true, which it shouldn't be since
it's not part of the kernel image.
I had tried to figure out what is RO and what not but was not able
to determine that - from the discussion it seemed that the
assumption of RO is correct though I did not ask if it would satisfy
is_kernel_rodata() so that explains the incorrect assertion.
see
VPFtkfllgnwpEIkkTIgw0K%2Fovg%3D&reserved=0
So then the only option is to check the return and cleanup on
allocation failure as the orriginal patch proposed.
Thanks for the good discussion. I will drop the previous patch. But
would it also be good to just have "soc_dev_attr.machine = machine"
directly?
I think that the intent is to switch to managed devm API so that the cleanup is
handled properly currently you would get "machine" from
of_property_read_string_index
-> of_property_read_string_helper
-> of_find_property
which does not do any allocation - so there would actually not be anything to
cleanup here - don´t see why your solution would not be suitable given the
current API. the only advantage of the devm_kstrdup() is that underlying
APIs internal changes would have no effect.
Thanks. I will sent out a new version.
Regards,
Leo