From patchwork Wed Mar 2 00:14:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 63361 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2110500lbc; Tue, 1 Mar 2016 16:14:31 -0800 (PST) X-Received: by 10.140.81.231 with SMTP id f94mr29481276qgd.25.1456877671594; Tue, 01 Mar 2016 16:14:31 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z89si16230250qgd.47.2016.03.01.16.14.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 16:14:31 -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]:53238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aauQx-0004RJ-2D for patch@linaro.org; Tue, 01 Mar 2016 19:14:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aauQr-0004Pe-QC for grub-devel@gnu.org; Tue, 01 Mar 2016 19:14:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aauQn-0001KM-2K for grub-devel@gnu.org; Tue, 01 Mar 2016 19:14:25 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:38706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aauQm-0001Jv-Sx for grub-devel@gnu.org; Tue, 01 Mar 2016 19:14:21 -0500 Received: by mail-wm0-x235.google.com with SMTP id l68so56157250wml.1 for ; Tue, 01 Mar 2016 16:14:20 -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=s/1EYAqR1o3teldW/llwnv1zeKpt/1iLecK6uOIsAN0=; b=TcWHolfJ1yFLo6JR+GzgYnivsJ+cqVstARu3K32EKTtn9TysqTUXKN6gwLPuCvYLeU lBfFBgAr2HNrX7DAGuTZS/VlUevJaI4Q4UUcpzK5j/xk8tIdmJPUD9dGC0QSAW0V91Fo yxsC2kMJBkn51cLYxezXiVfxuEjqAJh/qeFkI= 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=s/1EYAqR1o3teldW/llwnv1zeKpt/1iLecK6uOIsAN0=; b=FmsnBxTZBydEPiDLOdPXi8qiI+nCEsG74mTGGP9ZXEuR/iyHAVRwivP/ks56YlMGzu SdzsCT2d8SuFjCZvcczA4f2n8oTEAUlP3gbLZH25LIf5HEE7rRImm9iJzYImRNd9MDtf nmK5YaXJ7yQtZv0e+n9viZzTrmmbW7sGGJlaKlTe8uN1hs/JPCLloOFULSbXw63T0S/j +YW89G7IYDftLtk/LeTqKJv6womBkWMx0waBr8WJYjg1BOH10wSHb8kGrhbfUPqJgXEZ UhM5ZEO4ygHgSkSlm0QbkulWTwosNSjOq+l9NpkbS2y3S8ZJebIN/sYFznWKWm8qmLsK lXZA== X-Gm-Message-State: AD7BkJLSlJXNxU3BQmXLymreVRgqUsm2kUnU3NWqvUMBCyycz+KijzOWAlh5myFTb+CWp8N8 X-Received: by 10.28.223.8 with SMTP id w8mr1644256wmg.54.1456877660314; Tue, 01 Mar 2016 16:14:20 -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 ls5sm33035554wjb.33.2016.03.01.16.14.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Mar 2016 16:14:19 -0800 (PST) From: Leif Lindholm 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 Message-Id: <1456877652-19389-2-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456877652-19389-1-git-send-email-leif.lindholm@linaro.org> References: <1456877652-19389-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::235 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 | 11 +++++++++-- include/grub/disk.h | 5 +++++ 2 files changed, 14 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..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;