From: "Li.Xiubo@freescale.com" <Li.Xiubo@freescale.com>
To: Rob Herring <robherring2@gmail.com>
Cc: Grant Likely <grant.likely@linaro.org>,
Rob Herring <robh+dt@kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Pantelis Antoniou" <panto@antoniou-consulting.com>
Subject: RE: [PATCH] of: fix of_update_property()
Date: Mon, 20 Jan 2014 05:50:17 +0000 [thread overview]
Message-ID: <b61be84c13ed4056a62743e16beb70f2@BY2PR03MB505.namprd03.prod.outlook.com> (raw)
In-Reply-To: <CAL_JsqJuAv8=pBuzYO5ZGzroD1kq6gjmNsTjoVyXR=vcu+-pTA@mail.gmail.com>
> Subject: Re: [PATCH] of: fix of_update_property()
>
> On Thu, Jan 16, 2014 at 10:46 PM, Xiubo Li <Li.Xiubo@freescale.com> wrote:
> > The of_update_property() is intent to update a property in a node
>
> s/intent/indended/
>
> > and if the property does not exist, will add it to the node.
> >
> > The second search of the property is possibly won't be found, that
> > maybe removed by other thread just before the second search begain,
> > if so just retry it.
>
> How did you find this problem? Actual use or some artificial stress test?
>
Some artificial stress test at home.
> > Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
> > ---
> > drivers/of/base.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/of/base.c b/drivers/of/base.c
> > index f807d0e..d0c53bc 100644
> > --- a/drivers/of/base.c
> > +++ b/drivers/of/base.c
> > @@ -1572,6 +1572,7 @@ int of_update_property(struct device_node *np, struct
> property *newprop)
> > if (!newprop->name)
> > return -EINVAL;
> >
> > +retry:
> > oldprop = of_find_property(np, newprop->name, NULL);
> > if (!oldprop)
> > return of_add_property(np, newprop);
>
> Isn't there also a race that if you do 2 updates for a non-existent
> property and both threads try to add the property, the first one will
> succeed and the 2nd will fail. The 2nd one needs to retry as well.
>
Well, yes, that will happen.
Maybe we could add one __of_add_property() without any locks, like
__of_find_property(). And then in of_update_prperty() move the searching
and adding operations to between lock and unlock, like:
raw_spin_lock_irqsave();
oldprop = __of_find_property();
if (!oldprop) {
rc = __of_add_property(np, newprop);
...
}
...
replace the node...
...
raw_spin_unlock_irqrestore();
> Also, couldn't the node itself be removed while trying to do the update?
>
For this is between the lock operations. I think this doesn't matter here.
> There seem to be multiple problems with this code, but doing multiple
> simultaneous, conflicting updates seems like an unlikely case.
>
Yes, but this will happen in theory.
Thanks,
Best Regards,
Xiubo
next prev parent reply other threads:[~2014-01-20 5:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-17 4:46 [PATCH] of: fix of_update_property() Xiubo Li
[not found] ` < CAL_JsqJuAv8=pBuzYO5ZGzroD1kq6gjmNsTjoVyXR=vcu+-pTA@mail.gmail.com>
2014-01-17 14:49 ` Rob Herring
2014-01-17 16:42 ` Pantelis Antoniou
2014-01-20 5:50 ` Li.Xiubo [this message]
2014-02-04 17:26 ` Grant Likely
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=b61be84c13ed4056a62743e16beb70f2@BY2PR03MB505.namprd03.prod.outlook.com \
--to=li.xiubo@freescale.com \
--cc=devicetree@vger.kernel.org \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=panto@antoniou-consulting.com \
--cc=robh+dt@kernel.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).