Skip to contentSkip to conversation

Move grub_usb_get_string out of usb.mod

PATCH New Vladimir 'phcoder' Serbinenko 1 participant 1 message Aug 28, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Move grub_usb_get_string out of usb.mod

usb.mod may be size-critical (if booting from usb) but usbtest.mod isn't. grub_usb_get_string is in usb.mod but used only in usbtest.mod. Furthermore it's the only potentially size-critical function except filesystems which uses grub_utf16_to_utf8. Making it non-size critical would allow to inline it and save few bytes. Here is a patch to fix situation

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
ChangeLog +7 -0
index b657885..3e8d253 100644
@@ -1,5 +1,12 @@
 2009-08-28  Vladimir Serbinenko  <[email protected]>
 
+	* bus/usb/usb.c (grub_usb_get_string): Move from here ...
+	* commands/usbtest.c (grub_usb_get_string): ... move here.
+	(usb_print_str): Fix error handling.
+	* include/grub/usb.h (grub_usb_get_string): Remove.
+
+2009-08-28  Vladimir Serbinenko  <[email protected]>
+
 	* kern/file.c (grub_file_read): Check offset.
 	* fs/hfs.c (grub_hfs_read_file): Remove unnecessary offset check.
 	* fs/jfs.c (grub_jfs_read_file): Likewise.
bus/usb/usb.c +0 -36
index 310b8cc..8289185 100644
@@ -156,42 +156,6 @@ grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr)
 }
 
 grub_usb_err_t
-grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index, int langid,
-		     char **string)
-{
-  struct grub_usb_desc_str descstr;
-  struct grub_usb_desc_str *descstrp;
-  grub_usb_err_t err;
-
-  /* Only get the length.  */
-  err = grub_usb_control_msg (dev, 1 << 7,
-			      0x06, (3 << 8) | index,
-			      langid, 1, (char *) &descstr);
-  if (err)
-    return err;
-
-  descstrp = grub_malloc (descstr.length);
-  if (! descstrp)
-    return GRUB_USB_ERR_INTERNAL;
-  err = grub_usb_control_msg (dev, 1 << 7,
-			      0x06, (3 << 8) | index,
-			      langid, descstr.length, (char *) descstrp);
-
-  *string = grub_malloc (descstr.length / 2);
-  if (! *string)
-    {
-      grub_free (descstrp);
-      return GRUB_USB_ERR_INTERNAL;
-    }
-
-  grub_utf16_to_utf8 ((grub_uint8_t *) *string, descstrp->str, descstrp->length / 2 - 1);
-  (*string)[descstr.length / 2 - 1] = '\0';
-  grub_free (descstrp);
-
-  return GRUB_USB_ERR_NONE;
-}
-
-grub_usb_err_t
 grub_usb_device_initialize (grub_usb_device_t dev)
 {
   struct grub_usb_desc_device *descdev;
commands/usbtest.c +45 -3

63 lines not on this page · raw message

include/grub/usb.h +0 -3
index 8dd3b6e..dc90e78 100644
@@ -64,9 +64,6 @@ grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint);
 grub_usb_err_t grub_usb_set_configuration (grub_usb_device_t dev,
 					   int configuration);
 
-grub_usb_err_t grub_usb_get_string (grub_usb_device_t dev, grub_uint8_t index,
-				    int langid, char **string);
-
 void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb);
 
 void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);