From patchwork Fri Feb 19 16:18:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 62355 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1254849lbl; Fri, 19 Feb 2016 08:19:08 -0800 (PST) X-Received: by 10.140.231.80 with SMTP id b77mr17901313qhc.56.1455898747922; Fri, 19 Feb 2016 08:19:07 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d4si14989494qkj.49.2016.02.19.08.19.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 19 Feb 2016 08:19:07 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=grub-devel-bounces+patch=linaro.org@gnu.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([::1]:53481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWnlr-00068C-C9 for patch@linaro.org; Fri, 19 Feb 2016 11:19:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWnlX-00066A-6l for grub-devel@gnu.org; Fri, 19 Feb 2016 11:18:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWnlU-0005yq-4w for grub-devel@gnu.org; Fri, 19 Feb 2016 11:18:47 -0500 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:34120) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWnlT-0005yh-Ta for grub-devel@gnu.org; Fri, 19 Feb 2016 11:18:44 -0500 Received: by mail-wm0-x22e.google.com with SMTP id b205so75036112wmb.1 for ; Fri, 19 Feb 2016 08:18:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=ZefRK3WzmY+GPF8+yPHGm4dCzXYEDId4VQJqV+z9fic=; b=JqLGEKMC8iT2ECSvDPYsf+XBlPyAgtLnjbmuU0ziEUiLTL1ttQ42qxaz36tLVAooM6 QG0g7tBxTQ3UqbesKNvjFgNFDntdfs+F1TLdzg+m3lP2leNQp1Xb7bn4IdgDxbSYx8iB zWaPSn+Z9Nt1I2fWUelF7Ac7hNBYf4nRNBpUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ZefRK3WzmY+GPF8+yPHGm4dCzXYEDId4VQJqV+z9fic=; b=a7CjPKMwWLvnss44OyTOonkgFtStL9JNYmAqBCIj89jA0RaxQgUeq3rhxnywRqpCb2 7zUxBhrdpgWmvv4jSuF5dvjQlAUf31gvi6etESuZ2SBNaXFvwTQp/Ogh2hoN9Vy7bB7o 3x3L/frjyWxbwS/9fuW3QEyvynqSzt3LYOM5HcflAbUamD5AULHBJsYza3u7OyJ2iWpq SgvRGKB3ZIQgITvHrH293YgqZLbhBo4G9jgV0HNtz5OWNmc9u8+na9U0ZwAssAE2Aorw ZaNm4NPLbkI3ScnRM+weCP2S71/wsm50ZKA0rfF9iV+xpudOpKQ2ofiMspZl/8+4y+6E MtwA== X-Gm-Message-State: AG10YOQhNIi9t25wbWhuadKhlz1uc8xkcyqumwbMtrvNf73aAk5WsA+1Rp0EWVyr+UzLhAzJ X-Received: by 10.28.186.10 with SMTP id k10mr9430205wmf.99.1455898723318; Fri, 19 Feb 2016 08:18:43 -0800 (PST) Received: from mohikan.mushroom.smurfnet.nu (cpc92308-cmbg19-2-0-cust814.5-4.cable.virginm.net. [82.24.251.47]) by smtp.gmail.com with ESMTPSA id t205sm8304703wmt.23.2016.02.19.08.18.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Feb 2016 08:18:42 -0800 (PST) From: Leif Lindholm To: grub-devel@gnu.org Subject: [PATCH 1/2] disk: Add support for device-specific malloc function Date: Fri, 19 Feb 2016 16:18:33 +0000 Message-Id: <1455898714-25127-2-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455898714-25127-1-git-send-email-leif.lindholm@linaro.org> References: <1455898714-25127-1-git-send-email-leif.lindholm@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22e X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: grub-devel-bounces+patch=linaro.org@gnu.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 | 13 +++++++++++-- include/grub/disk.h | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) -- 2.1.4 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 789f8c0..e186586 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -184,6 +184,15 @@ find_part_sep (const char *name) return NULL; } +static void * +disk_malloc (struct grub_disk *disk, grub_size_t size) +{ + if (disk->malloc) + return disk->malloc (disk, size); + + return grub_malloc (size); +} + grub_disk_t grub_disk_open (const char *name) { @@ -331,7 +340,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 +382,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;