grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: grub-devel@gnu.org
Subject: [PATCH v2 1/3] disk: Add support for device-specific malloc function
Date: Wed,  2 Mar 2016 00:14:10 +0000	[thread overview]
Message-ID: <1456877652-19389-2-git-send-email-leif.lindholm@linaro.org> (raw)
In-Reply-To: <1456877652-19389-1-git-send-email-leif.lindholm@linaro.org>

Some disk types have allocation requirements beyond normal grub_malloc.
Add a function pointer to grub_disk_t and a wrapper function in
kern/disk.c making use of that function if available, to enable these
disk drivers to implement their own malloc.
---
 grub-core/kern/disk.c | 11 +++++++++--
 include/grub/disk.h   |  5 +++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c
index 789f8c0..60a920b 100644
--- a/grub-core/kern/disk.c
+++ b/grub-core/kern/disk.c
@@ -184,6 +184,12 @@ find_part_sep (const char *name)
   return NULL;
 }
 
+static void *
+disk_malloc (struct grub_disk *dummy __attribute__ ((unused)), grub_size_t size)
+{
+  return grub_malloc (size);
+}
+
 grub_disk_t
 grub_disk_open (const char *name)
 {
@@ -199,6 +205,7 @@ grub_disk_open (const char *name)
   if (! disk)
     return 0;
   disk->log_sector_size = GRUB_DISK_SECTOR_BITS;
+  disk->malloc = disk_malloc; /* Can be overridden by individual driver. */
   /* Default 1MiB of maximum agglomerate.  */
   disk->max_agglomerate = 1048576 >> (GRUB_DISK_SECTOR_BITS
 				      + GRUB_DISK_CACHE_BITS);
@@ -331,7 +338,7 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector,
     }
 
   /* Allocate a temporary buffer.  */
-  tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
+  tmp_buf = disk->malloc (disk, GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
   if (! tmp_buf)
     return grub_errno;
 
@@ -373,7 +380,7 @@ grub_disk_read_small_real (grub_disk_t disk, grub_disk_addr_t sector,
     num = ((size + offset + (1ULL << (disk->log_sector_size))
 	    - 1) >> (disk->log_sector_size));
 
-    tmp_buf = grub_malloc (num << disk->log_sector_size);
+    tmp_buf = disk->malloc (disk, num << disk->log_sector_size);
     if (!tmp_buf)
       return grub_errno;
     
diff --git a/include/grub/disk.h b/include/grub/disk.h
index b385af8..0fdd779 100644
--- a/include/grub/disk.h
+++ b/include/grub/disk.h
@@ -111,6 +111,8 @@ typedef void (*grub_disk_read_hook_t) (grub_disk_addr_t sector,
 				       unsigned offset, unsigned length,
 				       void *data);
 
+typedef void *(*grub_disk_malloc_t) (struct grub_disk *disk, grub_size_t size);
+
 /* Disk.  */
 struct grub_disk
 {
@@ -144,6 +146,9 @@ struct grub_disk
 
   /* Device-specific data.  */
   void *data;
+
+  /* Device-specific malloc function. */
+  grub_disk_malloc_t malloc;
 };
 typedef struct grub_disk *grub_disk_t;
 
-- 
2.1.4



  reply	other threads:[~2016-03-02  0:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-02  0:14 [PATCH v2 0/3] some disk reworking reposted Leif Lindholm
2016-03-02  0:14 ` Leif Lindholm [this message]
2016-03-02  0:14 ` [PATCH v2 2/3] efidisk: implement alignment-respecting malloc function Leif Lindholm
2016-03-02  3:46   ` Andrei Borzenkov
2016-03-02 14:00     ` Leif Lindholm
2016-03-02  0:14 ` [PATCH v2 3/3] disk: read into cache directly Leif Lindholm
2016-03-02  0:22   ` Vladimir 'phcoder' Serbinenko
2016-03-02  3:46     ` Andrei Borzenkov
2016-03-02  9:55       ` Vladimir 'phcoder' Serbinenko
2016-03-03  0:04   ` Elliott, Robert (Persistent Memory)

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=1456877652-19389-2-git-send-email-leif.lindholm@linaro.org \
    --to=leif.lindholm@linaro.org \
    --cc=grub-devel@gnu.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;
as well as URLs for NNTP newsgroup(s).