linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Henri Häkkinen" <henuxd@gmail.com>
To: gregkh@suse.de, ossama.othman@intel.com, henuxd@gmail.com,
	alan@linux.intel.com, mattij.lammi@gmail.com,
	randy.dunlap@oracle.com
Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] Staging: memrar: Fixed memrar_handler.c
Date: Thu, 24 Jun 2010 10:09:46 +0300	[thread overview]
Message-ID: <1277363386-4817-2-git-send-email-henuxd@gmail.com> (raw)
In-Reply-To: <1277363386-4817-1-git-send-email-henuxd@gmail.com>

Fixed memrar_handler.c to use the new memrar_allocator API.  Removed
the corresponding issue from TODO.  Implemented locking in
memrar_allocator_largest_free_area().

Signed-off-by: Henri Häkkinen <henuxd@gmail.com
---
 drivers/staging/memrar/TODO               |   16 +---------------
 drivers/staging/memrar/memrar_allocator.c |   12 +++++++++---
 drivers/staging/memrar/memrar_handler.c   |   13 ++++---------
 3 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/memrar/TODO b/drivers/staging/memrar/TODO
index 0087447..9659aab 100644
--- a/drivers/staging/memrar/TODO
+++ b/drivers/staging/memrar/TODO
@@ -16,21 +16,7 @@ memrar_allocator.[ch]
 ---------------------
 1. Address potential fragmentation issues with the memrar_allocator.
 
-2. Hide struct memrar_allocator details/fields.  They need not be
-   exposed to the user.
-     a. Forward declare struct memrar_allocator.
-     b. Move all three struct definitions to `memrar_allocator.c'
-        source file.
-     c. Add a memrar_allocator_largest_free_area() function, or
-        something like that to get access to the value of the struct
-        memrar_allocator "largest_free_area" field.  This allows the
-        struct memrar_allocator fields to be completely hidden from
-        the user.  The memrar_handler code really only needs this for
-        statistic gathering on-demand.
-     d. Do the same for the "capacity" field as the
-        "largest_free_area" field.
-
-3. Move memrar_allocator.* to kernel `lib' directory since it is HW
+2. Move memrar_allocator.* to kernel `lib' directory since it is HW
    neutral.
      a. Alternatively, use lib/genalloc.c instead.
      b. A kernel port of Doug Lea's malloc() implementation may also
diff --git a/drivers/staging/memrar/memrar_allocator.c b/drivers/staging/memrar/memrar_allocator.c
index cb74e3c..924eab3 100644
--- a/drivers/staging/memrar/memrar_allocator.c
+++ b/drivers/staging/memrar/memrar_allocator.c
@@ -455,9 +455,15 @@ exit_memrar_free:
 
 size_t memrar_allocator_largest_free_area(struct memrar_allocator *allocator)
 {
-	if (allocator == NULL)
-		return 0;
-	return allocator->largest_free_area;
+	size_t tmp = 0;
+
+	if (allocator != NULL) {
+		mutex_lock(&allocator->lock);
+		tmp = allocator->largest_free_area;
+		mutex_unlock(&allocator->lock);
+	}
+
+	return tmp;
 }
 
 size_t memrar_allocator_capacity(struct memrar_allocator *allocator)
diff --git a/drivers/staging/memrar/memrar_handler.c b/drivers/staging/memrar/memrar_handler.c
index 22208cd..a652593 100644
--- a/drivers/staging/memrar/memrar_handler.c
+++ b/drivers/staging/memrar/memrar_handler.c
@@ -351,7 +351,8 @@ static int memrar_init_rar_resources(int rarnum, char const *devname)
 		devname, rarnum, (unsigned long) low, (unsigned long) high);
 
 	pr_info("%s: BRAR[%d] size = %zu KiB\n",
-			devname, rarnum, rar->allocator->capacity / 1024);
+			devname, rarnum,
+			memrar_allocator_capacity(rar->allocator) / 1024);
 
 	rar->allocated = 1;
 	return 0;
@@ -542,15 +543,9 @@ static long memrar_get_stat(struct RAR_stat *r)
 
 	BUG_ON(allocator == NULL);
 
-	/*
-	 * Allocator capacity doesn't change over time.  No
-	 * need to synchronize.
-	 */
-	r->capacity = allocator->capacity;
+	r->capacity = memrar_allocator_capacity(allocator);
+	r->largest_block_size = memrar_allocator_largest_free_area(allocator);
 
-	mutex_lock(&allocator->lock);
-	r->largest_block_size = allocator->largest_free_area;
-	mutex_unlock(&allocator->lock);
 	return 0;
 }
 
-- 
1.7.1


  reply	other threads:[~2010-06-24  7:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-24  7:09 [PATCH 1/2] Staging: memrar: Moved memrar_allocator struct to memrar_allocator.c Henri Häkkinen
2010-06-24  7:09 ` Henri Häkkinen [this message]
2010-06-24  9:09   ` [PATCH 2/2] Staging: memrar: Fixed memrar_handler.c Alan Cox
2010-06-24 17:36     ` Othman, Ossama
2010-06-24  9:16 ` [PATCH 1/2] Staging: memrar: Moved memrar_allocator struct to memrar_allocator.c Alan Cox
2010-06-24  9:27   ` Henri Häkkinen

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=1277363386-4817-2-git-send-email-henuxd@gmail.com \
    --to=henuxd@gmail.com \
    --cc=alan@linux.intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mattij.lammi@gmail.com \
    --cc=ossama.othman@intel.com \
    --cc=randy.dunlap@oracle.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).