]> git.proxmox.com Git - grub2.git/commitdiff
Move grub_usb_get_string.
authorphcoder <phcoder@debian.easynote.phnet.easynote.phnet>
Fri, 28 Aug 2009 18:09:44 +0000 (20:09 +0200)
committerphcoder <phcoder@debian.easynote.phnet.easynote.phnet>
Fri, 28 Aug 2009 18:09:44 +0000 (20:09 +0200)
ChangeLog
bus/usb/usb.c
commands/usbtest.c
include/grub/usb.h

index b657885fed4f66b86a64e42bbf0b7458376ba27f..3e8d2533b6445d9694edd235ebd463de42747718 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-28  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * 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  <phcoder@gmail.com>
 
        * kern/file.c (grub_file_read): Check offset.
index 310b8cc6a97564bfa2758f292c3034f6beff6cec..8289185da67da45cf6df8ddb6d561768d7247bc3 100644 (file)
@@ -155,42 +155,6 @@ grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr)
   return NULL;
 }
 
-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)
 {
index 018c1a25bb63f4375d9f3e4af907084972085adf..1c49d8104dfdd10ffb4afa9ba66d55dab442bf7d 100644 (file)
@@ -59,18 +59,60 @@ static const char *usb_devspeed[] =
     "High"
   };
 
+static 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;
+}
+
 static void
 usb_print_str (const char *description, grub_usb_device_t dev, int idx)
 {
   char *name;
+  grub_usb_err_t err;
   /* XXX: LANGID  */
 
   if (! idx)
     return;
 
-  grub_usb_get_string (dev, idx, 0x0409, &name);
-  grub_printf ("%s: `%s'\n", description, name);
-  grub_free (name);
+  err = grub_usb_get_string (dev, idx, 0x0409, &name);
+  if (err)
+    grub_printf ("Error %d retrieving %s\n", err, description);
+  else
+    {
+      grub_printf ("%s: `%s'\n", description, name);
+      grub_free (name);
+    }
 }
 
 static int
index 8dd3b6e2ec8d03d1807a1cb7e50bd0b9a49e968f..dc90e787921dc268cc77726f1d4a4cb3db97f398 100644 (file)
@@ -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);