Skip to contentSkip to conversation

Introduce grub_malloc0()

PATCH In review Pavel Roskin 3 participants 11 messages Jul 15, 2009 – Jul 19, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Introduce grub_malloc0()

Even though it's a new function added to the core, its use makes core.img smaller. And it makes modules smaller too.

ChangeLog:

* kern/mm.c (grub_malloc0): New function. (grub_debug_malloc0): Likewise.
* include/grub/mm.h: Declare grub_malloc0() and grub_debug_malloc0().
* util/misc.c (grub_malloc0): New function.
* bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_malloc0() instead of grub_malloc(), remove unneeded initializations.
* bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise.
* commands/extcmd.c (grub_extcmd_dispatcher): Likewise.
* commands/parttool.c (grub_cmd_parttool): Likewise.
* disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise.
* disk/raid5_recover.c (grub_raid5_recover): Likewise.
* disk/raid6_recover.c (grub_raid6_recover): Likewise.
* disk/usbms.c (grub_usbms_finddevs): Likewise.
* efiemu/mm.c (grub_efiemu_request_memalign): Likewise.
* efiemu/pnvram.c (grub_efiemu_pnvram): Likewise. (grub_cmd_efiemu_pnvram): Likewise.
* fs/i386/pc/pxe.c (grub_pxefs_open): Likewise.
* fs/iso9660.c (grub_iso9660_mount): Likewise. (grub_iso9660_iterate_dir): Likewise.
* fs/jfs.c (grub_jfs_opendir): Likewise.
* fs/ntfs.c (list_file): Likewise. (grub_ntfs_mount): Likewise.
* kern/disk.c (grub_disk_open): Likewise.
* kern/dl.c (grub_dl_load_core): Likewise.
* kern/elf.c (grub_elf_file): Likewise.
* kern/env.c (grub_env_context_open): Likewise. (grub_env_set): Likewise. (grub_env_set_data_slot): Likewise.
* kern/file.c (grub_file_open): Likewise.
* kern/fs.c (grub_fs_blocklist_open): Likewise.
* loader/i386/multiboot.c (grub_module): Likewise.
* loader/xnu.c (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise.
* normal/main.c (grub_normal_add_menu_entry): Likewise. (read_config_file): Likewise.
* normal/menu_entry.c (make_screen): Likewise.
* partmap/sun.c (sun_partition_map_iterate): Likewise.
* script/sh/lexer.c (grub_script_lexer_init): Likewise.
* script/sh/script.c (grub_script_parse): Likewise.
* video/bitmap.c (grub_video_bitmap_create): Likewise.
* video/readers/jpeg.c (grub_video_reader_jpeg): Likewise.
* video/readers/png.c (grub_png_output_byte): Likewise. (grub_video_reader_png): Likewise.

---
 bus/usb/uhci.c          |    5 +----
 bus/usb/usbhub.c        |    4 +---
 commands/extcmd.c       |    3 +--
 commands/parttool.c     |    7 ++-----
 disk/i386/pc/biosdisk.c |    3 +--
 disk/raid5_recover.c    |    4 +---
 disk/raid6_recover.c    |    7 ++-----
 disk/usbms.c            |    4 +---
 efiemu/mm.c             |    4 +---
 efiemu/pnvram.c         |    6 ++----
 fs/i386/pc/pxe.c        |    3 +--
 fs/iso9660.c            |    7 ++-----
 fs/jfs.c                |    4 +---
 fs/ntfs.c               |    7 ++-----
 include/grub/mm.h       |    6 ++++++
 kern/disk.c             |    6 +-----
 kern/dl.c               |    7 +------
 kern/elf.c              |    3 +--
 kern/env.c              |   11 +++--------
 kern/file.c             |    5 +----
 kern/fs.c               |    5 +----
 kern/mm.c               |   27 +++++++++++++++++++++++++++
 loader/i386/multiboot.c |    3 +--
 loader/xnu.c            |    7 ++-----
 normal/main.c           |   14 ++++----------
 normal/menu_entry.c     |    9 +--------
 partmap/sun.c           |    4 +---
 script/sh/lexer.c       |   11 +----------
 script/sh/script.c      |    7 +------
 util/misc.c             |   10 ++++++++++
 video/bitmap.c          |    5 +----
 video/readers/jpeg.c    |    3 +--
 video/readers/png.c     |    6 ++----
 33 files changed, 85 insertions(+), 132 deletions(-)
bus/usb/uhci.c +1 -4
index 84cd48d..f902488 100644
@@ -170,14 +170,11 @@ grub_uhci_pci_iter (int bus, int device, int func,
     return 0;
 
   /* Allocate memory for the controller and register it.  */
-  u = grub_malloc (sizeof (*u));
+  u = grub_malloc0 (sizeof (*u));
   if (! u)
     return 1;
 
   u->iobase = base & GRUB_UHCI_IOMASK;
-  u->framelist = 0;
-  u->qh = 0;
-  u->td = 0;
   grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x\n",
 		class, subclass, interf, u->iobase);
 
bus/usb/usbhub.c +1 -3
index ba0925a..336d657 100644
@@ -33,13 +33,11 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
   grub_usb_device_t dev;
   int i;
 
-  dev = grub_malloc (sizeof (struct grub_usb_device));
+  dev = grub_malloc0 (sizeof (struct grub_usb_device));
   if (! dev)
     return NULL;
 
   dev->controller = *controller;
-  dev->addr = 0;
-  dev->initialized = 0;
   dev->speed = speed;
 
   grub_usb_device_initialize (dev);
commands/extcmd.c +1 -2
index a605387..2e0d993 100644
@@ -40,8 +40,7 @@ grub_extcmd_dispatcher (struct grub_command *cmd,
     maxargs++;
 
   /* Set up the option state.  */
-  state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
-  grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
+  state = grub_malloc0 (sizeof (struct grub_arg_list) * maxargs);
 
   if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
     {
commands/parttool.c +2 -5
index c807f06..7e72791 100644
@@ -242,8 +242,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
     if (grub_strcmp (args[i], "help") == 0)
       return show_help ();
 
-  parsed = (int *) grub_malloc (argc * sizeof (int));
-  grub_memset (parsed, 0, argc * sizeof (int));
+  parsed = (int *) grub_malloc0 (argc * sizeof (int));
 
   for (i = 1; i < argc; i++)
     if (! parsed[i])
@@ -272,9 +271,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
 			     args[i]);
 	ptool = cur;
 	pargs = (struct grub_parttool_args *)
-	  grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
-	grub_memset (pargs, 0,
-		     ptool->nargs * sizeof (struct grub_parttool_args));
+	  grub_malloc0 (ptool->nargs * sizeof (struct grub_parttool_args));
 	for (j = i; j < argc; j++)
 	  if (! parsed[j])
 	    {
disk/i386/pc/biosdisk.c +1 -2
index 09f0ce7..a71a8f4 100644
@@ -109,12 +109,11 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
   disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
   disk->id = drive;
 
-  data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data));
+  data = (struct grub_biosdisk_data *) grub_malloc0 (sizeof (*data));
   if (! data)
     return grub_errno;
 
   data->drive = drive;
-  data->flags = 0;
 
   if ((cd_drive) && (drive == cd_drive))
     {
disk/raid5_recover.c +1 -3
index 31cef88..e4f1f78 100644
@@ -32,12 +32,10 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr,
   int i;
 
   size <<= GRUB_DISK_SECTOR_BITS;
-  buf2 = grub_malloc (size);
+  buf2 = grub_malloc0 (size);
   if (!buf2)
     return grub_errno;
 
-  grub_memset (buf, 0, size);
-
   for (i = 0; i < (int) array->total_devs; i++)
     {
       grub_err_t err;
disk/raid6_recover.c +2 -5
index 3a994af..0b7242c 100644
@@ -96,11 +96,11 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
   char *pbuf = 0, *qbuf = 0;
 
   size <<= GRUB_DISK_SECTOR_BITS;
-  pbuf = grub_malloc (size);
+  pbuf = grub_malloc0 (size);
   if (!pbuf)
     goto quit;
 
-  qbuf = grub_malloc (size);
+  qbuf = grub_malloc0 (size);
   if (!qbuf)
     goto quit;
 
@@ -108,9 +108,6 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
   if (q == (int) array->total_devs)
     q = 0;
 
-  grub_memset (pbuf, 0, size);
-  grub_memset (qbuf, 0, size);
-
   pos = q + 1;
   if (pos == (int) array->total_devs)
     pos = 0;
disk/usbms.c +1 -3
index 3c7ebaf..4c5e216 100644
@@ -107,14 +107,12 @@ grub_usbms_finddevs (void)
 	    }
 
 	  devcnt++;
-	  usbms = grub_malloc (sizeof (struct grub_usbms_dev));
+	  usbms = grub_malloc0 (sizeof (struct grub_usbms_dev));
 	  if (! usbms)
 	    return 1;
 
 	  usbms->dev = usbdev;
 	  usbms->interface = i;
-	  usbms->in = NULL;
-	  usbms->out = NULL;
 
 	  /* Iterate over all endpoints of this interface, at least a
 	     IN and OUT bulk endpoint are required.  */
efiemu/mm.c +1 -3
index 7d6a5d4..290ca11 100644
@@ -104,14 +104,12 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
   requested_memory[type] += align_overhead + size;
 
   /* Remember the request */
-  ret = grub_malloc (sizeof (*ret));
+  ret = grub_malloc0 (sizeof (*ret));
   if (!ret)
     return -1;
   ret->type = type;
   ret->size = size;
   ret->align_overhead = align_overhead;
-  ret->val = 0;
-  ret->next = 0;
   prev = 0;
 
   /* Add request to the end of the chain.
efiemu/pnvram.c +2 -4
index d5daaab..21f7d93 100644
@@ -339,11 +339,10 @@ grub_efiemu_pnvram (void)
   accuracy = 50000000;
   daylight = 0;
 
-  nvram = grub_malloc (nvramsize);
+  nvram = grub_malloc0 (nvramsize);
   if (!nvram)
     return grub_error (GRUB_ERR_OUT_OF_MEMORY,
 		       "Couldn't allocate space for temporary pnvram storage");
-  grub_memset (nvram, 0, nvramsize);
 
   return grub_efiemu_make_nvram ();
 }
@@ -365,11 +364,10 @@ grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
   accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
   daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
 
-  nvram = grub_malloc (nvramsize);
+  nvram = grub_malloc0 (nvramsize);
   if (!nvram)
     return grub_error (GRUB_ERR_OUT_OF_MEMORY,
 		       "Couldn't allocate space for temporary pnvram storage");
-  grub_memset (nvram, 0, nvramsize);
 
   if (argc == 1 && (err = read_pnvram (args[0])))
     {
fs/i386/pc/pxe.c +1 -2
index 1fc5680..5ee5fb7 100644
@@ -146,11 +146,10 @@ grub_pxefs_open (struct grub_file *file, const char *name)
   if (c.c2.status)
     return grub_error (GRUB_ERR_BAD_FS, "open fails");
 
-  data = grub_malloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
+  data = grub_malloc0 (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
   if (! data)
     return grub_errno;
 
-  data->packet_number = 0;
   data->block_size = grub_pxe_blksize;
   grub_strcpy (data->filename, name);
 
fs/iso9660.c +2 -5
index c79ad4f..6e5c3a9 100644
@@ -263,13 +263,11 @@ grub_iso9660_mount (grub_disk_t disk)
       return 0;
     }
 
-  data = grub_malloc (sizeof (struct grub_iso9660_data));
+  data = grub_malloc0 (sizeof (struct grub_iso9660_data));
   if (! data)
     return 0;
 
   data->disk = disk;
-  data->rockridge = 0;
-  data->joliet = 0;
 
   block = 16;
   do
@@ -509,8 +507,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,
 	      else
 		{
 		  size = entry->len - 5;
-		  filename = grub_malloc (size + 1);
-		  filename[0] = '\0';
+		  filename = grub_malloc0 (size + 1);
 		}
 	      filename_alloc = 1;
 	      grub_strncpy (filename, (char *) &entry->data[1], size);
fs/jfs.c +1 -3
index 4f91825..fae2800 100644
@@ -382,11 +382,10 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
       return 0;
     }
 
-  diro = grub_malloc (sizeof (struct grub_jfs_diropen));
+  diro = grub_malloc0 (sizeof (struct grub_jfs_diropen));
   if (!diro)
     return 0;
 
-  diro->index = 0;
   diro->data = data;
   diro->inode = inode;
 
@@ -397,7 +396,6 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
       diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
       diro->sorted = (char *) (inode->dir.header.sorted);
       diro->count = inode->dir.header.count;
-      diro->dirpage = 0;
 
       return diro;
     }
fs/ntfs.c +2 -5
index c312b8b..bcbbdae 100644
@@ -601,11 +601,10 @@ list_file (struct grub_ntfs_file *diro, char *pos,
 	    (u32at (pos, 0x48) & ATTR_DIRECTORY) ? GRUB_FSHELP_DIR :
 	    GRUB_FSHELP_REG;
 
-	  fdiro = grub_malloc (sizeof (struct grub_ntfs_file));
+	  fdiro = grub_malloc0 (sizeof (struct grub_ntfs_file));
 	  if (!fdiro)
 	    return 0;
 
-	  grub_memset (fdiro, 0, sizeof (*fdiro));
 	  fdiro->data = diro->data;
 	  fdiro->ino = u32at (pos, 0);
 
@@ -791,12 +790,10 @@ grub_ntfs_mount (grub_disk_t disk)
   if (!disk)
     goto fail;
 
-  data = (struct grub_ntfs_data *) grub_malloc (sizeof (*data));
+  data = (struct grub_ntfs_data *) grub_malloc0 (sizeof (*data));
   if (!data)
     goto fail;
 
-  grub_memset (data, 0, sizeof (*data));
-
   data->disk = disk;
 
   /* Read the BPB.  */
include/grub/mm.h +6 -0
index 4dd1363..413e439 100644
@@ -30,6 +30,7 @@
 
 void grub_mm_init_region (void *addr, grub_size_t size);
 void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
+void *EXPORT_FUNC(grub_malloc0) (grub_size_t size);
 void EXPORT_FUNC(grub_free) (void *ptr);
 void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
 void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
@@ -45,6 +46,9 @@ void grub_mm_dump (unsigned lineno);
 #define grub_malloc(size)	\
   grub_debug_malloc (__FILE__, __LINE__, size)
 
+#define grub_malloc0(size)	\
+  grub_debug_malloc0 (__FILE__, __LINE__, size)
+
 #define grub_realloc(ptr,size)	\
   grub_debug_realloc (__FILE__, __LINE__, ptr, size)
 
@@ -56,6 +60,8 @@ void grub_mm_dump (unsigned lineno);
 
 void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
 				      grub_size_t size);
+void *EXPORT_FUNC(grub_debug_malloc0) (const char *file, int line,
+				       grub_size_t size);
 void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
 void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
 				       grub_size_t size);
kern/disk.c +1 -5
index e167fb6..d1e3da3 100644
@@ -244,14 +244,10 @@ grub_disk_open (const char *name)
 
   grub_dprintf ("disk", "Opening `%s'...\n", name);
 
-  disk = (grub_disk_t) grub_malloc (sizeof (*disk));
+  disk = (grub_disk_t) grub_malloc0 (sizeof (*disk));
   if (! disk)
     return 0;
 
-  disk->dev = 0;
-  disk->read_hook = 0;
-  disk->partition = 0;
-  disk->data = 0;
   disk->name = grub_strdup (name);
   if (! disk->name)
     goto fail;
kern/dl.c +1 -6
index 122b6b9..ad6fc49 100644
@@ -535,16 +535,11 @@ grub_dl_load_core (void *addr, grub_size_t size)
       return 0;
     }
 
-  mod = (grub_dl_t) grub_malloc (sizeof (*mod));
+  mod = (grub_dl_t) grub_malloc0 (sizeof (*mod));
   if (! mod)
     return 0;
 
-  mod->name = 0;
   mod->ref_count = 1;
-  mod->dep = 0;
-  mod->segment = 0;
-  mod->init = 0;
-  mod->fini = 0;
 
   grub_dprintf ("modules", "relocating to %p\n", mod);
   if (grub_dl_resolve_name (mod, e)
kern/elf.c +1 -2
index 2590552..a9f4649 100644
@@ -61,12 +61,11 @@ grub_elf_file (grub_file_t file)
 {
   grub_elf_t elf;
 
-  elf = grub_malloc (sizeof (*elf));
+  elf = grub_malloc0 (sizeof (*elf));
   if (! elf)
     return 0;
 
   elf->file = file;
-  elf->phdrs = 0;
 
   if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
     goto fail;
kern/env.c +3 -8
index e85627b..faca4c0 100644
@@ -80,11 +80,10 @@ grub_env_context_open (int export)
   struct grub_env_context *context;
   int i;
 
-  context = grub_malloc (sizeof (*context));
+  context = grub_malloc0 (sizeof (*context));
   if (! context)
     return grub_errno;
 
-  grub_memset (context, 0, sizeof (*context));
   context->prev = current_context;
   current_context = context;
 
@@ -204,12 +203,10 @@ grub_env_set (const char *name, const char *val)
     }
 
   /* The variable does not exist, so create a new one.  */
-  var = grub_malloc (sizeof (*var));
+  var = grub_malloc0 (sizeof (*var));
   if (! var)
     return grub_errno;
 
-  grub_memset (var, 0, sizeof (*var));
-
   /* This is not necessary, because GRUB_ENV_VAR_LOCAL == 0. But leave
      this for readability.  */
   var->type = GRUB_ENV_VAR_LOCAL;
@@ -379,12 +376,10 @@ grub_env_set_data_slot (const char *name, const void *ptr)
     }
 
   /* The variable does not exist, so create a new one.  */
-  var = grub_malloc (sizeof (*var));
+  var = grub_malloc0 (sizeof (*var));
   if (! var)
     goto fail;
 
-  grub_memset (var, 0, sizeof (*var));
-
   var->type = GRUB_ENV_VAR_DATA;
   var->name = mangled_name;
   var->value = (char *) ptr;
kern/file.c +1 -4
index 5d5e640..2d7d967 100644
@@ -75,14 +75,11 @@ grub_file_open (const char *name)
   if (! device)
     goto fail;
 
-  file = (grub_file_t) grub_malloc (sizeof (*file));
+  file = (grub_file_t) grub_malloc0 (sizeof (*file));
   if (! file)
     goto fail;
 
   file->device = device;
-  file->offset = 0;
-  file->data = 0;
-  file->read_hook = 0;
 
   if (device->disk && file_name[0] != '/')
     /* This is a block list.  */
kern/fs.c +1 -4
index c8f4970..f17347e 100644
@@ -161,7 +161,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
   while (p);
 
   /* Allocate a block list.  */
-  blocks = grub_malloc (sizeof (struct grub_fs_block) * (num + 1));
+  blocks = grub_malloc0 (sizeof (struct grub_fs_block) * (num + 1));
   if (! blocks)
     return 0;
 
@@ -179,8 +179,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
 	      goto fail;
 	    }
 	}
-      else
-	blocks[i].offset = 0;
 
       p++;
       blocks[i].length = grub_strtoul (p, &p, 0);
@@ -203,7 +201,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
       p++;
     }
 
-  blocks[i].length = 0;
   file->data = blocks;
 
   return GRUB_ERR_NONE;
kern/mm.c +27 -0
index 9a0ae56..a07bd42 100644
@@ -68,6 +68,7 @@
 
 #ifdef MM_DEBUG
 # undef grub_malloc
+# undef grub_malloc0
 # undef grub_realloc
 # undef grub_free
 # undef grub_memalign
@@ -348,6 +349,19 @@ grub_malloc (grub_size_t size)
   return grub_memalign (0, size);
 }
 
+/* Allocate SIZE bytes, clear them and return the pointer.  */
+void *
+grub_malloc0 (grub_size_t size)
+{
+  void *ret;
+
+  ret = grub_memalign (0, size);
+  if (ret)
+    grub_memset (ret, 0, size);
+
+  return ret;
+}
+
 /* Deallocate the pointer PTR.  */
 void
 grub_free (void *ptr)
@@ -522,6 +536,19 @@ grub_debug_malloc (const char *file, int line, grub_size_t size)
   return ptr;
 }
 
+void *
+grub_debug_malloc0 (const char *file, int line, grub_size_t size)
+{
+  void *ptr;
+
+  if (grub_mm_debug)
+    grub_printf ("%s:%d: malloc0 (0x%zx) = ", file, line, size);
+  ptr = grub_malloc0 (size);
+  if (grub_mm_debug)
+    grub_printf ("%p\n", ptr);
+  return ptr;
+}
+
 void
 grub_debug_free (const char *file, int line, void *ptr)
 {
loader/i386/multiboot.c +1 -2
index 8ce315e..7e9ac66 100644
@@ -456,13 +456,12 @@ grub_module  (int argc, char *argv[])
     }
   else
     {
-      struct grub_mod_list *modlist = grub_malloc (sizeof (struct grub_mod_list));
+      struct grub_mod_list *modlist = grub_malloc0 (sizeof (struct grub_mod_list));
       if (! modlist)
 	goto fail;
       modlist->mod_start = (grub_uint32_t) module;
       modlist->mod_end = (grub_uint32_t) module + size;
       modlist->cmdline = (grub_uint32_t) cmdline;
-      modlist->pad = 0;
       mbi->mods_count = 1;
       mbi->mods_addr = (grub_uint32_t) modlist;
       mbi->flags |= MULTIBOOT_INFO_MODS;
loader/xnu.c +2 -5
index b2c6c05..0861b83 100644
@@ -278,7 +278,7 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
   ret = grub_xnu_find_key (*parent, name);
   if (ret)
     return ret;
-  ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
+  ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
   if (! ret)
     {
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
@@ -292,7 +292,6 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
       return 0;
     }
   ret->datasize = -1;
-  ret->first_child = 0;
   ret->next = *parent;
   *parent = ret;
   return ret;
@@ -313,7 +312,7 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
       ret->data = 0;
       return ret;
     }
-  ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
+  ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
   if (! ret)
     {
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
@@ -326,8 +325,6 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
       return 0;
     }
-  ret->datasize = 0;
-  ret->data = 0;
   ret->next = *parent;
   *parent = ret;
   return ret;
normal/main.c +4 -10
index 7f6336e..878b947 100644
@@ -166,11 +166,9 @@ grub_normal_add_menu_entry (int argc, const char **args,
   struct grub_menu_entry_class *classes_tail;
 
   /* Allocate dummy head node for class list.  */
-  classes_head = grub_malloc (sizeof (struct grub_menu_entry_class));
+  classes_head = grub_malloc0 (sizeof (struct grub_menu_entry_class));
   if (! classes_head)
     return grub_errno;
-  classes_head->name = 0;
-  classes_head->next = 0;
   classes_tail = classes_head;
 
   menu = grub_env_get_data_slot ("menu");
@@ -206,7 +204,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
 		}
 
 	      /* Create a new class and add it at the tail of the list.  */
-	      new_class = grub_malloc (sizeof (struct grub_menu_entry_class));
+	      new_class = grub_malloc0 (sizeof (struct grub_menu_entry_class));
 	      if (! new_class)
 		{
 		  grub_free (class_name);
@@ -215,7 +213,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
 		}
 	      /* Fill in the new class node.  */
 	      new_class->name = class_name;
-	      new_class->next = 0;
 	      /* Link the tail to it, and make it the new tail.  */
 	      classes_tail->next = new_class;
 	      classes_tail = new_class;
@@ -267,7 +264,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
   while (*last)
     last = &(*last)->next;
 
-  *last = grub_malloc (sizeof (**last));
+  *last = grub_malloc0 (sizeof (**last));
   if (! *last)
     {
       free_menu_entry_classes (classes_head);
@@ -278,7 +275,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
 
   (*last)->title = menutitle;
   (*last)->classes = classes_head;
-  (*last)->next = 0;
   (*last)->sourcecode = menusourcecode;
 
   menu->size++;
@@ -346,11 +342,9 @@ read_config_file (const char *config)
   newmenu = grub_env_get_data_slot ("menu");
   if (! newmenu)
     {
-      newmenu = grub_malloc (sizeof (*newmenu));
+      newmenu = grub_malloc0 (sizeof (*newmenu));
       if (! newmenu)
 	return 0;
-      newmenu->size = 0;
-      newmenu->entry_list = 0;
 
       grub_env_set_data_slot ("menu", newmenu);
     }
normal/menu_entry.c +1 -8
index 86e581e..86cad0a 100644
@@ -416,18 +416,11 @@ make_screen (grub_menu_entry_t entry)
   struct screen *screen;
 
   /* Initialize the screen.  */
-  screen = grub_malloc (sizeof (*screen));
+  screen = grub_malloc0 (sizeof (*screen));
   if (! screen)
     return 0;
 
   screen->num_lines = 1;
-  screen->column = 0;
-  screen->real_column = 0;
-  screen->line = 0;
-  screen->x = 0;
-  screen->y = 0;
-  screen->killed_text = 0;
-  screen->completion_shown = 0;
   screen->lines = grub_malloc (sizeof (struct line));
   if (! screen->lines)
     goto fail;
partmap/sun.c +1 -3
index 6094777..e442ff7 100644
@@ -95,12 +95,10 @@ sun_partition_map_iterate (grub_disk_t disk,
   raw = *disk;
   raw.partition = 0;
 
-  p = (grub_partition_t) grub_malloc (sizeof (struct grub_partition));
+  p = (grub_partition_t) grub_malloc0 (sizeof (struct grub_partition));
   if (! p)
     return grub_errno;
 
-  p->offset = 0;
-  p->data = 0;
   p->partmap = &grub_sun_partition_map;
   if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
 		      &block) == GRUB_ERR_NONE)
script/sh/lexer.c +1 -10
index 17f18e2..cbc33d7 100644
@@ -49,22 +49,13 @@ grub_script_lexer_init (char *script, grub_reader_getline_t getline)
 {
   struct grub_lexer_param *param;
 
-  param = grub_malloc (sizeof (*param));
+  param = grub_malloc0 (sizeof (*param));
   if (! param)
     return 0;
 
   param->state = GRUB_PARSER_STATE_TEXT;
   param->getline = getline;
-  param->refs = 0;
-  param->done = 0;
-  param->newscript = 0;
   param->script = script;
-  param->record = 0;
-  param->recording = 0;
-  param->recordpos = 0;
-  param->recordlen = 0;
-  param->tokenonhold = 0;
-  param->was_newline = 0;
 
   return param;
 }
script/sh/script.c +1 -6
index 89fa947..3019cd7 100644
@@ -304,15 +304,10 @@ grub_script_parse (char *script, grub_reader_getline_t getline)
   if (! parsed)
     return 0;
 
-  parsestate = grub_malloc (sizeof (*parsestate));
+  parsestate = grub_malloc0 (sizeof (*parsestate));
   if (! parsestate)
     return 0;
 
-  parsestate->err = 0;
-  parsestate->func_mem = 0;
-  parsestate->memused = 0;
-  parsestate->parsed = 0;
-
   /* Initialize the lexer.  */
   lexstate = grub_script_lexer_init (script, getline);
   if (! lexstate)
util/misc.c +10 -0
index f615a42..19a4244 100644
@@ -257,6 +257,16 @@ grub_malloc (grub_size_t size)
   return xmalloc (size);
 }
 
+void *
+grub_malloc0 (grub_size_t size)
+{
+  void *ret;
+
+  ret = xmalloc (size);
+  memset (ret, 0, size);
+  return ret;
+}
+
 void
 grub_free (void *ptr)
 {
video/bitmap.c +1 -4
index d399fd7..009d3e4 100644
@@ -137,7 +137,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
   /* Calculate size needed for the data.  */
   size = (width * mode_info->bytes_per_pixel) * height;
 
-  (*bitmap)->data = grub_malloc (size);
+  (*bitmap)->data = grub_malloc0 (size);
   if (! (*bitmap)->data)
     {
       grub_free (*bitmap);
@@ -146,9 +146,6 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
       return grub_errno;
     }
 
-  /* Clear bitmap.  */
-  grub_memset ((*bitmap)->data, 0, size);
-
   return GRUB_ERR_NONE;
 }
 
video/readers/jpeg.c +1 -2
index b64bf3f..076f6fd 100644
@@ -667,12 +667,11 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
   if (!file)
     return grub_errno;
 
-  data = grub_malloc (sizeof (*data));
+  data = grub_malloc0 (sizeof (*data));
   if (data != NULL)
     {
       int i;
 
-      grub_memset (data, 0, sizeof (*data));
       data->file = file;
       data->bitmap = bitmap;
       grub_jpeg_decode_jpeg (data);
video/readers/png.c +2 -4
index 733fa73..3ae8fb2 100644
@@ -543,11 +543,10 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n)
 
       if (data->first_line)
 	{
-	  blank_line = grub_malloc (row_bytes);
+	  blank_line = grub_malloc0 (row_bytes);
 	  if (blank_line == NULL)
 	    return grub_errno;
 
-	  grub_memset (blank_line, 0, row_bytes);
 	  up = blank_line;
 	}
       else
@@ -843,10 +842,9 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
   if (!file)
     return grub_errno;
 
-  data = grub_malloc (sizeof (*data));
+  data = grub_malloc0 (sizeof (*data));
   if (data != NULL)
     {
-      grub_memset (data, 0, sizeof (*data));
       data->file = file;
       data->bitmap = bitmap;
 
#1 lore raw

PATCH 2/2 Disable lzo compression, lzma is doing its job just fine

ChangeLog:

* Makefile.in: Remove LIBLZO and enable_lzo.
* conf/i386-pc.rmk: Remove lzo support.
* configure.ac: Remove checks for lzo, don't define ENABLE_LZMA.
* include/grub/i386/pc/kernel.h: Define ENABLE_LZMA. Remove lzo support.
* kern/i386/pc/lzo1x.S: Remove.
* kern/i386/pc/startup.S: Remove lzo support.
* util/i386/pc/grub-mkimage.c: Likewise.

---
 Makefile.in                   |    2 
 conf/i386-pc.rmk              |    6 -
 configure.ac                  |   26 ---
 include/grub/i386/pc/kernel.h |    7 -
 kern/i386/pc/lzo1x.S          |  315 -----------------------------------------
 kern/i386/pc/startup.S        |   19 --
 util/i386/pc/grub-mkimage.c   |   54 -------
 7 files changed, 8 insertions(+), 421 deletions(-)
 delete mode 100644 kern/i386/pc/lzo1x.S
Makefile.in +0 -2
index 3d208e7..29e347a 100644
@@ -94,7 +94,6 @@ HELP2MAN := LANG=C $(HELP2MAN) --no-info --source=FSF
 endif
 AWK = @AWK@
 LIBCURSES = @LIBCURSES@
-LIBLZO = @LIBLZO@
 YACC = @YACC@
 UNIFONT_BDF = @UNIFONT_BDF@
 
@@ -103,7 +102,6 @@ enable_grub_emu = @enable_grub_emu@
 enable_grub_emu_usb = @enable_grub_emu_usb@
 enable_grub_fstest = @enable_grub_fstest@
 enable_grub_pe2elf = @enable_grub_pe2elf@
-enable_lzo = @enable_lzo@
 enable_grub_mkfont = @enable_grub_mkfont@
 freetype_cflags = @freetype_cflags@
 freetype_libs = @freetype_libs@
conf/i386-pc.rmk +0 -6
index f1915b6..f5bded2 100644
@@ -89,14 +89,8 @@ sbin_UTILITIES += grub-emu
 endif
 
 # For grub-mkimage.
-ifeq ($(enable_lzo), yes)
-grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
-	util/resolve.c
-grub_mkimage_LDFLAGS = $(LIBLZO)
-else
 grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
 	util/resolve.c lib/LzmaEnc.c lib/LzFind.c
-endif
 grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)
 util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile
 
configure.ac +0 -26
index 8b12c58..66f2b59 100644
@@ -171,32 +171,6 @@ if test x$grub_cv_apple_cc = xyes ; then
   ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
 fi
 
-# Check LZO when compiling for the i386-pc.
-if test "$target_cpu"-"$platform" = i386-pc; then
-  AC_ARG_ENABLE([lzo],
-	      [AS_HELP_STRING([--enable-lzo],
-                             [use lzo to compress kernel (default is lzma)])])
-  [if [ x"$enable_lzo" = xyes ]; then
-    # There are three possibilities. LZO version 2 installed with the name
-    # liblzo2, with the name liblzo, and LZO version 1.]
-    AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
-    AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
-      [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
-        [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
-	       [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
-    AC_SUBST([LIBLZO])
-    [LIBS="$LIBS $LIBLZO"]
-    AC_CHECK_FUNC([lzo1x_999_compress], ,
-	        [AC_MSG_ERROR([LZO1X-999 must be enabled])])
-
-    [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
-    AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
-  [else]
-    AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
-  [fi]
-  AC_SUBST([enable_lzo])
-fi
-
 # Check for functions.
 AC_CHECK_FUNCS(posix_memalign memalign asprintf)
 
include/grub/i386/pc/kernel.h +3 -4
index 5b9d8dc..e830afa 100644
@@ -41,11 +41,10 @@
 #define GRUB_KERNEL_MACHINE_DATA_END		0x5c
 
 /* The size of the first region which won't be compressed.  */
-#if defined(ENABLE_LZO)
-#define GRUB_KERNEL_MACHINE_RAW_SIZE		(GRUB_KERNEL_MACHINE_DATA_END + 0x450)
-#elif defined(ENABLE_LZMA)
 #define GRUB_KERNEL_MACHINE_RAW_SIZE		(GRUB_KERNEL_MACHINE_DATA_END + 0x5F0)
-#endif
+
+/* Enable LZMA compression */
+#define ENABLE_LZMA	1
 
 #ifndef ASM_FILE
 
kern/i386/pc/lzo1x.S deleted +0 -315

315 lines not on this page · raw message

kern/i386/pc/startup.S +2 -17
index 171fbea..be258fb 100644
@@ -210,20 +210,7 @@ codestart:
 	incl	%eax
 	call	EXT_C(grub_gate_a20)
 
-#if defined(ENABLE_LZO)
-	/* decompress the compressed part and put the result at 1MB */
-	movl	$GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %esi
-	movl	$(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
-
-	pushl	%esi
-	pushl	EXT_C(grub_compressed_size)
-	pushl	%edi
-	call	lzo1x_decompress
-	addl	$12, %esp
-
-	movl	%eax, %ecx
-	cld
-#elif defined(ENABLE_LZMA)
+#ifdef ENABLE_LZMA
 	movl	$GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi
 	movl	$(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi
 	pushl	%edi
@@ -451,9 +438,7 @@ gate_a20_check_state:
 	popl	%ebx
 	ret
 
-#if defined(ENABLE_LZO)
-#include "lzo1x.S"
-#elif defined(ENABLE_LZMA)
+#ifdef ENABLE_LZMA
 #include "lzma_decode.S"
 #endif
 
util/i386/pc/grub-mkimage.c +3 -51

74 lines not on this page · raw message

#2 lore raw

Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine

Quoted 10 lines · Pavel Roskin

ChangeLog:

       * Makefile.in: Remove LIBLZO and enable_lzo.
       * conf/i386-pc.rmk: Remove lzo support.
       * configure.ac: Remove checks for lzo, don't define ENABLE_LZMA.
       * include/grub/i386/pc/kernel.h: Define ENABLE_LZMA.  Remove lzo support.
       * kern/i386/pc/lzo1x.S: Remove.
       * kern/i386/pc/startup.S: Remove lzo support.
       * util/i386/pc/grub-mkimage.c: Likewise.

Is there a reason to remove lzo? I know that lzma performs much better in terms of compression but afaik lzo doesn't create any problems nor is compiled by default and may be desirable for some users

Quoted 552 lines

---
 Makefile.in                   |    2
 conf/i386-pc.rmk              |    6 -
 configure.ac                  |   26 --- include/grub/i386/pc/kernel.h |    7 -
 kern/i386/pc/lzo1x.S          |  315 ----------------------------------------- kern/i386/pc/startup.S        |   19 -- util/i386/pc/grub-mkimage.c   |   54 -------

 7 files changed, 8 insertions(+), 421 deletions(-)

 delete mode 100644 kern/i386/pc/lzo1x.S

Makefile.in +0 -0
index 3d208e7..29e347a 100644
@@ -94,7 +94,6 @@ HELP2MAN := LANG=C $(HELP2MAN) --no-info --source=FSF

 endif
 AWK = @AWK@
 LIBCURSES = @LIBCURSES@
-LIBLZO = @LIBLZO@
 YACC = @YACC@
 UNIFONT_BDF = @UNIFONT_BDF@

Makefile.in +0 -0
@@ -103,7 +102,6 @@ enable_grub_emu = @enable_grub_emu@

 enable_grub_emu_usb = @enable_grub_emu_usb@
 enable_grub_fstest = @enable_grub_fstest@
 enable_grub_pe2elf = @enable_grub_pe2elf@
-enable_lzo = @enable_lzo@
 enable_grub_mkfont = @enable_grub_mkfont@
 freetype_cflags = @freetype_cflags@
 freetype_libs = @freetype_libs@

conf/i386-pc.rmk +0 -0
index f1915b6..f5bded2 100644
@@ -89,14 +89,8 @@ sbin_UTILITIES += grub-emu

 endif

 # For grub-mkimage.

conf/i386-pc.rmk +0 -5
-ifeq ($(enable_lzo), yes)
-grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
-       util/resolve.c
-grub_mkimage_LDFLAGS = $(LIBLZO)
-else

 grub_mkimage_SOURCES = util/i386/pc/grub-mkimage.c util/misc.c \
       util/resolve.c lib/LzmaEnc.c lib/LzFind.c
-endif
 grub_mkimage_CFLAGS = -DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR) util/i386/pc/grub-mkimage.c_DEPENDENCIES = Makefile

configure.ac +0 -0
index 8b12c58..66f2b59 100644
@@ -171,32 +171,6 @@ if test x$grub_cv_apple_cc = xyes ; then

  ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
 fi

configure.ac +0 -26
-# Check LZO when compiling for the i386-pc.
-if test "$target_cpu"-"$platform" = i386-pc; then
-  AC_ARG_ENABLE([lzo],
-             [AS_HELP_STRING([--enable-lzo],
-                             [use lzo to compress kernel (default is lzma)])])
-  [if [ x"$enable_lzo" = xyes ]; then
-    # There are three possibilities. LZO version 2 installed with the name
-    # liblzo2, with the name liblzo, and LZO version 1.]
-    AC_DEFINE([ENABLE_LZO], [1], [Use lzo compression])
-    AC_CHECK_LIB([lzo2], [__lzo_init_v2], [LIBLZO="-llzo2"],
-      [AC_CHECK_LIB([lzo], [__lzo_init_v2], [LIBLZO="-llzo"],
-        [AC_CHECK_LIB([lzo], [__lzo_init2], [LIBLZO="-llzo"],
-              [AC_MSG_ERROR([LZO library version 1.02 or later is required])])])])
-    AC_SUBST([LIBLZO])
-    [LIBS="$LIBS $LIBLZO"]
-    AC_CHECK_FUNC([lzo1x_999_compress], ,
-               [AC_MSG_ERROR([LZO1X-999 must be enabled])])
-
-    [# LZO version 2 uses lzo/lzo1x.h, while LZO version 1 uses lzo1x.h.]
-    AC_CHECK_HEADERS([lzo/lzo1x.h lzo1x.h])
-  [else]
-    AC_DEFINE([ENABLE_LZMA], [1], [Use lzma compression])
-  [fi]
-  AC_SUBST([enable_lzo])
-fi
-

 # Check for functions.
 AC_CHECK_FUNCS(posix_memalign memalign asprintf)

include/grub/i386/pc/kernel.h +3 -4
index 5b9d8dc..e830afa 100644
@@ -41,11 +41,10 @@
  #define GRUB_KERNEL_MACHINE_DATA_END           0x5c
 
  /* The size of the first region which won't be compressed.  */
-#if defined(ENABLE_LZO)
-#define GRUB_KERNEL_MACHINE_RAW_SIZE           (GRUB_KERNEL_MACHINE_DATA_END + 0x450)
-#elif defined(ENABLE_LZMA)
  #define GRUB_KERNEL_MACHINE_RAW_SIZE           (GRUB_KERNEL_MACHINE_DATA_END + 0x5F0)
-#endif
+
+/* Enable LZMA compression */
+#define ENABLE_LZMA    1
 
  #ifndef ASM_FILE
 
kern/i386/pc/lzo1x.S deleted +0 -315
deleted file mode 100644
index 49ba8cc..0000000
@@ -1,315 +0,0 @@
-/*
- *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
- *  Copyright (C) 2003,2007  Free Software Foundation, Inc.
- *
- *  GRUB is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  GRUB is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * This code was stolen from the files enter.sh, leave.sh, lzo1x_d.sh,
- * lzo1x_f.s and lzo_asm.h in LZO version 1.08, and was heavily modified
- * to adapt it to GRUB's requirement.
- *
- * See <http://www.oberhumer.com/opensource/lzo/>, for more information
- * about LZO.
- */
-
-#define INP    4+16(%esp)
-#define INS    8+16(%esp)
-#define OUTP   12+16(%esp)
-#define NN     3
-#define N_3    %ebp
-#define N_255  $255
-#define LODSB  movb (%esi), %al ;  incl %esi
-#define NOTL_3(r)      xorl N_3, r
-#define MOVSL(r1,r2,x) movl (r1), x ; addl $4, r1 ; movl x, (r2) ; addl $4, r2
-#define COPYL_C(r1,r2,x,rc)    9: MOVSL(r1,r2,x) ; decl rc ; jnz 9b
-#define COPYL(r1,r2,x) COPYL_C(r1,r2,x,%ecx)
-
-lzo1x_decompress:
-       pushl   %ebp
-       pushl   %edi
-       pushl   %esi
-       pushl   %ebx
-
-       cld
-
-       movl    INP, %esi
-       movl    OUTP, %edi
-       movl    $3, %ebp
-
-
-       xorl    %eax, %eax
-       xorl    %ebx, %ebx      /* high bits 9-32 stay 0 */
-       lodsb
-       cmpb    $17, %al
-       jbe     .L01
-       subb    $17-NN, %al
-       jmp     .LFLR
-
-
-/***********************************************************************
-// literal run
-************************************************************************/
-
-0:     addl    N_255, %eax
-1:     movb    (%esi), %bl
-       incl    %esi
-       orb     %bl, %bl
-       jz      0b
-       leal    18+NN(%eax,%ebx), %eax
-       jmp     3f
-
-
-.L00:
-       LODSB
-.L01:
-       cmpb    $16, %al
-       jae     .LMATCH
-
-       /* a literal run */
-       orb     %al, %al
-       jz      1b
-       addl    $3+NN, %eax
-3:
-.LFLR:
-       movl    %eax, %ecx
-       NOTL_3(%eax)
-       shrl    $2, %ecx
-       andl    N_3, %eax
-       COPYL(%esi,%edi,%edx)
-       subl    %eax, %esi
-       subl    %eax, %edi
-
-       LODSB
-       cmpb    $16, %al
-       jae     .LMATCH
-
-
-/***********************************************************************
-// R1
-************************************************************************/
-
-       shrl    $2, %eax
-       movb    (%esi), %bl
-       leal    -0x801(%edi), %edx
-       leal    (%eax,%ebx,4), %eax
-       incl    %esi
-       subl    %eax, %edx
-       movl    (%edx), %ecx
-       movl    %ecx, (%edi)
-       addl    N_3, %edi
-       jmp     .LMDONE
-
-
-/***********************************************************************
-// M2
-************************************************************************/
-
-.LMATCH:
-       cmpb    $64, %al
-       jb      .LM3MATCH
-
-       /* a M2 match */
-       movl    %eax, %ecx
-       shrl    $2, %eax
-       leal    -1(%edi), %edx
-       andl    $7, %eax
-       movb    (%esi), %bl
-       shrl    $5, %ecx
-       leal    (%eax,%ebx,8), %eax
-       incl    %esi
-       subl    %eax, %edx
-
-       addl    $1+3, %ecx
-
-       cmpl    N_3, %eax
-       jae     .LCOPYLONG
-       jmp     .LCOPYBYTE
-
-
-/***********************************************************************
-// M3
-************************************************************************/
-
-0:     addl    N_255, %eax
-1:     movb    (%esi), %bl
-       incl    %esi
-       orb     %bl, %bl
-       jz      0b
-       leal    33+NN(%eax,%ebx), %ecx
-       xorl    %eax, %eax
-       jmp     3f
-
-
-.LM3MATCH:
-       cmpb    $32, %al
-       jb      .LM4MATCH
-
-       /* a M3 match */
-       andl    $31, %eax
-       jz      1b
-       lea     2+NN(%eax), %ecx
-3:
-       movw    (%esi), %ax
-       leal    -1(%edi), %edx
-       shrl    $2, %eax
-       addl    $2, %esi
-       subl    %eax, %edx
-
-       cmpl    N_3, %eax
-       jb      .LCOPYBYTE
-
-
-/***********************************************************************
-// copy match
-************************************************************************/
-
-.LCOPYLONG:                     /* copy match using longwords */
-       leal    -3(%edi,%ecx), %eax
-       shrl    $2, %ecx
-       COPYL(%edx,%edi,%ebx)
-       movl    %eax, %edi
-       xorl    %ebx, %ebx
-
-.LMDONE:
-       movb    -2(%esi), %al
-       andl    N_3, %eax
-       jz      .L00
-.LFLR3:
-       movl    (%esi), %edx
-       addl    %eax, %esi
-       movl    %edx, (%edi)
-       addl    %eax, %edi
-
-       LODSB
-       jmp     .LMATCH
-
-
-.LCOPYBYTE:                     /* copy match using bytes */
-       xchgl   %edx,%esi
-       subl    N_3,%ecx
-
-       rep
-       movsb
-       movl    %edx, %esi
-       jmp     .LMDONE
-
-
-/***********************************************************************
-// M4
-************************************************************************/
-
-0:     addl    N_255, %ecx
-1:     movb    (%esi), %bl
-       incl    %esi
-       orb     %bl, %bl
-       jz      0b
-       leal    9+NN(%ebx,%ecx), %ecx
-       jmp     3f
-
-
-.LM4MATCH:
-       cmpb    $16, %al
-       jb      .LM1MATCH
-
-       /* a M4 match */
-       movl    %eax, %ecx
-       andl    $8, %eax
-       shll    $13, %eax       /* save in bit 16 */
-       andl    $7, %ecx
-       jz      1b
-       addl    $2+NN, %ecx
-3:
-       movw    (%esi), %ax
-       addl    $2, %esi
-       leal    -0x4000(%edi), %edx
-       shrl    $2, %eax
-       jz      .LEOF
-       subl    %eax, %edx
-       jmp     .LCOPYLONG
-
-
-/***********************************************************************
-// M1
-************************************************************************/
-
-.LM1MATCH:
-       /* a M1 match */
-       shrl    $2, %eax
-       movb    (%esi), %bl
-       leal    -1(%edi), %edx
-       leal    (%eax,%ebx,4), %eax
-       incl    %esi
-       subl    %eax, %edx
-
-       movb    (%edx), %al     /* we must use this because edx can be edi-1 */
-       movb    %al, (%edi)
-       movb    1(%edx), %bl
-       movb    %bl, 1(%edi)
-       addl    $2, %edi
-       jmp     .LMDONE
-
-
-/***********************************************************************
-//
-************************************************************************/
-
-.LEOF:
-/****  xorl    %eax,%eax          eax=0 from above */
-
-       cmpl    $3+NN, %ecx     /* ecx must be 3/6 */
-       setnz   %al
-
-       /* check compressed size */
-       movl    INP, %edx
-       addl    INS, %edx
-       cmpl    %edx, %esi       /* check compressed size */
-       ja      .L_input_overrun
-       jb      .L_input_not_consumed
-
-.L_leave:
-       negl    %eax
-       jnz     1f
-
-       subl    OUTP, %edi       /* write back the uncompressed size */
-       movl    %edi, %eax
-
-1:     popl    %ebx
-       popl    %esi
-       popl    %edi
-       popl    %ebp
-       ret
-
-.L_input_not_consumed:
-        movl    $8, %eax         /* LZO_E_INPUT_NOT_CONSUMED */
-        jmp     .L_leave
-
-.L_input_overrun:
-        movl    $4, %eax         /* LZO_E_INPUT_OVERRUN */
-        jmp     .L_leave
-
-#undef INP
-#undef INS
-#undef OUTP
-#undef NN
-#undef NN
-#undef N_3
-#undef N_255
-#undef LODSB
-#undef NOTL_3
-#undef MOVSL
-#undef COPYL_C
-#undef COPYL
kern/i386/pc/startup.S +0 -0
index 171fbea..be258fb 100644
@@ -210,20 +210,7 @@ codestart:

       incl    %eax
       call    EXT_C(grub_gate_a20)

kern/i386/pc/startup.S +1 -14
-#if defined(ENABLE_LZO)
-       /* decompress the compressed part and put the result at 1MB */
-       movl    $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %esi
-       movl    $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
-
-       pushl   %esi
-       pushl   EXT_C(grub_compressed_size)
-       pushl   %edi
-       call    lzo1x_decompress
-       addl    $12, %esp
-
-       movl    %eax, %ecx
-       cld
-#elif defined(ENABLE_LZMA)
+#ifdef ENABLE_LZMA

       movl    $GRUB_MEMORY_MACHINE_DECOMPRESSION_ADDR, %edi movl    $(_start + GRUB_KERNEL_MACHINE_RAW_SIZE), %esi pushl   %edi

kern/i386/pc/startup.S +0 -0
@@ -451,9 +438,7 @@ gate_a20_check_state:

       popl    %ebx
       ret

kern/i386/pc/startup.S +1 -3
-#if defined(ENABLE_LZO)
-#include "lzo1x.S"
-#elif defined(ENABLE_LZMA)
+#ifdef ENABLE_LZMA

 #include "lzma_decode.S"
 #endif

util/i386/pc/grub-mkimage.c +2 -50
index ee1af82..b81392c 100644
@@ -36,57 +36,9 @@
  #define _GNU_SOURCE    1
  #include <getopt.h>
 
-#if defined(ENABLE_LZO)
-
-#if defined(HAVE_LZO_LZO1X_H)
-# include <lzo/lzo1x.h>
-#elif defined(HAVE_LZO1X_H)
-# include <lzo1x.h>
-#endif
-
-#elif defined(ENABLE_LZMA)
-
+#ifdef ENABLE_LZMA
  #include <grub/lib/LzmaEnc.h>
 
-#endif
-
-#if defined(ENABLE_LZO)
-
-static void
-compress_kernel (char *kernel_img, size_t kernel_size,
-                char **core_img, size_t *core_size)
-{
-  lzo_uint size;
-  char *wrkmem;
-
-  if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
-    grub_util_error ("the core image is too small");
-
-  if (lzo_init () != LZO_E_OK)
-    grub_util_error ("cannot initialize LZO");
-
-  *core_img = xmalloc (kernel_size + kernel_size / 64 + 16 + 3);
-  wrkmem = xmalloc (LZO1X_999_MEM_COMPRESS);
-
-  memcpy (*core_img, kernel_img, GRUB_KERNEL_MACHINE_RAW_SIZE);
-
-  grub_util_info ("compressing the core image");
-  if (lzo1x_999_compress ((const lzo_byte *) (kernel_img
-                                             + GRUB_KERNEL_MACHINE_RAW_SIZE),
-                         kernel_size - GRUB_KERNEL_MACHINE_RAW_SIZE,
-                         (lzo_byte *) (*core_img
-                                       + GRUB_KERNEL_MACHINE_RAW_SIZE),
-                         &size, wrkmem)
-      != LZO_E_OK)
-    grub_util_error ("cannot compress the kernel image");
-
-  free (wrkmem);
-
-  *core_size = (size_t) size + GRUB_KERNEL_MACHINE_RAW_SIZE;
-}
-
-#elif defined(ENABLE_LZMA)
-
  static void *SzAlloc(void *p, size_t size) { p = p; return xmalloc(size); }
  static void SzFree(void *p, void *address) { p = p; free(address); }
  static ISzAlloc g_Alloc = { SzAlloc, SzFree };
@@ -124,7 +76,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
   *core_size += GRUB_KERNEL_MACHINE_RAW_SIZE;
  }
 
-#else
+#else  /* No lzma compression */
 

 static void
 compress_kernel (char *kernel_img, size_t kernel_size,

util/i386/pc/grub-mkimage.c +1 -1
@@ -135,7 +87,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
   *core_size = kernel_size;
  }
 
-#endif
+#endif /* No lzma compression */
 

 static void
 generate_image (const char *dir, char *prefix, FILE *out, char *mods[],

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#3 lore raw

Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine

Quoted 11 lines · Vladimir 'phcoder' Serbinenko
Quoted 10 lines · Pavel Roskin

ChangeLog:

       * Makefile.in: Remove LIBLZO and enable_lzo.
       * conf/i386-pc.rmk: Remove lzo support.
       * configure.ac: Remove checks for lzo, don't define ENABLE_LZMA.
       * include/grub/i386/pc/kernel.h: Define ENABLE_LZMA.  Remove lzo support.
       * kern/i386/pc/lzo1x.S: Remove.
       * kern/i386/pc/startup.S: Remove lzo support.
       * util/i386/pc/grub-mkimage.c: Likewise.

Quoted 3 lines

Is there a reason to remove lzo? I know that lzma performs much better in terms of compression but afaik lzo doesn't create any problems nor is compiled by default

It doesn't break things, since it's barely modified, and doesn't interact with the rest of the code, but simply having more code means an added work to maintain it when we restructure things, etc. It needs to pay off in some way.

Quoted 1 line

and may be desirable for some users

Can you give an example?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#4 lore raw

Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine

Quoted 3 lines · Robert Millan

It doesn't break things, since it's barely modified, and doesn't interact with the rest of the code, but simply having more code means an added work to maintain it when we restructure things, etc. It needs to pay off in some way.

Exactly.

Actually, my intention was to improve test coverage. To test lzma and lzo, GRUB needs to be compiled twice.

If we want to support MacOS compilation properly (I mean local labels), we'll need to adjust both lzma and lzo.

Extra code means more development time wasted on mostly unused code.

There then there is an issue of user choice. I think we are offering too many choices without explaining what's behind it.

I could say lzo is "old and proven" and lzma is "new and more effective", but since lzo is disabled by default and there are no complaints about it, keeping lzo becomes pointless.

I don't think we are going to see compression much more effecting than lzma to justify keeping the infrastructure for more than one compression algorithm.

Signature · 2 lines
Regards,
Pavel Roskin
#5 lore raw

Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine

Quoted 6 lines

There then there is an issue of user choice.  I think we are offering too many choices without explaining what's behind it.

I could say lzo is "old and proven" and lzma is "new and more effective", but since lzo is disabled by default and there are no complaints about it, keeping lzo becomes pointless.

lzo is faster than lzma but I did a small count and seen that decompression time is around 10 ms on 31 KiB image on slow computer. Difference of few ms doesn't pay off

Quoted 4 lines

I don't think we are going to see compression much more effecting than lzma to justify keeping the infrastructure for more than one compression algorithm.

Now I agree with you. No further oppositions from me

Quoted 11 lines

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#6 lore raw

Re: [PATCH 2/2] Disable lzo compression, lzma is doing its job just fine

Quoted 1 line · Vladimir 'phcoder' Serbinenko

Now I agree with you. No further oppositions from me

Committed.

Signature · 2 lines
Regards,
Pavel Roskin
#7 lore raw
In reply to Pavel Roskin
Quoted 2 lines · Pavel Roskin

Even though it's a new function added to the core, its use makes core.img smaller.  And it makes modules smaller too.

I like the idea even if function name is inexplicit. Do you have a better alterative?

Quoted 946 lines

ChangeLog:

       * kern/mm.c (grub_malloc0): New function. (grub_debug_malloc0): Likewise.
       * include/grub/mm.h: Declare grub_malloc0() and grub_debug_malloc0().
       * util/misc.c (grub_malloc0): New function.
       * bus/usb/uhci.c (grub_uhci_pci_iter): Use grub_malloc0() instead of grub_malloc(), remove unneeded initializations.
       * bus/usb/usbhub.c (grub_usb_hub_add_dev): Likewise.
       * commands/extcmd.c (grub_extcmd_dispatcher): Likewise.
       * commands/parttool.c (grub_cmd_parttool): Likewise.
       * disk/i386/pc/biosdisk.c (grub_biosdisk_open): Likewise.
       * disk/raid5_recover.c (grub_raid5_recover): Likewise.
       * disk/raid6_recover.c (grub_raid6_recover): Likewise.
       * disk/usbms.c (grub_usbms_finddevs): Likewise.
       * efiemu/mm.c (grub_efiemu_request_memalign): Likewise.
       * efiemu/pnvram.c (grub_efiemu_pnvram): Likewise. (grub_cmd_efiemu_pnvram): Likewise.
       * fs/i386/pc/pxe.c (grub_pxefs_open): Likewise.
       * fs/iso9660.c (grub_iso9660_mount): Likewise. (grub_iso9660_iterate_dir): Likewise.
       * fs/jfs.c (grub_jfs_opendir): Likewise.
       * fs/ntfs.c (list_file): Likewise. (grub_ntfs_mount): Likewise.
       * kern/disk.c (grub_disk_open): Likewise.
       * kern/dl.c (grub_dl_load_core): Likewise.
       * kern/elf.c (grub_elf_file): Likewise.
       * kern/env.c (grub_env_context_open): Likewise. (grub_env_set): Likewise. (grub_env_set_data_slot): Likewise.
       * kern/file.c (grub_file_open): Likewise.
       * kern/fs.c (grub_fs_blocklist_open): Likewise.
       * loader/i386/multiboot.c (grub_module): Likewise.
       * loader/xnu.c (grub_xnu_create_key): Likewise. (grub_xnu_create_value): Likewise.
       * normal/main.c (grub_normal_add_menu_entry): Likewise. (read_config_file): Likewise.
       * normal/menu_entry.c (make_screen): Likewise.
       * partmap/sun.c (sun_partition_map_iterate): Likewise.
       * script/sh/lexer.c (grub_script_lexer_init): Likewise.
       * script/sh/script.c (grub_script_parse): Likewise.
       * video/bitmap.c (grub_video_bitmap_create): Likewise.
       * video/readers/jpeg.c (grub_video_reader_jpeg): Likewise.
       * video/readers/png.c (grub_png_output_byte): Likewise. (grub_video_reader_png): Likewise.
---
 bus/usb/uhci.c          |    5 +----
 bus/usb/usbhub.c        |    4 +---
 commands/extcmd.c       |    3 +--
 commands/parttool.c     |    7 ++----- disk/i386/pc/biosdisk.c |    3 +-- disk/raid5_recover.c    |    4 +--- disk/raid6_recover.c    |    7 ++-----
 disk/usbms.c            |    4 +---
 efiemu/mm.c             |    4 +---
 efiemu/pnvram.c         |    6 ++----
 fs/i386/pc/pxe.c        |    3 +--
 fs/iso9660.c            |    7 ++-----
 fs/jfs.c                |    4 +---
 fs/ntfs.c               |    7 ++----- include/grub/mm.h       |    6 ++++++
 kern/disk.c             |    6 +-----

 kern/dl.c               |    7 +------
 kern/elf.c              |    3 +--
 kern/env.c              |   11 +++--------

 kern/file.c             |    5 +----
 kern/fs.c               |    5 +----
 kern/mm.c               |   27 +++++++++++++++++++++++++++ loader/i386/multiboot.c |    3 +--
 loader/xnu.c            |    7 ++----- normal/main.c           |   14 ++++---------- normal/menu_entry.c     |    9 +-------- partmap/sun.c           |    4 +--- script/sh/lexer.c       |   11 +---------- script/sh/script.c      |    7 +------ util/misc.c             |   10 ++++++++++ video/bitmap.c          |    5 +---- video/readers/jpeg.c    |    3 +-- video/readers/png.c     |    6 ++----

 33 files changed, 85 insertions(+), 132 deletions(-)
bus/usb/uhci.c +1 -4
index 84cd48d..f902488 100644
@@ -170,14 +170,11 @@ grub_uhci_pci_iter (int bus, int device, int func,
     return 0;
 
   /* Allocate memory for the controller and register it.  */
-  u = grub_malloc (sizeof (*u));
+  u = grub_malloc0 (sizeof (*u));
   if (! u)
     return 1;
 
   u->iobase = base & GRUB_UHCI_IOMASK;
-  u->framelist = 0;
-  u->qh = 0;
-  u->td = 0;
   grub_dprintf ("uhci", "class=0x%02x 0x%02x interface 0x%02x base=0x%x\n",
                class, subclass, interf, u->iobase);
 
bus/usb/usbhub.c +1 -3
index ba0925a..336d657 100644
@@ -33,13 +33,11 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, grub_usb_speed_t speed)
   grub_usb_device_t dev;
   int i;
 
-  dev = grub_malloc (sizeof (struct grub_usb_device));
+  dev = grub_malloc0 (sizeof (struct grub_usb_device));
   if (! dev)
     return NULL;
 
   dev->controller = *controller;
-  dev->addr = 0;
-  dev->initialized = 0;
   dev->speed = speed;
 
   grub_usb_device_initialize (dev);
commands/extcmd.c +1 -2
index a605387..2e0d993 100644
@@ -40,8 +40,7 @@ grub_extcmd_dispatcher (struct grub_command *cmd,
     maxargs++;
 
   /* Set up the option state.  */
-  state = grub_malloc (sizeof (struct grub_arg_list) * maxargs);
-  grub_memset (state, 0, sizeof (struct grub_arg_list) * maxargs);
+  state = grub_malloc0 (sizeof (struct grub_arg_list) * maxargs);
 
   if (grub_arg_parse (ext, argc, args, state, &new_args, &new_argc))
     {
commands/parttool.c +2 -5
index c807f06..7e72791 100644
@@ -242,8 +242,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
     if (grub_strcmp (args[i], "help") == 0)
       return show_help ();
 
-  parsed = (int *) grub_malloc (argc * sizeof (int));
-  grub_memset (parsed, 0, argc * sizeof (int));
+  parsed = (int *) grub_malloc0 (argc * sizeof (int));
 
   for (i = 1; i < argc; i++)
     if (! parsed[i])
@@ -272,9 +271,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
                             args[i]);
        ptool = cur;
        pargs = (struct grub_parttool_args *)
-         grub_malloc (ptool->nargs * sizeof (struct grub_parttool_args));
-       grub_memset (pargs, 0,
-                    ptool->nargs * sizeof (struct grub_parttool_args));
+         grub_malloc0 (ptool->nargs * sizeof (struct grub_parttool_args));
        for (j = i; j < argc; j++)
          if (! parsed[j])
            {
disk/i386/pc/biosdisk.c +1 -2
index 09f0ce7..a71a8f4 100644
@@ -109,12 +109,11 @@ grub_biosdisk_open (const char *name, grub_disk_t disk)
   disk->has_partitions = ((drive & 0x80) && (drive != cd_drive));
   disk->id = drive;
 
-  data = (struct grub_biosdisk_data *) grub_malloc (sizeof (*data));
+  data = (struct grub_biosdisk_data *) grub_malloc0 (sizeof (*data));
   if (! data)
     return grub_errno;
 
   data->drive = drive;
-  data->flags = 0;
 
   if ((cd_drive) && (drive == cd_drive))
     {
disk/raid5_recover.c +1 -3
index 31cef88..e4f1f78 100644
@@ -32,12 +32,10 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr,
   int i;
 
   size <<= GRUB_DISK_SECTOR_BITS;
-  buf2 = grub_malloc (size);
+  buf2 = grub_malloc0 (size);
   if (!buf2)
     return grub_errno;
 
-  grub_memset (buf, 0, size);
-
   for (i = 0; i < (int) array->total_devs; i++)
     {
       grub_err_t err;
disk/raid6_recover.c +2 -5
index 3a994af..0b7242c 100644
@@ -96,11 +96,11 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
   char *pbuf = 0, *qbuf = 0;
 
   size <<= GRUB_DISK_SECTOR_BITS;
-  pbuf = grub_malloc (size);
+  pbuf = grub_malloc0 (size);
   if (!pbuf)
     goto quit;
 
-  qbuf = grub_malloc (size);
+  qbuf = grub_malloc0 (size);
   if (!qbuf)
     goto quit;
 
@@ -108,9 +108,6 @@ grub_raid6_recover (struct grub_raid_array *array, int disknr, int p,
   if (q == (int) array->total_devs)
     q = 0;
 
-  grub_memset (pbuf, 0, size);
-  grub_memset (qbuf, 0, size);
-
   pos = q + 1;
   if (pos == (int) array->total_devs)
     pos = 0;
disk/usbms.c +1 -3
index 3c7ebaf..4c5e216 100644
@@ -107,14 +107,12 @@ grub_usbms_finddevs (void)
            }
 
          devcnt++;
-         usbms = grub_malloc (sizeof (struct grub_usbms_dev));
+         usbms = grub_malloc0 (sizeof (struct grub_usbms_dev));
          if (! usbms)
            return 1;
 
          usbms->dev = usbdev;
          usbms->interface = i;
-         usbms->in = NULL;
-         usbms->out = NULL;
 
          /* Iterate over all endpoints of this interface, at least a

            IN and OUT bulk endpoint are required.  */

efiemu/mm.c +1 -3
index 7d6a5d4..290ca11 100644
@@ -104,14 +104,12 @@ grub_efiemu_request_memalign (grub_size_t align, grub_size_t size,
   requested_memory[type] += align_overhead + size;
 
   /* Remember the request */
-  ret = grub_malloc (sizeof (*ret));
+  ret = grub_malloc0 (sizeof (*ret));
   if (!ret)
     return -1;
   ret->type = type;
   ret->size = size;
   ret->align_overhead = align_overhead;
-  ret->val = 0;
-  ret->next = 0;
   prev = 0;
 
   /* Add request to the end of the chain.
efiemu/pnvram.c +2 -4
index d5daaab..21f7d93 100644
@@ -339,11 +339,10 @@ grub_efiemu_pnvram (void)
   accuracy = 50000000;
   daylight = 0;
 
-  nvram = grub_malloc (nvramsize);
+  nvram = grub_malloc0 (nvramsize);
   if (!nvram)
     return grub_error (GRUB_ERR_OUT_OF_MEMORY,
                       "Couldn't allocate space for temporary pnvram storage");
-  grub_memset (nvram, 0, nvramsize);
 
   return grub_efiemu_make_nvram ();
  }
@@ -365,11 +364,10 @@ grub_cmd_efiemu_pnvram (struct grub_extcmd *cmd,
   accuracy = state[3].set ? grub_strtoul (state[3].arg, 0, 0) : 50000000;
   daylight = state[4].set ? grub_strtoul (state[4].arg, 0, 0) : 0;
 
-  nvram = grub_malloc (nvramsize);
+  nvram = grub_malloc0 (nvramsize);
   if (!nvram)
     return grub_error (GRUB_ERR_OUT_OF_MEMORY,
                       "Couldn't allocate space for temporary pnvram storage");
-  grub_memset (nvram, 0, nvramsize);
 
   if (argc == 1 && (err = read_pnvram (args[0])))
     {
fs/i386/pc/pxe.c +1 -2
index 1fc5680..5ee5fb7 100644
@@ -146,11 +146,10 @@ grub_pxefs_open (struct grub_file *file, const char *name)
   if (c.c2.status)
     return grub_error (GRUB_ERR_BAD_FS, "open fails");
 
-  data = grub_malloc (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
+  data = grub_malloc0 (sizeof (struct grub_pxe_data) + grub_strlen (name) + 1);
   if (! data)
     return grub_errno;
 
-  data->packet_number = 0;
   data->block_size = grub_pxe_blksize;
   grub_strcpy (data->filename, name);
 
fs/iso9660.c +1 -3
index c79ad4f..6e5c3a9 100644
@@ -263,13 +263,11 @@ grub_iso9660_mount (grub_disk_t disk)
       return 0;
     }
 
-  data = grub_malloc (sizeof (struct grub_iso9660_data));
+  data = grub_malloc0 (sizeof (struct grub_iso9660_data));
   if (! data)
     return 0;
 
   data->disk = disk;
-  data->rockridge = 0;
-  data->joliet = 0;
 
   block = 16;

  do

fs/iso9660.c +0 -0
@@ -509,8 +507,7 @@ grub_iso9660_iterate_dir (grub_fshelp_node_t dir,

             else
               {
                 size = entry->len - 5;
-                 filename = grub_malloc (size + 1);
-                 filename[0] = '\0';
+                 filename = grub_malloc0 (size + 1);
               }
             filename_alloc = 1;
             grub_strncpy (filename, (char *) &entry->data[1], size);

fs/jfs.c +1 -3
index 4f91825..fae2800 100644
@@ -382,11 +382,10 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
       return 0;
     }
 
-  diro = grub_malloc (sizeof (struct grub_jfs_diropen));
+  diro = grub_malloc0 (sizeof (struct grub_jfs_diropen));
   if (!diro)
     return 0;
 
-  diro->index = 0;
   diro->data = data;
   diro->inode = inode;
 
@@ -397,7 +396,6 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
       diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
       diro->sorted = (char *) (inode->dir.header.sorted);
       diro->count = inode->dir.header.count;
-      diro->dirpage = 0;
 
       return diro;
     }
fs/ntfs.c +0 -0
index c312b8b..bcbbdae 100644
@@ -601,11 +601,10 @@ list_file (struct grub_ntfs_file *diro, char *pos,

           (u32at (pos, 0x48) & ATTR_DIRECTORY) ? GRUB_FSHELP_DIR :
           GRUB_FSHELP_REG;

-         fdiro = grub_malloc (sizeof (struct grub_ntfs_file));
+         fdiro = grub_malloc0 (sizeof (struct grub_ntfs_file)); if (!fdiro)
           return 0;

-         grub_memset (fdiro, 0, sizeof (*fdiro)); fdiro->data = diro->data; fdiro->ino = u32at (pos, 0);

fs/ntfs.c +1 -3
@@ -791,12 +790,10 @@ grub_ntfs_mount (grub_disk_t disk)
   if (!disk)
     goto fail;
 
-  data = (struct grub_ntfs_data *) grub_malloc (sizeof (*data));
+  data = (struct grub_ntfs_data *) grub_malloc0 (sizeof (*data));
   if (!data)
     goto fail;
 
-  grub_memset (data, 0, sizeof (*data));
-
   data->disk = disk;
 
   /* Read the BPB.  */
include/grub/mm.h +6 -0
index 4dd1363..413e439 100644
@@ -30,6 +30,7 @@
 
  void grub_mm_init_region (void *addr, grub_size_t size);
  void *EXPORT_FUNC(grub_malloc) (grub_size_t size);
+void *EXPORT_FUNC(grub_malloc0) (grub_size_t size);
  void EXPORT_FUNC(grub_free) (void *ptr);
  void *EXPORT_FUNC(grub_realloc) (void *ptr, grub_size_t size);
  void *EXPORT_FUNC(grub_memalign) (grub_size_t align, grub_size_t size);
@@ -45,6 +46,9 @@ void grub_mm_dump (unsigned lineno);
  #define grub_malloc(size)      \
   grub_debug_malloc (__FILE__, __LINE__, size)
 
+#define grub_malloc0(size)     \
+  grub_debug_malloc0 (__FILE__, __LINE__, size)
+
  #define grub_realloc(ptr,size) \
   grub_debug_realloc (__FILE__, __LINE__, ptr, size)
 
@@ -56,6 +60,8 @@ void grub_mm_dump (unsigned lineno);
 
  void *EXPORT_FUNC(grub_debug_malloc) (const char *file, int line,
                                      grub_size_t size);
+void *EXPORT_FUNC(grub_debug_malloc0) (const char *file, int line,
+                                      grub_size_t size);
  void EXPORT_FUNC(grub_debug_free) (const char *file, int line, void *ptr);
  void *EXPORT_FUNC(grub_debug_realloc) (const char *file, int line, void *ptr,
                                       grub_size_t size);
kern/disk.c +1 -5
index e167fb6..d1e3da3 100644
@@ -244,14 +244,10 @@ grub_disk_open (const char *name)
 
   grub_dprintf ("disk", "Opening `%s'...\n", name);
 
-  disk = (grub_disk_t) grub_malloc (sizeof (*disk));
+  disk = (grub_disk_t) grub_malloc0 (sizeof (*disk));
   if (! disk)
     return 0;
 
-  disk->dev = 0;
-  disk->read_hook = 0;
-  disk->partition = 0;
-  disk->data = 0;
   disk->name = grub_strdup (name);
   if (! disk->name)
     goto fail;
kern/dl.c +1 -6
index 122b6b9..ad6fc49 100644
@@ -535,16 +535,11 @@ grub_dl_load_core (void *addr, grub_size_t size)
       return 0;
     }
 
-  mod = (grub_dl_t) grub_malloc (sizeof (*mod));
+  mod = (grub_dl_t) grub_malloc0 (sizeof (*mod));
   if (! mod)
     return 0;
 
-  mod->name = 0;
   mod->ref_count = 1;
-  mod->dep = 0;
-  mod->segment = 0;
-  mod->init = 0;
-  mod->fini = 0;
 
   grub_dprintf ("modules", "relocating to %p\n", mod);
   if (grub_dl_resolve_name (mod, e)
kern/elf.c +1 -2
index 2590552..a9f4649 100644
@@ -61,12 +61,11 @@ grub_elf_file (grub_file_t file)
  {
   grub_elf_t elf;
 
-  elf = grub_malloc (sizeof (*elf));
+  elf = grub_malloc0 (sizeof (*elf));
   if (! elf)
     return 0;
 
   elf->file = file;
-  elf->phdrs = 0;
 
   if (grub_file_seek (elf->file, 0) == (grub_off_t) -1)
     goto fail;
kern/env.c +2 -5
index e85627b..faca4c0 100644
@@ -80,11 +80,10 @@ grub_env_context_open (int export)
   struct grub_env_context *context;
   int i;
 
-  context = grub_malloc (sizeof (*context));
+  context = grub_malloc0 (sizeof (*context));
   if (! context)
     return grub_errno;
 
-  grub_memset (context, 0, sizeof (*context));
   context->prev = current_context;
   current_context = context;
 
@@ -204,12 +203,10 @@ grub_env_set (const char *name, const char *val)
     }
 
   /* The variable does not exist, so create a new one.  */
-  var = grub_malloc (sizeof (*var));
+  var = grub_malloc0 (sizeof (*var));
   if (! var)
     return grub_errno;
 
-  grub_memset (var, 0, sizeof (*var));
-
   /* This is not necessary, because GRUB_ENV_VAR_LOCAL == 0. But leave

     this for readability.  */
  var->type = GRUB_ENV_VAR_LOCAL;

kern/env.c +1 -3
@@ -379,12 +376,10 @@ grub_env_set_data_slot (const char *name, const void *ptr)
     }
 
   /* The variable does not exist, so create a new one.  */
-  var = grub_malloc (sizeof (*var));
+  var = grub_malloc0 (sizeof (*var));
   if (! var)
     goto fail;
 
-  grub_memset (var, 0, sizeof (*var));
-
   var->type = GRUB_ENV_VAR_DATA;
   var->name = mangled_name;
   var->value = (char *) ptr;
kern/file.c +1 -4
index 5d5e640..2d7d967 100644
@@ -75,14 +75,11 @@ grub_file_open (const char *name)
   if (! device)
     goto fail;
 
-  file = (grub_file_t) grub_malloc (sizeof (*file));
+  file = (grub_file_t) grub_malloc0 (sizeof (*file));
   if (! file)
     goto fail;
 
   file->device = device;
-  file->offset = 0;
-  file->data = 0;
-  file->read_hook = 0;
 
   if (device->disk && file_name[0] != '/')
     /* This is a block list.  */
kern/fs.c +1 -4
index c8f4970..f17347e 100644
@@ -161,7 +161,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
   while (p);
 
   /* Allocate a block list.  */
-  blocks = grub_malloc (sizeof (struct grub_fs_block) * (num + 1));
+  blocks = grub_malloc0 (sizeof (struct grub_fs_block) * (num + 1));
   if (! blocks)
     return 0;
 
@@ -179,8 +179,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
              goto fail;
            }
        }
-      else
-       blocks[i].offset = 0;
 
       p++;
       blocks[i].length = grub_strtoul (p, &p, 0);
@@ -203,7 +201,6 @@ grub_fs_blocklist_open (grub_file_t file, const char *name)
       p++;
     }
 
-  blocks[i].length = 0;
   file->data = blocks;
 
   return GRUB_ERR_NONE;
kern/mm.c +14 -0
index 9a0ae56..a07bd42 100644
@@ -68,6 +68,7 @@
 
  #ifdef MM_DEBUG
  # undef grub_malloc
+# undef grub_malloc0
  # undef grub_realloc
  # undef grub_free
  # undef grub_memalign
@@ -348,6 +349,19 @@ grub_malloc (grub_size_t size)
   return grub_memalign (0, size);
  }
 
+/* Allocate SIZE bytes, clear them and return the pointer.  */
+void *
+grub_malloc0 (grub_size_t size)
+{
+  void *ret;
+
+  ret = grub_memalign (0, size);
+  if (ret)
+    grub_memset (ret, 0, size);
+
+  return ret;
+}
+
  /* Deallocate the pointer PTR.  */

 void
 grub_free (void *ptr)

kern/mm.c +13 -0
@@ -522,6 +536,19 @@ grub_debug_malloc (const char *file, int line, grub_size_t size)
   return ptr;
  }
 
+void *
+grub_debug_malloc0 (const char *file, int line, grub_size_t size)
+{
+  void *ptr;
+
+  if (grub_mm_debug)
+    grub_printf ("%s:%d: malloc0 (0x%zx) = ", file, line, size);
+  ptr = grub_malloc0 (size);
+  if (grub_mm_debug)
+    grub_printf ("%p\n", ptr);
+  return ptr;
+}
+

 void
 grub_debug_free (const char *file, int line, void *ptr) {

loader/i386/multiboot.c +0 -0
index 8ce315e..7e9ac66 100644
@@ -456,13 +456,12 @@ grub_module  (int argc, char *argv[])
     }

  else
    {
-      struct grub_mod_list *modlist = grub_malloc (sizeof (struct grub_mod_list));
+      struct grub_mod_list *modlist = grub_malloc0 (sizeof (struct grub_mod_list)); if (! modlist)
       goto fail;
      modlist->mod_start = (grub_uint32_t) module;
      modlist->mod_end = (grub_uint32_t) module + size; modlist->cmdline = (grub_uint32_t) cmdline;
-      modlist->pad = 0;
      mbi->mods_count = 1;
      mbi->mods_addr = (grub_uint32_t) modlist;
      mbi->flags |= MULTIBOOT_INFO_MODS;

loader/xnu.c +2 -5
index b2c6c05..0861b83 100644
@@ -278,7 +278,7 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
   ret = grub_xnu_find_key (*parent, name);
   if (ret)
     return ret;
-  ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
+  ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
   if (! ret)
     {
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create key %s", name);
@@ -292,7 +292,6 @@ grub_xnu_create_key (struct grub_xnu_devtree_key **parent, char *name)
       return 0;
     }
   ret->datasize = -1;
-  ret->first_child = 0;
   ret->next = *parent;
   *parent = ret;
   return ret;
@@ -313,7 +312,7 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
       ret->data = 0;
       return ret;
     }
-  ret = (struct grub_xnu_devtree_key *) grub_malloc (sizeof (*ret));
+  ret = (struct grub_xnu_devtree_key *) grub_malloc0 (sizeof (*ret));
   if (! ret)
     {
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
@@ -326,8 +325,6 @@ grub_xnu_create_value (struct grub_xnu_devtree_key **parent, char *name)
       grub_error (GRUB_ERR_OUT_OF_MEMORY, "can't create value %s", name);
       return 0;
     }
-  ret->datasize = 0;
-  ret->data = 0;
   ret->next = *parent;
   *parent = ret;
   return ret;
normal/main.c +4 -10
index 7f6336e..878b947 100644
@@ -166,11 +166,9 @@ grub_normal_add_menu_entry (int argc, const char **args,
   struct grub_menu_entry_class *classes_tail;
 
   /* Allocate dummy head node for class list.  */
-  classes_head = grub_malloc (sizeof (struct grub_menu_entry_class));
+  classes_head = grub_malloc0 (sizeof (struct grub_menu_entry_class));
   if (! classes_head)
     return grub_errno;
-  classes_head->name = 0;
-  classes_head->next = 0;
   classes_tail = classes_head;
 
   menu = grub_env_get_data_slot ("menu");
@@ -206,7 +204,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
                }
 
              /* Create a new class and add it at the tail of the list.  */
-             new_class = grub_malloc (sizeof (struct grub_menu_entry_class));
+             new_class = grub_malloc0 (sizeof (struct grub_menu_entry_class));
              if (! new_class)
                {
                  grub_free (class_name);
@@ -215,7 +213,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
                }
              /* Fill in the new class node.  */
              new_class->name = class_name;
-             new_class->next = 0;
              /* Link the tail to it, and make it the new tail.  */
              classes_tail->next = new_class;
              classes_tail = new_class;
@@ -267,7 +264,7 @@ grub_normal_add_menu_entry (int argc, const char **args,
   while (*last)
     last = &(*last)->next;
 
-  *last = grub_malloc (sizeof (**last));
+  *last = grub_malloc0 (sizeof (**last));
   if (! *last)
     {
       free_menu_entry_classes (classes_head);
@@ -278,7 +275,6 @@ grub_normal_add_menu_entry (int argc, const char **args,
 
   (*last)->title = menutitle;
   (*last)->classes = classes_head;
-  (*last)->next = 0;
   (*last)->sourcecode = menusourcecode;
 
   menu->size++;
@@ -346,11 +342,9 @@ read_config_file (const char *config)
   newmenu = grub_env_get_data_slot ("menu");
   if (! newmenu)
     {
-      newmenu = grub_malloc (sizeof (*newmenu));
+      newmenu = grub_malloc0 (sizeof (*newmenu));
       if (! newmenu)
        return 0;
-      newmenu->size = 0;
-      newmenu->entry_list = 0;
 
       grub_env_set_data_slot ("menu", newmenu);
     }
normal/menu_entry.c +1 -8
index 86e581e..86cad0a 100644
@@ -416,18 +416,11 @@ make_screen (grub_menu_entry_t entry)
   struct screen *screen;
 
   /* Initialize the screen.  */
-  screen = grub_malloc (sizeof (*screen));
+  screen = grub_malloc0 (sizeof (*screen));
   if (! screen)
     return 0;
 
   screen->num_lines = 1;
-  screen->column = 0;
-  screen->real_column = 0;
-  screen->line = 0;
-  screen->x = 0;
-  screen->y = 0;
-  screen->killed_text = 0;
-  screen->completion_shown = 0;
   screen->lines = grub_malloc (sizeof (struct line));
   if (! screen->lines)
     goto fail;
partmap/sun.c +1 -3
index 6094777..e442ff7 100644
@@ -95,12 +95,10 @@ sun_partition_map_iterate (grub_disk_t disk,
   raw = *disk;
   raw.partition = 0;
 
-  p = (grub_partition_t) grub_malloc (sizeof (struct grub_partition));
+  p = (grub_partition_t) grub_malloc0 (sizeof (struct grub_partition));
   if (! p)
     return grub_errno;
 
-  p->offset = 0;
-  p->data = 0;
   p->partmap = &grub_sun_partition_map;
   if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
                      &block) == GRUB_ERR_NONE)
script/sh/lexer.c +1 -10
index 17f18e2..cbc33d7 100644
@@ -49,22 +49,13 @@ grub_script_lexer_init (char *script, grub_reader_getline_t getline)
  {
   struct grub_lexer_param *param;
 
-  param = grub_malloc (sizeof (*param));
+  param = grub_malloc0 (sizeof (*param));
   if (! param)
     return 0;
 
   param->state = GRUB_PARSER_STATE_TEXT;
   param->getline = getline;
-  param->refs = 0;
-  param->done = 0;
-  param->newscript = 0;
   param->script = script;
-  param->record = 0;
-  param->recording = 0;
-  param->recordpos = 0;
-  param->recordlen = 0;
-  param->tokenonhold = 0;
-  param->was_newline = 0;
 
   return param;
  }
script/sh/script.c +1 -6
index 89fa947..3019cd7 100644
@@ -304,15 +304,10 @@ grub_script_parse (char *script, grub_reader_getline_t getline)
   if (! parsed)
     return 0;
 
-  parsestate = grub_malloc (sizeof (*parsestate));
+  parsestate = grub_malloc0 (sizeof (*parsestate));
   if (! parsestate)
     return 0;
 
-  parsestate->err = 0;
-  parsestate->func_mem = 0;
-  parsestate->memused = 0;
-  parsestate->parsed = 0;
-
   /* Initialize the lexer.  */
   lexstate = grub_script_lexer_init (script, getline);
   if (! lexstate)
util/misc.c +10 -0
index f615a42..19a4244 100644
@@ -257,6 +257,16 @@ grub_malloc (grub_size_t size)
   return xmalloc (size);
  }
 
+void *
+grub_malloc0 (grub_size_t size)
+{
+  void *ret;
+
+  ret = xmalloc (size);
+  memset (ret, 0, size);
+  return ret;
+}
+

 void
 grub_free (void *ptr)
 {

video/bitmap.c +1 -4
index d399fd7..009d3e4 100644
@@ -137,7 +137,7 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
   /* Calculate size needed for the data.  */
   size = (width * mode_info->bytes_per_pixel) * height;
 
-  (*bitmap)->data = grub_malloc (size);
+  (*bitmap)->data = grub_malloc0 (size);
   if (! (*bitmap)->data)
     {
       grub_free (*bitmap);
@@ -146,9 +146,6 @@ grub_video_bitmap_create (struct grub_video_bitmap **bitmap,
       return grub_errno;
     }
 
-  /* Clear bitmap.  */
-  grub_memset ((*bitmap)->data, 0, size);
-
   return GRUB_ERR_NONE;
  }
 
video/readers/jpeg.c +1 -2
index b64bf3f..076f6fd 100644
@@ -667,12 +667,11 @@ grub_video_reader_jpeg (struct grub_video_bitmap **bitmap,
   if (!file)
     return grub_errno;
 
-  data = grub_malloc (sizeof (*data));
+  data = grub_malloc0 (sizeof (*data));
   if (data != NULL)
     {
       int i;
 
-      grub_memset (data, 0, sizeof (*data));
       data->file = file;
       data->bitmap = bitmap;
       grub_jpeg_decode_jpeg (data);
video/readers/png.c +1 -2
index 733fa73..3ae8fb2 100644
@@ -543,11 +543,10 @@ grub_png_output_byte (struct grub_png_data *data, grub_uint8_t n)
 
       if (data->first_line)
        {
-         blank_line = grub_malloc (row_bytes);
+         blank_line = grub_malloc0 (row_bytes);
          if (blank_line == NULL)
            return grub_errno;
 
-         grub_memset (blank_line, 0, row_bytes);
          up = blank_line;
        }

      else

video/readers/png.c +1 -2
@@ -843,10 +842,9 @@ grub_video_reader_png (struct grub_video_bitmap **bitmap,
   if (!file)
     return grub_errno;
 
-  data = grub_malloc (sizeof (*data));
+  data = grub_malloc0 (sizeof (*data));
   if (data != NULL)
     {
-      grub_memset (data, 0, sizeof (*data));
       data->file = file;
       data->bitmap = bitmap;
 

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#8 lore raw
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Pavel Roskin

Even though it's a new function added to the core, its use makes core.img smaller. And it makes modules smaller too.

I like the idea even if function name is inexplicit. Do you have a better alterative?

I was thinking about it. Here are some ideas:

grub_malloc0 - good that "0" is there, bad that malloc0 is not a traditional libc name. It's easy to scan sources for both grub_malloc and grub_malloc0

grub_calloc - we would need two arguments (element size and element number) to be compatible with libc. We could make it a macro expandable to grub_malloc0 to optimize out multiplication. Still, having two arguments introduces unnecessary choice to the caller.

grub_calloc with one argument - this break the tradition or replacing libc functions with equivalents.

grub_zalloc - similar to Linux kzalloc and kmalloc. By zalloc is not a libc function.

grub_malloc_cleared, grub_malloc_zero - too long and just as nonstandard as grub_zalloc.

grub_0malloc - even more weird than grub_malloc0, and it's harder to scan for both.

After having written that, I actually tend to prefer grub_zalloc().

Signature · 2 lines
Regards,
Pavel Roskin
#9 lore raw
Quoted 24 lines · Pavel Roskin
Quoted 5 lines · Vladimir 'phcoder' Serbinenko
Quoted 2 lines · Pavel Roskin

Even though it's a new function added to the core, its use makes core.img smaller.  And it makes modules smaller too.

I like the idea even if function name is inexplicit. Do you have a better alterative?

I was thinking about it.  Here are some ideas:

grub_malloc0 - good that "0" is there, bad that malloc0 is not a traditional libc name.  It's easy to scan sources for both grub_malloc and grub_malloc0

grub_calloc - we would need two arguments (element size and element number) to be compatible with libc.  We could make it a macro expandable to grub_malloc0 to optimize out multiplication.  Still, having two arguments introduces unnecessary choice to the caller.

grub_calloc with one argument - this break the tradition or replacing libc functions with equivalents.

grub_zalloc - similar to Linux kzalloc and kmalloc.  By zalloc is not a libc function.

Quoted 8 lines

grub_malloc_cleared, grub_malloc_zero - too long and just as nonstandard as grub_zalloc.

grub_0malloc - even more weird than grub_malloc0, and it's harder to scan for both.

After having written that, I actually tend to prefer grub_zalloc().

After having read this I agree with you

Quoted 11 lines

--
Regards,
Pavel Roskin

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#10 lore raw
Quoted 2 lines · Vladimir 'phcoder' Serbinenko
Quoted 1 line

After having written that, I actually tend to prefer grub_zalloc().

After having read this I agree with you

Committed with grub_zalloc().

Signature · 2 lines
Regards,
Pavel Roskin