mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Marcin Niestroj <m.niestroj@grinn-global.com>
Subject: [PATCH] fs: ramfs: make chunk counting in truncate() better readable
Date: Wed, 26 Sep 2018 10:10:29 +0200	[thread overview]
Message-ID: <20180926081029.28103-1-s.hauer@pengutronix.de> (raw)

In ramfs_truncate() "newchunks" denotes the number of chunks we
want to have after the call. We decrease that number while iterating
over the existing chunks and decrease it further with every newly
allocated chunk until "newchunks" is zero.
This is a bit hard to read. Instead we drop the decreasing while
iterating over existing chunks and increase "oldchunks" while allocating
until it reaches "newchunks".

This is mainly done to make the next patch easier.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/ramfs.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/ramfs.c b/fs/ramfs.c
index 09dafe02ae..8ba8d77de9 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -384,19 +384,18 @@ static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
 			if (!node->data)
 				return -ENOMEM;
 			data = node->data;
+			newchunks = 1;
 		}
 
-		newchunks--;
-		while (data->next) {
-			newchunks--;
+		while (data->next)
 			data = data->next;
-		}
 
-		while (newchunks--) {
+		while (newchunks > oldchunks) {
 			data->next = ramfs_get_chunk();
 			if (!data->next)
 				return -ENOMEM;
 			data = data->next;
+			oldchunks++;
 		}
 	}
 	node->size = size;
-- 
2.19.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2018-09-26  8:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26  8:10 Sascha Hauer [this message]
2018-09-26 11:09 ` Marcin Niestrój
2018-09-26 11:22   ` Marcin Niestrój
2018-09-27  7:25     ` Sascha Hauer

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=20180926081029.28103-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=m.niestroj@grinn-global.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