Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MOg6n-0008H0-5p for mharc-grub-devel@gnu.org; Wed, 08 Jul 2009 18:59:25 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MOg6l-0008Ge-JZ for grub-devel@gnu.org; Wed, 08 Jul 2009 18:59:23 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MOg6g-0008FU-7R for grub-devel@gnu.org; Wed, 08 Jul 2009 18:59:22 -0400 Received: from [199.232.76.173] (port=33532 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MOg6g-0008FP-39 for grub-devel@gnu.org; Wed, 08 Jul 2009 18:59:18 -0400 Received: from c60.cesmail.net ([216.154.195.49]:32671) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1MOg6f-0000j4-Ic for grub-devel@gnu.org; Wed, 08 Jul 2009 18:59:17 -0400 Received: from unknown (HELO smtprelay2.cesmail.net) ([192.168.1.112]) by c60.cesmail.net with ESMTP; 08 Jul 2009 18:59:15 -0400 Received: from mj.roinet.com (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by smtprelay2.cesmail.net (Postfix) with ESMTPSA id 3C30634C6A for ; Wed, 8 Jul 2009 19:07:47 -0400 (EDT) From: Pavel Roskin To: grub-devel@gnu.org Date: Wed, 08 Jul 2009 18:59:14 -0400 Message-ID: <20090708225914.9290.71677.stgit@mj.roinet.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH] Simplify and optimize grub_device_iterate() X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jul 2009 22:59:23 -0000 I wanted to switch the partition buffering from LIFO to FIFO, but it would increase the core size for a cosmetic improvement in the ls output. This patch is a side effect of me touching that function. ChangeLog: * kern/device.c (grub_device_iterate): Change struct part_ent to hold the name, not a pointer to it. Use one grub_malloc(), not two. Free partition_name if grub_malloc() fails. Set ents to NULL only before grub_partition_iterate() is called. --- kern/device.c | 16 +++++----------- 1 files changed, 5 insertions(+), 11 deletions(-) diff --git a/kern/device.c b/kern/device.c index 55c750b..83ae3dc 100644 --- a/kern/device.c +++ b/kern/device.c @@ -86,8 +86,8 @@ grub_device_iterate (int (*hook) (const char *name)) struct part_ent { struct part_ent *next; - char *name; - } *ents = NULL; + char name[0]; + } *ents; int iterate_disk (const char *disk_name) { @@ -105,18 +105,17 @@ grub_device_iterate (int (*hook) (const char *name)) struct part_ent *p; int ret = 0; + ents = NULL; (void) grub_partition_iterate (dev->disk, iterate_partition); grub_device_close (dev); p = ents; - ents = NULL; while (p != NULL) { struct part_ent *next = p->next; if (!ret) ret = hook (p->name); - grub_free (p->name); grub_free (p); p = next; } @@ -137,15 +136,10 @@ grub_device_iterate (int (*hook) (const char *name)) if (! partition_name) return 1; - p = grub_malloc (sizeof (*p)); + p = grub_malloc (sizeof (p->next) + grub_strlen (disk->name) + 1 + + grub_strlen (partition_name) + 1); if (!p) - return 1; - - p->name = grub_malloc (grub_strlen (disk->name) + 1 - + grub_strlen (partition_name) + 1); - if (! p->name) { - grub_free (p); grub_free (partition_name); return 1; }