Index: uspace/lib/usbdev/src/request.c
===================================================================
--- uspace/lib/usbdev/src/request.c	(revision 94c40ce2fbf2aaad836abc367830f94458ebe367)
+++ uspace/lib/usbdev/src/request.c	(revision d8cdf39e69c66f24413ec8870e82b1e544433085)
@@ -49,9 +49,9 @@
  * @param request Actual request (e.g. GET_DESCRIPTOR).
  * @param value Value of @c wValue field of setup packet
- * 	(must be in USB endianness).
+ *	(must be in USB endianness).
  * @param index Value of @c wIndex field of setup packet
- * 	(must be in USB endianness).
+ *	(must be in USB endianness).
  * @param data Data to be sent during DATA stage
- * 	(expected to be in USB endianness).
+ *	(expected to be in USB endianness).
  * @param data_size Size of the @p data buffer (in native endianness).
  * @return Error code.
@@ -62,7 +62,6 @@
 int usb_control_request_set(usb_pipe_t *pipe,
     usb_request_type_t request_type, usb_request_recipient_t recipient,
-    uint8_t request,
-    uint16_t value, uint16_t index,
-    void *data, size_t data_size)
+    uint8_t request, uint16_t value, uint16_t index,
+    const void *data, size_t data_size)
 {
 	if (pipe == NULL) {
@@ -83,16 +82,14 @@
 	 */
 
-	usb_device_request_setup_packet_t setup_packet;
-	setup_packet.request_type = (request_type << 5) | recipient;
-	setup_packet.request = request;
-	setup_packet.value = value;
-	setup_packet.index = index;
-	setup_packet.length = (uint16_t) data_size;
-
-	int rc = usb_pipe_control_write(pipe,
-	    &setup_packet, sizeof(setup_packet),
-	    data, data_size);
-
-	return rc;
+	const usb_device_request_setup_packet_t setup_packet = {
+		.request_type = (request_type << 5) | recipient,
+		.request = request,
+		.value = value,
+		.index = index,
+		.length = (uint16_t) data_size,
+	};
+
+	return usb_pipe_control_write(pipe,
+	    &setup_packet, sizeof(setup_packet), data, data_size);
 }
 
@@ -106,5 +103,5 @@
   * @param request Actual request (e.g. GET_DESCRIPTOR).
   * @param value Value of @c wValue field of setup packet
-  * 	(must be in USB endianness).
+  *	(must be in USB endianness).
   * @param index Value of @c wIndex field of setup packet
   *	(must be in USB endianness).
@@ -114,5 +111,5 @@
   *	(in native endianness).
   * @param actual_data_size Actual size of transfered data
-  *        (in native endianness).
+  *	(in native endianness).
   * @return Error code.
   * @retval EBADMEM @p pipe is NULL.
@@ -122,6 +119,5 @@
 int usb_control_request_get(usb_pipe_t *pipe,
     usb_request_type_t request_type, usb_request_recipient_t recipient,
-    uint8_t request,
-    uint16_t value, uint16_t index,
+    uint8_t request, uint16_t value, uint16_t index,
     void *data, size_t data_size, size_t *actual_data_size)
 {
@@ -207,16 +203,13 @@
 {
 	if (request_type == USB_REQUEST_TYPE_STANDARD) {
-		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
-		    && (index != 0)) {
+		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0))
+		{
 			return EINVAL;
 		}
 	}
 
-	int rc = usb_control_request_set(pipe, request_type, recipient,
-	    USB_DEVREQ_CLEAR_FEATURE,
-	    uint16_host2usb(feature_selector), uint16_host2usb(index),
-	    NULL, 0);
-
-	return rc;
+	return usb_control_request_set(pipe,
+	    request_type, recipient, USB_DEVREQ_CLEAR_FEATURE,
+	    uint16_host2usb(feature_selector), uint16_host2usb(index), NULL, 0);
 }
 
@@ -235,16 +228,13 @@
 {
 	if (request_type == USB_REQUEST_TYPE_STANDARD) {
-		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
-		    && (index != 0)) {
+		if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0))
+		{
 			return EINVAL;
 		}
 	}
 
-	int rc = usb_control_request_set(pipe, request_type, recipient,
-	    USB_DEVREQ_SET_FEATURE,
-	    uint16_host2usb(feature_selector), uint16_host2usb(index),
-	    NULL, 0);
-
-	return rc;
+	return usb_control_request_set(pipe,
+	    request_type, recipient, USB_DEVREQ_SET_FEATURE,
+	    uint16_host2usb(feature_selector), uint16_host2usb(index), NULL, 0);
 }
 
@@ -314,21 +304,19 @@
 	 * Get only first byte to retrieve descriptor length.
 	 */
-	uint8_t tmp_buffer[1];
+	uint8_t tmp_buffer;
 	size_t bytes_transfered;
 	rc = usb_request_get_descriptor(pipe, request_type, recipient,
 	    descriptor_type, descriptor_index, language,
-	    &tmp_buffer, 1, &bytes_transfered);
+	    &tmp_buffer, sizeof(tmp_buffer), &bytes_transfered);
 	if (rc != EOK) {
 		return rc;
 	}
 	if (bytes_transfered != 1) {
-		/* FIXME: some better error code? */
-		return ESTALL;
-	}
-
-	size_t size = tmp_buffer[0];
+		return ELIMIT;
+	}
+
+	const size_t size = tmp_buffer;
 	if (size == 0) {
-		/* FIXME: some better error code? */
-		return ESTALL;
+		return ELIMIT;
 	}
 
@@ -350,6 +338,5 @@
 	if (bytes_transfered != size) {
 		free(buffer);
-		/* FIXME: some better error code? */
-		return ESTALL;
+		return ELIMIT;
 	}
 
@@ -379,6 +366,5 @@
 	int rc = usb_request_get_descriptor(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
-	    USB_DESCTYPE_DEVICE, 0, 0,
-	    &descriptor_tmp, sizeof(descriptor_tmp),
+	    USB_DESCTYPE_DEVICE, 0, 0, &descriptor_tmp, sizeof(descriptor_tmp),
 	    &actually_transferred);
 
@@ -422,5 +408,5 @@
 	size_t actually_transferred = 0;
 	usb_standard_configuration_descriptor_t descriptor_tmp;
-	int rc = usb_request_get_descriptor(pipe,
+	const int rc = usb_request_get_descriptor(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
 	    USB_DESCTYPE_CONFIGURATION, index, 0,
@@ -547,6 +533,5 @@
     usb_request_type_t request_type, usb_request_recipient_t recipient,
     uint8_t descriptor_type, uint8_t descriptor_index,
-    uint16_t language,
-    void *buffer, size_t size)
+    uint16_t language, const void *buffer, size_t size)
 {
 	if (buffer == NULL) {
@@ -561,8 +546,6 @@
 
 	return usb_control_request_set(pipe,
-	    request_type, recipient,
-	    USB_DEVREQ_SET_DESCRIPTOR,
-	    wValue, language,
-	    buffer, size);
+	    request_type, recipient, USB_DEVREQ_SET_DESCRIPTOR,
+	    wValue, language, buffer, size);
 }
 
@@ -579,9 +562,7 @@
 	size_t actual_size;
 
-	int rc = usb_control_request_get(pipe,
+	const int rc = usb_control_request_get(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
-	    USB_DEVREQ_GET_CONFIGURATION,
-	    0, 0,
-	    &value, 1, &actual_size);
+	    USB_DEVREQ_GET_CONFIGURATION, 0, 0, &value, 1, &actual_size);
 
 	if (rc != EOK) {
@@ -608,5 +589,5 @@
     uint8_t configuration_value)
 {
-	uint16_t config_value
+	const uint16_t config_value
 	    = uint16_host2usb((uint16_t) configuration_value);
 
@@ -630,9 +611,9 @@
 	size_t actual_size;
 
-	int rc = usb_control_request_get(pipe,
+	const int rc = usb_control_request_get(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
 	    USB_DEVREQ_GET_INTERFACE,
 	    0, uint16_host2usb((uint16_t) interface_index),
-	    &value, 1, &actual_size);
+	    &value, sizeof(value), &actual_size);
 
 	if (rc != EOK) {
@@ -679,10 +660,5 @@
     l18_win_locales_t **languages_ptr, size_t *languages_count)
 {
-	int rc;
-
-	if (languages_ptr == NULL) {
-		return EBADMEM;
-	}
-	if (languages_count == NULL) {
+	if (languages_ptr == NULL || languages_count == NULL) {
 		return EBADMEM;
 	}
@@ -690,5 +666,5 @@
 	uint8_t *string_descriptor = NULL;
 	size_t string_descriptor_size = 0;
-	rc = usb_request_get_descriptor_alloc(pipe,
+	const int rc = usb_request_get_descriptor_alloc(pipe,
 	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
 	    USB_DESCTYPE_STRING, 0, 0,
@@ -711,7 +687,7 @@
 	}
 
-	size_t langs_count = string_descriptor_size / 2;
-	l18_win_locales_t *langs
-	    = malloc(sizeof(l18_win_locales_t) * langs_count);
+	const size_t langs_count = string_descriptor_size / 2;
+	l18_win_locales_t *langs =
+	    calloc(langs_count, sizeof(l18_win_locales_t));
 	if (langs == NULL) {
 		free(string_descriptor);
@@ -719,9 +695,9 @@
 	}
 
-	size_t i;
-	for (i = 0; i < langs_count; i++) {
+	for (size_t i = 0; i < langs_count; i++) {
 		/* Language code from the descriptor is in USB endianness. */
 		/* FIXME: is this really correct? */
-		uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8)
+		const uint16_t lang_code =
+		    (string_descriptor[2 + 2 * i + 1] << 8)
 		    + string_descriptor[2 + 2 * i];
 		langs[i] = uint16_usb2host(lang_code);
@@ -762,5 +738,5 @@
 	}
 	/* Language is actually two byte value. */
-	if (lang > 0xFFFF) {
+	if (lang > L18N_WIN_LOCALE_MAX) {
 		return ERANGE;
 	}
@@ -796,5 +772,5 @@
 	}
 
-	size_t string_char_count = string_size / 2;
+	const size_t string_char_count = string_size / 2;
 	string_chars = malloc(sizeof(wchar_t) * (string_char_count + 1));
 	if (string_chars == NULL) {
@@ -808,7 +784,6 @@
 	 * do not have them).
 	 */
-	size_t i;
-	for (i = 0; i < string_char_count; i++) {
-		uint16_t uni_char = (string[2 + 2 * i + 1] << 8)
+	for (size_t i = 0; i < string_char_count; i++) {
+		const uint16_t uni_char = (string[2 + 2 * i + 1] << 8)
 		    + string[2 + 2 * i];
 		string_chars[i] = uni_char;
@@ -828,10 +803,6 @@
 
 leave:
-	if (string != NULL) {
-		free(string);
-	}
-	if (string_chars != NULL) {
-		free(string_chars);
-	}
+	free(string);
+	free(string_chars);
 
 	return rc;
