All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jerry Van Baren <gerald.vanbaren@comcast.net>
To: linuxppc-dev@ozlabs.org
Subject: Re: libfdt: going forward for u-boot
Date: Wed, 21 Mar 2007 21:37:24 -0400	[thread overview]
Message-ID: <4601DDD4.2030105@comcast.net> (raw)
In-Reply-To: <20070322012507.GF2295@localhost.localdomain>

David Gibson wrote:
> On Wed, Mar 21, 2007 at 09:12:31PM -0400, Jerry Van Baren wrote:
>> David Gibson wrote:

[snip]

>>>> fdt_rw.c
>>>> --------
>>>> * Nonessential improvements to fdt_open_into()
>>>>   * Validate the header (fdt_move() does the validation, but I skip
>>>>       the move if buf == fdt so I needed to add the validation)
>>>>   * Do the fdt_move() only if (buf != fdt) - I call this at times with
>>>>       a new (longer) length but don't want to actually move the blob,
>>>>       just want the longer length so I can modify the fdt in-place.  The
>>>>       current code works, but it seemed silly to do a move if I'm not
>>>>       actually moving it.
>>> If fdt == buf, the memmove() in fdt_move() will become a no-op in any
>>> case.  I don't see any point to conditionalizing the fdt_move().
>> But it allows me to make the blob bigger.  Ahh, it looks like all I need 
>> to do is:
>>          fdt_set_header(fdt, totalsize, bufsize);
>> so I agree, I'm working way too hard on this one.
> 
> No, if you want to make more space to do edits in, you should
> definitely be using fdt_open_into() - that's the purpose of
> fdt_open_into().  I'm just saying there's no need to conditionalize
> the fdt_move(), because fdt_move() *already* correctly handles the
> case where fdt==buf.

Not in my copy unless the memmove() implementation counts.
--------------------------------
int fdt_move(const void *fdt, void *buf, int bufsize)
{
         int err = _fdt_check_header(fdt);

         if (err)
                 return err;

         if (fdt_totalsize(fdt) > bufsize)
                 return -FDT_ERR_NOSPACE;

         memmove(buf, fdt, fdt_totalsize(fdt));
         return 0;
}
--------------------------------
--- a/fdt_rw.c
+++ b/fdt_rw.c
@@ -260,11 +260,19 @@ int fdt_del_node(void *fdt, int nodeoffset)

  int fdt_open_into(void *fdt, void *buf, int bufsize)
  {
-       int err;
-
-       err = fdt_move(fdt, buf, bufsize);
-       if (err)
-               return err;
+        int err = rw_check_header(fdt);
+
+        if (err)
+                return err;
+
+       /*
+        * If we are just expanding the size in-place, no need to do the 
move.
+        */
+       if (buf != fdt) {
+               err = fdt_move(fdt, buf, bufsize);
+               if (err)
+                       return err;
+       }

         fdt = buf;

--------------------------------
(Yes, the above is whitespace damaged.  It ain't a patch ;-)

Best regards,
gvb

  reply	other threads:[~2007-03-22  1:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-22  0:08 libfdt: going forward for u-boot Jerry Van Baren
2007-03-22  0:49 ` David Gibson
2007-03-22  1:12   ` Jerry Van Baren
2007-03-22  1:25     ` David Gibson
2007-03-22  1:37       ` Jerry Van Baren [this message]
2007-03-22  1:49         ` David Gibson
2007-03-22 11:16   ` Segher Boessenkool
2007-03-22 16:42   ` Hollis Blanchard
2007-03-23  4:17     ` David Gibson

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=4601DDD4.2030105@comcast.net \
    --to=gerald.vanbaren@comcast.net \
    --cc=linuxppc-dev@ozlabs.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.