From: Matthew Wilcox <willy@debian.org>
To: linux-kernel@vger.kernel.org
Subject: [RFC] expand_resource()
Date: Fri, 26 Sep 2003 13:39:04 +0100 [thread overview]
Message-ID: <20030926123904.GI24824@parcelfarce.linux.theplanet.co.uk> (raw)
We have a situation where we descend through the resource tree and
figure out that firmware has set up the resources wrongly. This patch
allows us to grow our parent's resource to accommodate our requirements.
I'm looking for feedback at this point, not application, so I've mangled
the patch to make it hard to apply.
diff -u -p -r1.2 resource.c
--- kernel/resource.c 12 Aug 2003 19:11:29 -0000 1.2
+++ kernel/resource.c 26 Sep 2003 02:28:45 -0000
@@ -250,6 +252,62 @@ int allocate_resource(struct resource *r
err = -EBUSY;
write_unlock(&resource_lock);
return err;
+}
+
+/*
+ * Expand an existing resource by size amount.
+ */
+int expand_resource(struct resource *res, unsigned long size,
+ unsigned long align)
+{
+ unsigned long start, end;
+
+ /* see if we can expand above */
+ end = (res->end + size + align - 1) & ~(align - 1);
+
+ write_lock(&resource_lock);
+ if (res->sibling) {
+ if (res->sibling->start > end)
+ goto end;
+ } else {
+ if (res->parent->end >= end)
+ goto end;
+ }
+
+ /* now try below */
+ start = ((res->start - size + align) & ~(align - 1)) - align;
+
+ if (res->parent->child == res) {
+ if (res->start <= start)
+ goto start;
+ } else {
+ struct resource *prev = res->parent->child;
+ while (prev->sibling != res)
+ prev = prev->sibling;
+ if (prev->end < start)
+ goto start;
+ }
+
+ write_unlock(&resource_lock);
+ return -ENOMEM;
+
+ start:
+ res->start = start;
+ write_unlock(&resource_lock);
+ return 0;
+ end:
+ res->end = end;
+ write_unlock(&resource_lock);
+ return 0;
}
--
"It's not Hollywood. War is real, war is primarily not about defeat or
victory, it is about death. I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
reply other threads:[~2003-09-26 12:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20030926123904.GI24824@parcelfarce.linux.theplanet.co.uk \
--to=willy@debian.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®