Linux-ARM-Kernel Archive on lore.kernel.org
 help / Atom feed
* [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
@ 2018-12-07  8:22 Nicholas Mc Guire
  2018-12-22  2:29 ` Scott Wood
  0 siblings, 1 reply; 6+ messages in thread
From: Nicholas Mc Guire @ 2018-12-07  8:22 UTC (permalink / raw)
  To: Li Yang; +Cc: linuxppc-dev, linux-kernel, linux-arm-kernel, Nicholas Mc Guire

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 <hofrat@osadl.org>
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(-)

diff --git a/drivers/soc/fsl/guts.c b/drivers/soc/fsl/guts.c
index 302e0c8..15071ec 100644
--- a/drivers/soc/fsl/guts.c
+++ b/drivers/soc/fsl/guts.c
@@ -157,7 +157,8 @@ static int fsl_guts_probe(struct platform_device *pdev)
 		of_property_read_string_index(root, "compatible", 0, &machine);
 	of_node_put(root);
 	if (machine)
-		soc_dev_attr.machine = devm_kstrdup(dev, machine, GFP_KERNEL);
+		soc_dev_attr.machine = devm_kstrdup_const(dev, machine,
+							  GFP_KERNEL);
 
 	svr = fsl_guts_get_svr();
 	soc_die = fsl_soc_die_match(svr, fsl_soc_die);
-- 
2.1.4


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
  2018-12-07  8:22 [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data Nicholas Mc Guire
@ 2018-12-22  2:29 ` Scott Wood
  2018-12-22  7:59   ` Nicholas Mc Guire
  0 siblings, 1 reply; 6+ messages in thread
From: Scott Wood @ 2018-12-22  2:29 UTC (permalink / raw)
  To: Nicholas Mc Guire, Li Yang; +Cc: linuxppc-dev, linux-kernel, linux-arm-kernel

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



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
  2018-12-22  2:29 ` Scott Wood
@ 2018-12-22  7:59   ` Nicholas Mc Guire
  2019-01-10 19:43     ` Li Yang
  0 siblings, 1 reply; 6+ messages in thread
From: Nicholas Mc Guire @ 2018-12-22  7:59 UTC (permalink / raw)
  To: Scott Wood
  Cc: Li Yang, linuxppc-dev, linux-kernel, linux-arm-kernel, Nicholas Mc Guire

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:
> > 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
  2018-12-22  7:59   ` Nicholas Mc Guire
@ 2019-01-10 19:43     ` Li Yang
  2019-01-11  2:43       ` Nicholas Mc Guire
  0 siblings, 1 reply; 6+ messages in thread
From: Li Yang @ 2019-01-10 19:43 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Scott Wood, linuxppc-dev, lkml,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	Nicholas Mc Guire

On Sat, Dec 22, 2018 at 2:02 AM Nicholas Mc Guire <der.herr@hofr.at> wrote:
>
> 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:
> > > 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
  2019-01-10 19:43     ` Li Yang
@ 2019-01-11  2:43       ` Nicholas Mc Guire
  2019-01-11 21:32         ` Leo Li
  0 siblings, 1 reply; 6+ messages in thread
From: Nicholas Mc Guire @ 2019-01-11  2:43 UTC (permalink / raw)
  To: Li Yang
  Cc: Scott Wood, linuxppc-dev, lkml,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	Nicholas Mc Guire

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 <der.herr@hofr.at> wrote:
> >
> > 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:
> > > > 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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data
  2019-01-11  2:43       ` Nicholas Mc Guire
@ 2019-01-11 21:32         ` Leo Li
  0 siblings, 0 replies; 6+ messages in thread
From: Leo Li @ 2019-01-11 21:32 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Scott Wood, linuxppc-dev, lkml,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	Nicholas Mc Guire



> -----Original Message-----
> From: Nicholas Mc Guire <der.herr@hofr.at>
> Sent: Thursday, January 10, 2019 8:44 PM
> To: Leo Li <leoyang.li@nxp.com>
> Cc: Scott Wood <oss@buserror.net>; linuxppc-dev <linuxppc-
> dev@lists.ozlabs.org>; lkml <linux-kernel@vger.kernel.org>; moderated
> list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE <linux-arm-
> kernel@lists.infradead.org>; Nicholas Mc Guire <hofrat@osadl.org>
> 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:
> > On Sat, Dec 22, 2018 at 2:02 AM Nicholas Mc Guire <der.herr@hofr.at>
> wrote:
> > >
> > > 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:
> > > > > 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://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fl
> > >
> kml.org%2Flkml%2F2018%2F12%2F6%2F42&amp;data=02%7C01%7Cleoyang.l
> i%40
> > >
> nxp.com%7Cf72d70a65d1b47f6883808d6776e9d58%7C686ea1d3bc2b4c6fa92c
> d99
> > >
> c5c301635%7C0%7C1%7C636827714307963102&amp;sdata=xnaO0Y7q%2Byad
> Yv8sF
> > > VPFtkfllgnwpEIkkTIgw0K%2Fovg%3D&amp;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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-07  8:22 [PATCH] soc: fsl: guts: us devm_kstrdup_const() for RO data Nicholas Mc Guire
2018-12-22  2:29 ` Scott Wood
2018-12-22  7:59   ` Nicholas Mc Guire
2019-01-10 19:43     ` Li Yang
2019-01-11  2:43       ` Nicholas Mc Guire
2019-01-11 21:32         ` Leo Li

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox