From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1aXtnv-0004qw-K5 for mharc-grub-devel@gnu.org; Mon, 22 Feb 2016 11:57:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXtns-0004lH-T8 for grub-devel@gnu.org; Mon, 22 Feb 2016 11:57:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXtno-00043E-Pu for grub-devel@gnu.org; Mon, 22 Feb 2016 11:57:44 -0500 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]:33419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXtno-00042b-IS for grub-devel@gnu.org; Mon, 22 Feb 2016 11:57:40 -0500 Received: by mail-lf0-x235.google.com with SMTP id m1so98795229lfg.0 for ; Mon, 22 Feb 2016 08:57:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=DfiSNpeHAsA4C+ErZzsDb63ye+eklYW1kWqdW9/Z9jY=; b=BNQub8LtesHaJJd/TYHADJ80wvOszu6tvRPejMxt2T/2mdG+djHk8Ho9zzUvIehMDG W60x0F3//5Pkk0qNEbxb9Wkzuy9K3qX2/gWGDduz65Cxl1SQQm7aXMHnuKxNktumfTmx zD4Aom/2RoEisgBy9AXzFYO0oKvS22rb7jqhrrqn8psGI9g3nybYEDq3nmCzib5K9qWl ZbQAYdWJO+nmScSKF7ukpgjXPFlkCcJPTGIUQ+F3PgbHIwdTI1wkbNeGWBKqE/FW8g2n yYO8YAZ5LgSQ22o6HUNOzSDjeOBEjV+SZ/OZaHSecarPkhjiyuQ9p+AJucUo/5xoMy2n iizQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=DfiSNpeHAsA4C+ErZzsDb63ye+eklYW1kWqdW9/Z9jY=; b=A/EMWE932vcGGufQ30ST5xzlzUwT3Qw58l8X6CZKVIsLDtMkaId2vMMgSeLVDqMzol d3eWC3imFvlG3n6VmSMIkgKI/+3RxG9tdut5XKKxzpr7dILfuqcv/nERkuO9pR2WjChV UfRRgm42S7i35H6mB1Fc/FbEJoP6xz0wbzSjeq8XJsEh9FZbTbX1A6OJhxx7MAMdEJ4S g8PUCZbOWte3pbnsMrTmvS+5MAhz2u+15ToKkd7kl/O6QudHe5FcPgSlrEToKh+X0O7M DaSSWPfxnpznah+H+waxiEuNbpoN3IZOPSFcQYLHpINSRcKCPt5LF5zTSYzsvJVwzt98 3OFA== X-Gm-Message-State: AG10YOTccn32eVauG8rxEbUTIsHs1TlxN0GY89er92GXjWgtyHav20AyJpw8rLjawMnCMQ== X-Received: by 10.25.143.141 with SMTP id r135mr11566976lfd.100.1456160259731; Mon, 22 Feb 2016 08:57:39 -0800 (PST) Received: from [192.168.1.41] (ppp109-252-76-159.pppoe.spdop.ru. [109.252.76.159]) by smtp.gmail.com with ESMTPSA id r200sm514677lfr.47.2016.02.22.08.57.38 for (version=TLSv1/SSLv3 cipher=OTHER); Mon, 22 Feb 2016 08:57:38 -0800 (PST) Subject: Re: [PATCH 1/2] disk: Add support for device-specific malloc function To: grub-devel@gnu.org References: <1455898714-25127-1-git-send-email-leif.lindholm@linaro.org> <1455898714-25127-2-git-send-email-leif.lindholm@linaro.org> From: Andrei Borzenkov Message-ID: <56CB3E01.9080605@gmail.com> Date: Mon, 22 Feb 2016 19:57:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <1455898714-25127-2-git-send-email-leif.lindholm@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::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: , X-List-Received-Date: Mon, 22 Feb 2016 16:57:45 -0000 19.02.2016 19:18, Leif Lindholm пишет: > 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(-) > > 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); > +} Just initialize disk->malloc to grub_alloc in all other drivers then, no need for repeated runtime check. > + > 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; > >