All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH 0/2] Staging: Use put_unaligned_le16
@ 2015-02-20  8:48 Vaishali Thakkar
  2015-02-20  8:48 ` [RESEND PATCH v3 1/2] Staging: rtl8188eu: " Vaishali Thakkar
  2015-02-20  8:48 ` [RESEND PATCH v2 2/2] Staging: rtl8723au: " Vaishali Thakkar
  0 siblings, 2 replies; 5+ messages in thread
From: Vaishali Thakkar @ 2015-02-20  8:48 UTC (permalink / raw)
  To: outreachy-kernel

This patch series introduces the use of function 
put_unaligned_le16 as using byte ordering functions 
and then memcpy() is risky and prone to hide errors 
which are hard to track down. 

This change is done using Coccinelle.

Vaishali Thakkar (2):
  Staging: rtl8188eu: Use put_unaligned_le16
  Staging: rtl8723au: Use put_unaligned_le16

 drivers/staging/rtl8188eu/core/rtw_ap.c | 8 +++-----
 drivers/staging/rtl8723au/core/rtw_ap.c | 8 +++-----
 2 files changed, 6 insertions(+), 10 deletions(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RESEND PATCH v3 1/2] Staging: rtl8188eu: Use put_unaligned_le16
  2015-02-20  8:48 [RESEND PATCH 0/2] Staging: Use put_unaligned_le16 Vaishali Thakkar
@ 2015-02-20  8:48 ` Vaishali Thakkar
  2015-02-20  9:37   ` [Outreachy kernel] " Arnd Bergmann
  2015-02-20  8:48 ` [RESEND PATCH v2 2/2] Staging: rtl8723au: " Vaishali Thakkar
  1 sibling, 1 reply; 5+ messages in thread
From: Vaishali Thakkar @ 2015-02-20  8:48 UTC (permalink / raw)
  To: outreachy-kernel

Using byte ordering functions and then memcpy() is risky and
prone to hide errors which are hard to track down. So, this
patch introduces the use of function put_unaligned_le16 which
makes the code clear. Here, use of variable tim_bitmap_le
and variable itself is removed. Also, to be compatible with the
changes header file is added too.

Coccinelle is used to do this change and semantic patch used for
this is as follows:

@a@
typedef __le16;
__le16 e16;
identifier tmp;
expression ptr;
expression y,e;
type T;
@@

- tmp = cpu_to_le16(y);

<+... when != tmp
(
- memcpy(ptr, (T)&tmp, \(2\|sizeof(__le16)\|sizeof(e16)\));
+ put_unaligned_le16(y,ptr);
|
- memcpy(ptr, (T)&tmp, ...);
+ put_unaligned_le16(y,ptr);
)
...+>
? tmp = e

@@ type T; identifier a.tmp; @@

- T tmp;
...when != tmp

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
Changes since v2:
	-Edit commit log
	-Merge this patch in a patch-series

Changes since v1:
	-Remove use of variable tim_bitmap_le
	-Remove variable tim_bitmap_le
	-Add header file to be compatible with the changes
	-Edit commit log

 drivers/staging/rtl8188eu/core/rtw_ap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index da19145..e65ee6e 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -23,6 +23,7 @@
 #include <drv_types.h>
 #include <wifi.h>
 #include <ieee80211.h>
+#include <asm/unaligned.h>
 
 #ifdef CONFIG_88EU_AP_MODE
 
@@ -78,11 +79,8 @@ static void update_BCNTIM(struct adapter *padapter)
 	if (true) {
 		u8 *p, *dst_ie, *premainder_ie = NULL;
 		u8 *pbackup_remainder_ie = NULL;
-		__le16 tim_bitmap_le;
 		uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
 
-		tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
-
 		p = rtw_get_ie(pie + _FIXED_IE_LENGTH_, _TIM_IE_, &tim_ielen, pnetwork_mlmeext->IELength - _FIXED_IE_LENGTH_);
 		if (p != NULL && tim_ielen > 0) {
 			tim_ielen += 2;
@@ -137,9 +135,9 @@ static void update_BCNTIM(struct adapter *padapter)
 			*dst_ie++ = 0;
 
 		if (tim_ielen == 4) {
-			*dst_ie++ = *(u8 *)&tim_bitmap_le;
+			*dst_ie++ = pstapriv->tim_bitmap & 0xff;
 		} else if (tim_ielen == 5) {
-			memcpy(dst_ie, &tim_bitmap_le, 2);
+			put_unaligned_le16(pstapriv->tim_bitmap, dst_ie);
 			dst_ie += 2;
 		}
 
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RESEND PATCH v2 2/2] Staging: rtl8723au: Use put_unaligned_le16
  2015-02-20  8:48 [RESEND PATCH 0/2] Staging: Use put_unaligned_le16 Vaishali Thakkar
  2015-02-20  8:48 ` [RESEND PATCH v3 1/2] Staging: rtl8188eu: " Vaishali Thakkar
@ 2015-02-20  8:48 ` Vaishali Thakkar
  2015-02-20  9:36   ` [Outreachy kernel] " Arnd Bergmann
  1 sibling, 1 reply; 5+ messages in thread
From: Vaishali Thakkar @ 2015-02-20  8:48 UTC (permalink / raw)
  To: outreachy-kernel

Using byte ordering functions and then memcpy() is risky and
prone to hide errors which are hard to track down. So, this
patch introduces the use of function put_unaligned_le16 which
makes the code clear. Here, use of variable tim_bitmap_le
and variable itself is removed. Also, to be compatible with the
changes header file is added too.

Coccinelle is used to do this change and semantic patch used for
this is as follows:

@a@
typedef __le16;
__le16 e16;
identifier tmp;
expression ptr;
expression y,e;
type T;
@@

- tmp = cpu_to_le16(y);

<+... when != tmp
(
- memcpy(ptr, (T)&tmp, \(2\|sizeof(__le16)\|sizeof(e16)\));
+ put_unaligned_le16(y,ptr);
|
- memcpy(ptr, (T)&tmp, ...);
+ put_unaligned_le16(y,ptr);
)
...+>
? tmp = e

@@ type T; identifier a.tmp; @@

- T tmp;
...when != tmp

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
Changes since v1:
	-Edit commit log
	-Merge this patch in a patch series

 drivers/staging/rtl8723au/core/rtw_ap.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_ap.c b/drivers/staging/rtl8723au/core/rtw_ap.c
index c6327c0..7fa4352 100644
--- a/drivers/staging/rtl8723au/core/rtw_ap.c
+++ b/drivers/staging/rtl8723au/core/rtw_ap.c
@@ -20,6 +20,7 @@
 #include <wifi.h>
 #include <rtl8723a_cmd.h>
 #include <rtl8723a_hal.h>
+#include <asm/unaligned.h>
 
 extern unsigned char WMM_OUI23A[];
 extern unsigned char WPS_OUI23A[];
@@ -72,11 +73,8 @@ static void update_BCNTIM(struct rtw_adapter *padapter)
 	struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
 	unsigned char *pie = pnetwork_mlmeext->IEs;
 	u8 *p, *dst_ie, *premainder_ie = NULL, *pbackup_remainder_ie = NULL;
-	__le16 tim_bitmap_le;
 	uint offset, tmp_len, tim_ielen, tim_ie_offset, remainder_ielen;
 
-	tim_bitmap_le = cpu_to_le16(pstapriv->tim_bitmap);
-
 	p = rtw_get_ie23a(pie, WLAN_EID_TIM, &tim_ielen,
 			  pnetwork_mlmeext->IELength);
 	if (p != NULL && tim_ielen > 0) {
@@ -143,9 +141,9 @@ static void update_BCNTIM(struct rtw_adapter *padapter)
 		*dst_ie++ = 0;
 
 	if (tim_ielen == 4) {
-		*dst_ie++ = *(u8 *)&tim_bitmap_le;
+		*dst_ie++ = pstapriv->tim_bitmap & 0xff;
 	} else if (tim_ielen == 5) {
-		memcpy(dst_ie, &tim_bitmap_le, 2);
+		put_unaligned_le16(pstapriv->tim_bitmap, dst_ie);
 		dst_ie += 2;
 	}
 
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Outreachy kernel] [RESEND PATCH v2 2/2] Staging: rtl8723au: Use put_unaligned_le16
  2015-02-20  8:48 ` [RESEND PATCH v2 2/2] Staging: rtl8723au: " Vaishali Thakkar
@ 2015-02-20  9:36   ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2015-02-20  9:36 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Vaishali Thakkar

On Friday 20 February 2015 14:18:45 Vaishali Thakkar wrote:
> Using byte ordering functions and then memcpy() is risky and
> prone to hide errors which are hard to track down. So, this
> patch introduces the use of function put_unaligned_le16 which
> makes the code clear. Here, use of variable tim_bitmap_le
> and variable itself is removed. Also, to be compatible with the
> changes header file is added too.
> 
> Coccinelle is used to do this change and semantic patch used for
> this is as follows:
> 
> @a@
> typedef __le16;
> __le16 e16;
> identifier tmp;
> expression ptr;
> expression y,e;
> type T;
> @@
> 
> - tmp = cpu_to_le16(y);
> 
> <+... when != tmp
> (
> - memcpy(ptr, (T)&tmp, \(2\|sizeof(__le16)\|sizeof(e16)\));
> + put_unaligned_le16(y,ptr);
> |
> - memcpy(ptr, (T)&tmp, ...);
> + put_unaligned_le16(y,ptr);
> )
> ...+>
> ? tmp = e
> 
> @@ type T; identifier a.tmp; @@
> 
> - T tmp;
> ...when != tmp
> 
> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> 

Reviewed-by: Arnd Bergmann <arnd@arndb.de>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Outreachy kernel] [RESEND PATCH v3 1/2] Staging: rtl8188eu: Use put_unaligned_le16
  2015-02-20  8:48 ` [RESEND PATCH v3 1/2] Staging: rtl8188eu: " Vaishali Thakkar
@ 2015-02-20  9:37   ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2015-02-20  9:37 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Vaishali Thakkar

On Friday 20 February 2015 14:18:37 Vaishali Thakkar wrote:
> Using byte ordering functions and then memcpy() is risky and
> prone to hide errors which are hard to track down. So, this
> patch introduces the use of function put_unaligned_le16 which
> makes the code clear. Here, use of variable tim_bitmap_le
> and variable itself is removed. Also, to be compatible with the
> changes header file is added too.
> 
> Coccinelle is used to do this change and semantic patch used for
> this is as follows:
> 
> @a@
> typedef __le16;
> __le16 e16;
> identifier tmp;
> expression ptr;
> expression y,e;
> type T;
> @@
> 
> - tmp = cpu_to_le16(y);
> 
> <+... when != tmp
> (
> - memcpy(ptr, (T)&tmp, \(2\|sizeof(__le16)\|sizeof(e16)\));
> + put_unaligned_le16(y,ptr);
> |
> - memcpy(ptr, (T)&tmp, ...);
> + put_unaligned_le16(y,ptr);
> )
> ...+>
> ? tmp = e
> 
> @@ type T; identifier a.tmp; @@
> 
> - T tmp;
> ...when != tmp
> 
> Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
> 

Reviewed-by: Arnd Bergmann <arnd@arndb.de>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-20  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-20  8:48 [RESEND PATCH 0/2] Staging: Use put_unaligned_le16 Vaishali Thakkar
2015-02-20  8:48 ` [RESEND PATCH v3 1/2] Staging: rtl8188eu: " Vaishali Thakkar
2015-02-20  9:37   ` [Outreachy kernel] " Arnd Bergmann
2015-02-20  8:48 ` [RESEND PATCH v2 2/2] Staging: rtl8723au: " Vaishali Thakkar
2015-02-20  9:36   ` [Outreachy kernel] " Arnd Bergmann

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.