Skip to contentSkip to conversation

dvb-usb: unaligned

PATCH In review Al Viro 3 participants 4 messages May 21, 2008 Media (V4L/DVB)

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 1/1 dvb-usb: unaligned

---
 drivers/media/dvb/dvb-usb/dvb-usb-firmware.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +1 -1
index e1112e3..733a7ff 100644
@@ -127,7 +127,7 @@ int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx,
 	if ((*pos + hx->len + 4) >= fw->size)
 		return -EINVAL;
 
-	hx->addr = le16_to_cpu( *((u16 *) &b[1]) );
+	hx->addr = b[1] | (b[2] << 8);
 	hx->type = b[3];
 
 	if (hx->type == 0x04) {
Signature · 1 line
1.5.3.GIT
#1 lore raw
Quoted 10 lines · Al Viro
---
 drivers/media/dvb/dvb-usb/dvb-usb-firmware.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +0 -0
index e1112e3..733a7ff 100644

drivers/media/dvb/dvb-usb/dvb-usb-firmware.c int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, · line 130

Quoted 5 lines
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +1 -1
@@ -127,7 +127,7 @@ int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx,
 	if ((*pos + hx->len + 4) >= fw->size)
 		return -EINVAL;
 
-	hx->addr = le16_to_cpu( *((u16 *) &b[1]) );
+	hx->addr = b[1] | (b[2] << 8);

hx->addr = get_unaligned_le16(&b[1]);

Cheers,

Harvey

#2 lore raw
Quoted 14 lines · Harvey Harrison
Quoted 13 lines · Al Viro
---
 drivers/media/dvb/dvb-usb/dvb-usb-firmware.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +0 -0
index e1112e3..733a7ff 100644
@@ -127,7 +127,7 @@ int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx,
 	if ((*pos + hx->len + 4) >= fw->size)
 		return -EINVAL;
 
Quoted 4 lines

drivers/media/dvb/dvb-usb/dvb-usb-firmware.c int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, · line 130

Quoted 2 lines
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +1 -1
-	hx->addr = le16_to_cpu( *((u16 *) &b[1]) );
+	hx->addr = b[1] | (b[2] << 8);

???hx->addr = get_unaligned_le16(&b[1]);

Again, what's the benefit? Having a function doesn't mean that we need to use it religiously - if it doesn't make things more clear...

#3 lore raw
Quoted 15 lines · Al Viro
Quoted 14 lines · Harvey Harrison
Quoted 13 lines · Al Viro
---
 drivers/media/dvb/dvb-usb/dvb-usb-firmware.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +0 -0
index e1112e3..733a7ff 100644
@@ -127,7 +127,7 @@ int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx,
 	if ((*pos + hx->len + 4) >= fw->size)
 		return -EINVAL;
 
Quoted 7 lines
Quoted 4 lines

drivers/media/dvb/dvb-usb/dvb-usb-firmware.c int dvb_usb_get_hexline(const struct firmware *fw, struct hexline *hx, · line 130

Quoted 2 lines
drivers/media/dvb/dvb-usb/dvb-usb-firmware.c +1 -1
-	hx->addr = le16_to_cpu( *((u16 *) &b[1]) );
+	hx->addr = b[1] | (b[2] << 8);

???hx->addr = get_unaligned_le16(&b[1]);

Again, what's the benefit? Having a function doesn't mean that we need to use it religiously - if it doesn't make things more clear...

Just curious, is gcc smart enough to just turn this into a 2-byte load on x86 (little-endian with no particular alignment constraints). Otherwise it would have a better chance at doing this using the helper function.

You're right though, it is a small consideration.

Harvey