devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Dong Aisheng <aisheng.dong@freescale.com>
Cc: Rob Herring <robherring2@gmail.com>,
	Dong Aisheng-B29396 <B29396@freescale.com>,
	"devicetree-discuss@lists.ozlabs.org"
	<devicetree-discuss@lists.ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Kumar Gala <galak@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH 1/1] of: reform prom_update_property function
Date: Fri, 22 Jun 2012 10:01:24 +1000	[thread overview]
Message-ID: <1340323284.16104.4.camel@pasglop> (raw)
In-Reply-To: <20120621093702.GE21231@shlinux2.ap.freescale.net>

On Thu, 2012-06-21 at 17:37 +0800, Dong Aisheng wrote:
> Maybe we could change it as as follows.
> It looks then the code follow is the same as before.
> Do you think if it's ok?
> 
> diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c
> index 7b3bf76..4c237f4 100644
> --- a/arch/powerpc/platforms/pseries/reconfig.c
> +++ b/arch/powerpc/platforms/pseries/reconfig.c
> @@ -443,6 +443,9 @@ static int do_update_property(char *buf, size_t bufsize)
>         if (!next_prop)
>                 return -EINVAL;
> 
> +       if (!strlen(name)
> +               return -ENODEV;
> +
>         newprop = new_property(name, length, value, NULL);
>         if (!newprop)
>                 return -ENOMEM;
> @@ -450,13 +453,6 @@ static int do_update_property(char *buf, size_t bufsize)
>         if (!strcmp(name, "slb-size") || !strcmp(name, "ibm,slb-size"))
>                 slb_set_size(*(int *)value);
> 
> -       oldprop = of_find_property(np, name,NULL);
> -       if (!oldprop) {
> -               if (strlen(name))
> -                       return prom_add_property(np, newprop);
> -               return -ENODEV;
> -       }

No:

IE. Old code did:

	if (property doesn't exist) {
		if (has a name)
			create_it()
		return -ENODEV;
	}

What you propose is:

	if (!has_a_name)
		return -ENODEV;

Not at all the same semantic.

 .../...
 
> > IE. The allocation of the "old" property isn't disposed of. It can't
> > because today we don't know whether any of those pointers was
> > dynamically allocated or not. IE they could point to the fdt

> Hmm, i did not see static allocated property before.
> Where can we see an exist case?

Almost all your property names and values. They are pointers to the
original fdt block, so you can't free them. But dynamically added
propreties will have kmalloc'ed pointers which should be freed. We need
to add flags to indicate that if we want to avoid leaking memory in very
dynamic environments.

> If we really have this issue, it seems of_node_release also has the same issue,
> since it frees the property without distinguish whether the property is allocated
> dynamically.

Well, actually we do have a flag:

        if (!of_node_check_flag(node, OF_DYNAMIC))
                return;

So we use that. Good. So if update property uses that flag it should be
able to know when to free or not. I forgot we had that :-)

> > string list, data block, or could be bootmem ... or could be
> > actual kernel memory.
> > 
> > We might want to extend the struct property to contain indications of
> > the allocation type so we can kfree dynamic properties properly.
> > 
> I wonder the simplest way may be not allow static allocated property, like dt
> node does i guess.

No way. We generate the device-tree way before we have an allocator
available.

> > But then there's the question of the lifetime of a property... since
> > they aren't reference counted like nodes are.
> > 
> Yes, that's a real exist problem.
> 
> Anyway, i guess we could do that work of this problem in another patch
> rather than have to in this patch series.

Cheers,
Ben.

  reply	other threads:[~2012-06-22  0:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20  5:54 [PATCH 1/1] of: reform prom_update_property function Dong Aisheng
     [not found] ` <1340171647-2815-1-git-send-email-b29396-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-06-20 13:07   ` Rob Herring
2012-06-20 13:53     ` Dong Aisheng
     [not found]     ` <4FE1CB2C.5040208-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2012-06-21  0:16       ` Benjamin Herrenschmidt
2012-06-21  9:37         ` Dong Aisheng
2012-06-22  0:01           ` Benjamin Herrenschmidt [this message]
2012-06-22  5:25             ` Dong Aisheng
     [not found]               ` <CAA+hA=RoxfXWOQbZ2i=6w8GJShbpdi4EzkQRghSi2DL5F8pAng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-22  5:39                 ` Benjamin Herrenschmidt

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=1340323284.16104.4.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=B29396@freescale.com \
    --cc=aisheng.dong@freescale.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=galak@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=robherring2@gmail.com \
    /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).