Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1719455
| From | Bjorn Andersson <bjorn.andersson@linaro.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] of/device: Fix of_device_get_modalias() buffer handling |
| Date | 2017-08-24 19:30 +0200 |
| Message-ID | <ui478-14g-7@gated-at.bofh.it> (permalink) |
| References | <uhOOK-81q-13@gated-at.bofh.it> <ui3E6-Db-31@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu 24 Aug 09:51 PDT 2017, Rob Herring wrote:
> On Wed, Aug 23, 2017 at 8:03 PM, Bjorn Andersson
> <bjorn.andersson@linaro.org> wrote:
[..]
> > @@ -206,12 +207,16 @@ static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len
> > /* Name & Type */
> > csize = snprintf(str, len, "of:N%sT%s", dev->of_node->name,
> > dev->of_node->type);
> > + tsize = csize;
> > len -= csize;
> > - str += csize;
> > + if (str)
> > + str += csize;
> >
> > of_property_for_each_string(dev->of_node, "compatible", p, compat) {
> > - if (strlen(compat) + 2 > len)
> > - break;
> > + csize = strlen(compat) + 1;
> > + tsize += csize;
> > + if (csize > len)
> > + continue;
> >
> > csize = snprintf(str, len, "C%s", compat);
>
> We could just use the snprintf to give us the length. Something like
> this following the snprintf:
>
> tsize +=csize;
> if (csize > len) {
> if (len) {
> str[0] = '\0';
> len = 0;
> }
> continue;
> }
>
> You'd need to prevent len from going negative up above too. It ends up
> being more lines but you save a strlen call. So perhaps it's fine as
> is, but since I've written it already throwing it out there...
>
Indeed, I did attempt a few variants of this as well, but ended up
taking the cost of an extra strlen() to keep the complexity of the code
down.
Regards,
Bjorn
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
[PATCH] of/device: Fix of_device_get_modalias() buffer handling Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-24 03:10 +0200
Re: [PATCH] of/device: Fix of_device_get_modalias() buffer handling Rob Herring <robh+dt@kernel.org> - 2017-08-24 19:00 +0200
Re: [PATCH] of/device: Fix of_device_get_modalias() buffer handling Bjorn Andersson <bjorn.andersson@linaro.org> - 2017-08-24 19:30 +0200
csiph-web