Re: [PATCH] rtlwifi: use %*ph[C] to dump small buffers

2 messages, 2 authors, 2012-09-28 · open the first message on its own page

Re: [PATCH] rtlwifi: use %*ph[C] to dump small buffers

From: Larry Finger <hidden>
Date: 2012-09-28 16:41:19

On 09/28/2012 04:04 AM, David Laight wrote:
quoted
quoted
Index: wireless-testing-new/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
===================================================================
--- wireless-testing-new.orig/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
+++ wireless-testing-new/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
@@ -1964,8 +1965,9 @@ static void rtl92ce_update_hal_rate_mask

          RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
                   "ratr_bitmap :%x\n", ratr_bitmap);
-       *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
-                                    (ratr_index << 28);
+       for (i = 0; i < 3; i++)
+               rate_mask[i] = ratr_bitmap & (0xff << (i * 4));
rate_mask is u8, doesn't this needs (calc) >> (i * 8)
quoted
+       rate_mask[3] = (ratr_bitmap & 0x0f000000) | (ratr_index << 28);
Perhaps you meant:

		((ratr_bitmap & 0x0f000000) >> 24) | (ratr_index << 4)
I'd just do:
	rate_mask[0] = ratr_bitmap;
	rate_mask[1] = ratr_bitmap >>= 8;
	rate_mask[2] = ratr_bitmap >>= 8;
	rate_mask[3] = (ratr_bitmap >> 8) & 0xf | ratr_index << 4;
which is, of course, little endian.
Which means it is different from the original code on big-endian systems.
So changing this here ought to require a change when the data is read.
So this either fixes, or adds, an endianness bug.
Yes, the rate_mask array is little endian after this fragment is run, but the 
only use of the byte array is to write it to the device, and LE is what it needs 
no matter the platform. This change fixes an endianness bug.

As I tend to get confused when doing these things, I wrote a small test program 
and ran it on x86_64 and PPC-32 to confirm the result.

Thanks for teaching me about a = b >>= 8. I was not aware that C could do that.

Larry


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Re: [PATCH] rtlwifi: use %*ph[C] to dump small buffers

From: Joe Perches <joe@perches.com>
Date: 2012-09-28 17:24:22

On Fri, 2012-09-28 at 11:41 -0500, Larry Finger wrote:
On 09/28/2012 04:04 AM, David Laight wrote:
quoted
quoted
quoted
Index: wireless-testing-new/drivers/net/wireless/rtlwifi/rtl8192ce/hw.c
[]
quoted
quoted
quoted
-       *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
-                                    (ratr_index << 28);
+       for (i = 0; i < 3; i++)
+               rate_mask[i] = ratr_bitmap & (0xff << (i * 4));
[]
quoted
So this either fixes, or adds, an endianness bug.
Yes, the rate_mask array is little endian after this fragment is run, but the 
only use of the byte array is to write it to the device, and LE is what it needs 
no matter the platform. This change fixes an endianness bug.

As I tend to get confused when doing these things, I wrote a small test program 
and ran it on x86_64 and PPC-32 to confirm the result.

Thanks for teaching me about a = b >>= 8. I was not aware that C could do that.
The other thing that could be done is to use cpu_to_le32()
but David's method I think is superior for this use as there's
no absolute guarantee that rate_mask is aligned on a u32.

I'd add parens to make the precedence explicit.

	rate_mask[0] = ratr_bitmap;
	rate_mask[1] = (ratr_bitmap >>= 8);
	rate_mask[2] = (ratr_bitmap >>= 8);
	rate_mask[3] = ((ratr_bitmap >> 8) & 0xf) | (ratr_index << 4);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help