* [PATCH v3] Simplify eir_parse_uuid* functions
@ 2011-10-20 12:53 Frédéric Danis
2011-10-20 20:27 ` Anderson Lizardo
2011-10-21 8:15 ` Johan Hedberg
0 siblings, 2 replies; 3+ messages in thread
From: Frédéric Danis @ 2011-10-20 12:53 UTC (permalink / raw)
To: linux-bluetooth
---
src/eir.c | 37 +++++++++++++++----------------------
1 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index f188031..88a4807 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -59,43 +59,33 @@ void eir_data_free(struct eir_data *eir)
eir->name = NULL;
}
-static void eir_parse_uuid16(struct eir_data *eir, uint8_t *data, uint8_t len)
+static void eir_parse_uuid16(struct eir_data *eir, void *data, uint8_t len)
{
- uint8_t *uuid_ptr = data;
+ uint16_t *uuid16 = data;
uuid_t service;
char *uuid_str;
unsigned int i;
- uint16_t val16;
service.type = SDP_UUID16;
- for (i = 0; i < len / 2; i++) {
- val16 = uuid_ptr[1];
- val16 = (val16 << 8) + uuid_ptr[0];
- service.value.uuid16 = val16;
+ for (i = 0; i < len / 2; i++, uuid16++) {
+ service.value.uuid16 = btohs(bt_get_unaligned(uuid16));
uuid_str = bt_uuid2string(&service);
eir->services = g_slist_append(eir->services, uuid_str);
- uuid_ptr += 2;
}
}
-static void eir_parse_uuid32(struct eir_data *eir, uint8_t *data, uint8_t len)
+static void eir_parse_uuid32(struct eir_data *eir, void *data, uint8_t len)
{
- uint8_t *uuid_ptr = data;
+ uint32_t *uuid32 = data;
uuid_t service;
char *uuid_str;
unsigned int i;
- uint32_t val32;
- int k;
service.type = SDP_UUID32;
- for (i = 0; i < len / 4; i++) {
- val32 = uuid_ptr[3];
- for (k = 2; k >= 0; k--)
- val32 = (val32 << 8) + uuid_ptr[k];
- service.value.uuid32 = val32;
+ for (i = 0; i < len / 4; i++, uuid32++) {
+ service.value.uuid32 = btohl(bt_get_unaligned(uuid32));
uuid_str = bt_uuid2string(&service);
eir->services = g_slist_append(eir->services, uuid_str);
- uuid_ptr += 4;
}
}
@@ -164,12 +154,15 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data)
case EIR_NAME_SHORT:
case EIR_NAME_COMPLETE:
- if (g_utf8_validate((char *) &eir_data[2],
+ if (!g_utf8_validate((char *) &eir_data[2],
field_len - 1, NULL))
- eir->name = g_strndup((char *) &eir_data[2],
+ break;
+
+ if (eir->name)
+ g_free(eir->name);
+
+ eir->name = g_strndup((char *) &eir_data[2],
field_len - 1);
- else
- eir->name = g_strdup("");
eir->name_complete = eir_data[1] == EIR_NAME_COMPLETE;
break;
}
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Simplify eir_parse_uuid* functions
2011-10-20 12:53 [PATCH v3] Simplify eir_parse_uuid* functions Frédéric Danis
@ 2011-10-20 20:27 ` Anderson Lizardo
2011-10-21 8:15 ` Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Anderson Lizardo @ 2011-10-20 20:27 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
Hi Frédéric,
2011/10/20 Frédéric Danis <frederic.danis@linux.intel.com>:
> + if (eir->name)
> + g_free(eir->name);
You don't need to check for NULL before passing a pointer to g_free().
IMHO just "g_free(eir->name)" is clearer.
> +
> + eir->name = g_strndup((char *) &eir_data[2],
> field_len - 1);
> - else
> - eir->name = g_strdup("");
> eir->name_complete = eir_data[1] == EIR_NAME_COMPLETE;
> break;
Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] Simplify eir_parse_uuid* functions
2011-10-20 12:53 [PATCH v3] Simplify eir_parse_uuid* functions Frédéric Danis
2011-10-20 20:27 ` Anderson Lizardo
@ 2011-10-21 8:15 ` Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2011-10-21 8:15 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
Hi Frédéric,
On Thu, Oct 20, 2011, Frédéric Danis wrote:
> ---
> src/eir.c | 37 +++++++++++++++----------------------
> 1 files changed, 15 insertions(+), 22 deletions(-)
I made the g_free fix suggestion from Lizardo and applied the patch.
Thanks.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-21 8:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-20 12:53 [PATCH v3] Simplify eir_parse_uuid* functions Frédéric Danis
2011-10-20 20:27 ` Anderson Lizardo
2011-10-21 8:15 ` Johan Hedberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.