linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Clean up some macros
@ 2022-06-12  1:05 Nam Cao
  2022-06-12  1:05 ` [PATCH 1/2] staging: r8188eu: simplify " Nam Cao
  2022-06-12  1:05 ` [PATCH 2/2] staging: r8188eu: replace FIELD_OFFSET with offsetof Nam Cao
  0 siblings, 2 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-12  1:05 UTC (permalink / raw)
  To: gregkh; +Cc: phil, linux-staging, linux-kernel, Nam Cao

Replace some macros with standard ones. Remove some useless macros.

Nam Cao (2):
  staging: r8188eu: simplify some macros
  staging: r8188eu: replace FIELD_OFFSET with offsetof

 drivers/staging/r8188eu/core/rtw_mlme_ext.c   |  4 +--
 .../r8188eu/include/Hal8188ERateAdaptive.h    | 10 +++---
 drivers/staging/r8188eu/include/basic_types.h | 33 -------------------
 drivers/staging/r8188eu/os_dep/ioctl_linux.c  |  4 +--
 4 files changed, 9 insertions(+), 42 deletions(-)

-- 
2.25.1


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

* [PATCH 1/2] staging: r8188eu: simplify some macros
  2022-06-12  1:05 [PATCH 0/2] Clean up some macros Nam Cao
@ 2022-06-12  1:05 ` Nam Cao
  2022-06-12  4:56   ` Greg KH
  2022-06-12  1:05 ` [PATCH 2/2] staging: r8188eu: replace FIELD_OFFSET with offsetof Nam Cao
  1 sibling, 1 reply; 13+ messages in thread
From: Nam Cao @ 2022-06-12  1:05 UTC (permalink / raw)
  To: gregkh; +Cc: phil, linux-staging, linux-kernel, Nam Cao

There are some macros which are not really useful, but make the code
harder to read. Replace these with clearer codes.

Signed-off-by: Nam Cao <namcaov@gmail.com>
---
 .../r8188eu/include/Hal8188ERateAdaptive.h    | 10 +++---
 drivers/staging/r8188eu/include/basic_types.h | 31 -------------------
 2 files changed, 5 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
index 20d73ca781e8..79e4210c6b65 100644
--- a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
+++ b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
@@ -26,15 +26,15 @@
 #define GET_TX_REPORT_TYPE1_RERTY_0(__paddr)			\
 	le16_get_bits(*(__le16 *)__paddr, GENMASK(15, 0))
 #define GET_TX_REPORT_TYPE1_RERTY_1(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 2, 0, 8)
+	((u8 *)__paddr)[2]
 #define GET_TX_REPORT_TYPE1_RERTY_2(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 3, 0, 8)
+	((u8 *)__paddr)[3]
 #define GET_TX_REPORT_TYPE1_RERTY_3(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 4, 0, 8)
+	((u8 *)__paddr)[4]
 #define GET_TX_REPORT_TYPE1_RERTY_4(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 5, 0, 8)
+	((u8 *)__paddr)[5]
 #define GET_TX_REPORT_TYPE1_DROP_0(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 6, 0, 8)
+	((u8 *)__paddr)[6]
 /*  End rate adaptive define */
 
 int ODM_RAInfo_Init_all(struct odm_dm_struct *dm_odm);
diff --git a/drivers/staging/r8188eu/include/basic_types.h b/drivers/staging/r8188eu/include/basic_types.h
index ffb21170e898..c4b08fb82200 100644
--- a/drivers/staging/r8188eu/include/basic_types.h
+++ b/drivers/staging/r8188eu/include/basic_types.h
@@ -15,37 +15,6 @@ typedef void (*proc_t)(void *);
 /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
  * to check correctness */
 
-/*
- *	Call endian free function when
- *		1. Read/write packet content.
- *		2. Before write integer to IO.
- *		3. After read integer from IO.
-*/
-
-/* Convert little data endian to host ordering */
-#define EF1BYTE(_val)		\
-	((u8)(_val))
-
-/* Create a bit mask  */
-#define BIT_LEN_MASK_8(__bitlen) \
-	(0xFF >> (8 - (__bitlen)))
-
-/*Description:
- * Return 4-byte value in host byte ordering from
- * 4-byte pointer in little-endian system.
- */
-#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
-	(EF1BYTE(*((u8 *)(__pstart))))
-
-/*Description:
-Translate subfield (continuous bits in little-endian) of 4-byte
-value to host byte ordering.*/
-#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
-	( \
-		(LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
-		BIT_LEN_MASK_8(__bitlen) \
-	)
-
 #define	N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
 	(__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
 
-- 
2.25.1


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

* [PATCH 2/2] staging: r8188eu: replace FIELD_OFFSET with offsetof
  2022-06-12  1:05 [PATCH 0/2] Clean up some macros Nam Cao
  2022-06-12  1:05 ` [PATCH 1/2] staging: r8188eu: simplify " Nam Cao
@ 2022-06-12  1:05 ` Nam Cao
  1 sibling, 0 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-12  1:05 UTC (permalink / raw)
  To: gregkh; +Cc: phil, linux-staging, linux-kernel, Nam Cao

This driver defines FIELD_OFFSET which does the same as offsetof.
Replace this macro with offsetof.

Signed-off-by: Nam Cao <namcaov@gmail.com>
---
 drivers/staging/r8188eu/core/rtw_mlme_ext.c   | 4 ++--
 drivers/staging/r8188eu/include/basic_types.h | 2 --
 drivers/staging/r8188eu/os_dep/ioctl_linux.c  | 4 ++--
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_mlme_ext.c b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
index 87bf37f33606..2be166abe99c 100644
--- a/drivers/staging/r8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_mlme_ext.c
@@ -7072,7 +7072,7 @@ u8 createbss_hdl(struct adapter *padapter, u8 *pbuf)
 		/* clear CAM */
 		flush_all_cam_entry(padapter);
 
-		memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
+		memcpy(pnetwork, pbuf, offsetof(struct wlan_bssid_ex, IELength));
 		pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
 
 		if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
@@ -7129,7 +7129,7 @@ u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf)
 	pmlmeinfo->candidate_tid_bitmap = 0;
 	pmlmeinfo->bwmode_updated = false;
 
-	memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
+	memcpy(pnetwork, pbuf, offsetof(struct wlan_bssid_ex, IELength));
 	pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
 
 	if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
diff --git a/drivers/staging/r8188eu/include/basic_types.h b/drivers/staging/r8188eu/include/basic_types.h
index c4b08fb82200..0b71e2c6e41a 100644
--- a/drivers/staging/r8188eu/include/basic_types.h
+++ b/drivers/staging/r8188eu/include/basic_types.h
@@ -9,8 +9,6 @@
 
 typedef void (*proc_t)(void *);
 
-#define FIELD_OFFSET(s, field)	((ssize_t)&((s *)(0))->field)
-
 /* port from fw */
 /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
  * to check correctness */
diff --git a/drivers/staging/r8188eu/os_dep/ioctl_linux.c b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
index 1b09462ca908..2063ace8398f 100644
--- a/drivers/staging/r8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/r8188eu/os_dep/ioctl_linux.c
@@ -403,7 +403,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
 
 		if (wep_key_len > 0) {
 			wep_key_len = wep_key_len <= 5 ? 5 : 13;
-			wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
+			wep_total_len = wep_key_len + offsetof(struct ndis_802_11_wep, KeyMaterial);
 			pwep = kzalloc(wep_total_len, GFP_KERNEL);
 			if (!pwep)
 				goto exit;
@@ -1593,7 +1593,7 @@ static int rtw_wx_set_enc(struct net_device *dev,
 	if (erq->length > 0) {
 		wep.KeyLength = erq->length <= 5 ? 5 : 13;
 
-		wep.Length = wep.KeyLength + FIELD_OFFSET(struct ndis_802_11_wep, KeyMaterial);
+		wep.Length = wep.KeyLength + offsetof(struct ndis_802_11_wep, KeyMaterial);
 	} else {
 		wep.KeyLength = 0;
 
-- 
2.25.1


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

* Re: [PATCH 1/2] staging: r8188eu: simplify some macros
  2022-06-12  1:05 ` [PATCH 1/2] staging: r8188eu: simplify " Nam Cao
@ 2022-06-12  4:56   ` Greg KH
  2022-06-12  8:11     ` [PATCH v2 0/2] " Nam Cao
  0 siblings, 1 reply; 13+ messages in thread
From: Greg KH @ 2022-06-12  4:56 UTC (permalink / raw)
  To: Nam Cao; +Cc: phil, linux-staging, linux-kernel

On Sun, Jun 12, 2022 at 03:05:13AM +0200, Nam Cao wrote:
> There are some macros which are not really useful, but make the code
> harder to read. Replace these with clearer codes.
> 
> Signed-off-by: Nam Cao <namcaov@gmail.com>
> ---
>  .../r8188eu/include/Hal8188ERateAdaptive.h    | 10 +++---
>  drivers/staging/r8188eu/include/basic_types.h | 31 -------------------
>  2 files changed, 5 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> index 20d73ca781e8..79e4210c6b65 100644
> --- a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> +++ b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> @@ -26,15 +26,15 @@
>  #define GET_TX_REPORT_TYPE1_RERTY_0(__paddr)			\
>  	le16_get_bits(*(__le16 *)__paddr, GENMASK(15, 0))
>  #define GET_TX_REPORT_TYPE1_RERTY_1(__paddr)			\
> -	LE_BITS_TO_1BYTE(__paddr + 2, 0, 8)
> +	((u8 *)__paddr)[2]
>  #define GET_TX_REPORT_TYPE1_RERTY_2(__paddr)			\
> -	LE_BITS_TO_1BYTE(__paddr + 3, 0, 8)
> +	((u8 *)__paddr)[3]
>  #define GET_TX_REPORT_TYPE1_RERTY_3(__paddr)			\
> -	LE_BITS_TO_1BYTE(__paddr + 4, 0, 8)
> +	((u8 *)__paddr)[4]
>  #define GET_TX_REPORT_TYPE1_RERTY_4(__paddr)			\
> -	LE_BITS_TO_1BYTE(__paddr + 5, 0, 8)
> +	((u8 *)__paddr)[5]
>  #define GET_TX_REPORT_TYPE1_DROP_0(__paddr)			\
> -	LE_BITS_TO_1BYTE(__paddr + 6, 0, 8)
> +	((u8 *)__paddr)[6]
>  /*  End rate adaptive define */
>  
>  int ODM_RAInfo_Init_all(struct odm_dm_struct *dm_odm);
> diff --git a/drivers/staging/r8188eu/include/basic_types.h b/drivers/staging/r8188eu/include/basic_types.h
> index ffb21170e898..c4b08fb82200 100644
> --- a/drivers/staging/r8188eu/include/basic_types.h
> +++ b/drivers/staging/r8188eu/include/basic_types.h
> @@ -15,37 +15,6 @@ typedef void (*proc_t)(void *);
>  /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
>   * to check correctness */
>  
> -/*
> - *	Call endian free function when
> - *		1. Read/write packet content.
> - *		2. Before write integer to IO.
> - *		3. After read integer from IO.
> -*/
> -
> -/* Convert little data endian to host ordering */
> -#define EF1BYTE(_val)		\
> -	((u8)(_val))
> -
> -/* Create a bit mask  */
> -#define BIT_LEN_MASK_8(__bitlen) \
> -	(0xFF >> (8 - (__bitlen)))
> -
> -/*Description:
> - * Return 4-byte value in host byte ordering from
> - * 4-byte pointer in little-endian system.
> - */
> -#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
> -	(EF1BYTE(*((u8 *)(__pstart))))
> -
> -/*Description:
> -Translate subfield (continuous bits in little-endian) of 4-byte
> -value to host byte ordering.*/
> -#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
> -	( \
> -		(LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
> -		BIT_LEN_MASK_8(__bitlen) \
> -	)
> -
>  #define	N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
>  	(__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
>  
> -- 
> 2.25.1
> 
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch did many different things all at once, making it difficult
  to review.  All Linux kernel patches need to only do one thing at a
  time.  If you need to do multiple things (such as clean up all coding
  style issues in a file/driver), do it in a sequence of patches, each
  one doing only one thing.  This will make it easier to review the
  patches to ensure that they are correct, and to help alleviate any
  merge issues that larger patches can cause.

- You did not specify a description of why the patch is needed, or
  possibly, any description at all, in the email body.  Please read the
  section entitled "The canonical patch format" in the kernel file,
  Documentation/SubmittingPatches for what is needed in order to
  properly describe the change.

- You did not write a descriptive Subject: for the patch, allowing Greg,
  and everyone else, to know what this patch is all about.  Please read
  the section entitled "The canonical patch format" in the kernel file,
  Documentation/SubmittingPatches for what a proper Subject: line should
  look like.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

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

* [PATCH v2 0/2] staging: r8188eu: simplify some macros
  2022-06-12  4:56   ` Greg KH
@ 2022-06-12  8:11     ` Nam Cao
  2022-06-12  8:11       ` [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes Nam Cao
  2022-06-12  8:11       ` [PATCH v2 2/2] staging: r8188eu: remove unused macros Nam Cao
  0 siblings, 2 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-12  8:11 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, linux-staging, namcaov, phil

There are some bit manipulation macros in r8188eu, but are only
ever used for reading single bytes. Remove them.

V2:
  - Split into smaller commits so that it's easier to review

Nam Cao (2):
  staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes
  staging: r8188eu: remove unused macros

 .../r8188eu/include/Hal8188ERateAdaptive.h    | 10 +++---
 drivers/staging/r8188eu/include/basic_types.h | 31 -------------------
 2 files changed, 5 insertions(+), 36 deletions(-)

-- 
2.25.1


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

* [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes
  2022-06-12  8:11     ` [PATCH v2 0/2] " Nam Cao
@ 2022-06-12  8:11       ` Nam Cao
  2022-06-13 14:30         ` Dan Carpenter
  2022-06-12  8:11       ` [PATCH v2 2/2] staging: r8188eu: remove unused macros Nam Cao
  1 sibling, 1 reply; 13+ messages in thread
From: Nam Cao @ 2022-06-12  8:11 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, linux-staging, namcaov, phil

The statement LE_BITS_TO_1BYTE(__paddr + n, 0, 8) is not obvious on
what it is doing, while in truth it is simply reading one byte.
Replace these with clearer codes.

Signed-off-by: Nam Cao <namcaov@gmail.com>
---
 drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
index 20d73ca781e8..79e4210c6b65 100644
--- a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
+++ b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
@@ -26,15 +26,15 @@
 #define GET_TX_REPORT_TYPE1_RERTY_0(__paddr)			\
 	le16_get_bits(*(__le16 *)__paddr, GENMASK(15, 0))
 #define GET_TX_REPORT_TYPE1_RERTY_1(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 2, 0, 8)
+	((u8 *)__paddr)[2]
 #define GET_TX_REPORT_TYPE1_RERTY_2(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 3, 0, 8)
+	((u8 *)__paddr)[3]
 #define GET_TX_REPORT_TYPE1_RERTY_3(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 4, 0, 8)
+	((u8 *)__paddr)[4]
 #define GET_TX_REPORT_TYPE1_RERTY_4(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 5, 0, 8)
+	((u8 *)__paddr)[5]
 #define GET_TX_REPORT_TYPE1_DROP_0(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 6, 0, 8)
+	((u8 *)__paddr)[6]
 /*  End rate adaptive define */
 
 int ODM_RAInfo_Init_all(struct odm_dm_struct *dm_odm);
-- 
2.25.1


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

* [PATCH v2 2/2] staging: r8188eu: remove unused macros
  2022-06-12  8:11     ` [PATCH v2 0/2] " Nam Cao
  2022-06-12  8:11       ` [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes Nam Cao
@ 2022-06-12  8:11       ` Nam Cao
  1 sibling, 0 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-12  8:11 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, linux-staging, namcaov, phil

The macro LE_BITS_TO_1BYTE and related macros are not used anywhere.
Remove them.

Signed-off-by: Nam Cao <namcaov@gmail.com>
---
 drivers/staging/r8188eu/include/basic_types.h | 31 -------------------
 1 file changed, 31 deletions(-)

diff --git a/drivers/staging/r8188eu/include/basic_types.h b/drivers/staging/r8188eu/include/basic_types.h
index cfd15ac1d9c0..0b71e2c6e41a 100644
--- a/drivers/staging/r8188eu/include/basic_types.h
+++ b/drivers/staging/r8188eu/include/basic_types.h
@@ -13,37 +13,6 @@ typedef void (*proc_t)(void *);
 /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
  * to check correctness */
 
-/*
- *	Call endian free function when
- *		1. Read/write packet content.
- *		2. Before write integer to IO.
- *		3. After read integer from IO.
-*/
-
-/* Convert little data endian to host ordering */
-#define EF1BYTE(_val)		\
-	((u8)(_val))
-
-/* Create a bit mask  */
-#define BIT_LEN_MASK_8(__bitlen) \
-	(0xFF >> (8 - (__bitlen)))
-
-/*Description:
- * Return 4-byte value in host byte ordering from
- * 4-byte pointer in little-endian system.
- */
-#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
-	(EF1BYTE(*((u8 *)(__pstart))))
-
-/*Description:
-Translate subfield (continuous bits in little-endian) of 4-byte
-value to host byte ordering.*/
-#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
-	( \
-		(LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
-		BIT_LEN_MASK_8(__bitlen) \
-	)
-
 #define	N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
 	(__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
 
-- 
2.25.1


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

* Re: [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes
  2022-06-12  8:11       ` [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes Nam Cao
@ 2022-06-13 14:30         ` Dan Carpenter
  2022-06-14  9:34           ` Greg KH
  0 siblings, 1 reply; 13+ messages in thread
From: Dan Carpenter @ 2022-06-13 14:30 UTC (permalink / raw)
  To: Nam Cao; +Cc: gregkh, linux-kernel, linux-staging, phil

On Sun, Jun 12, 2022 at 10:11:43AM +0200, Nam Cao wrote:
> The statement LE_BITS_TO_1BYTE(__paddr + n, 0, 8) is not obvious on
> what it is doing, while in truth it is simply reading one byte.
> Replace these with clearer codes.
> 
> Signed-off-by: Nam Cao <namcaov@gmail.com>
> ---
>  drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> index 20d73ca781e8..79e4210c6b65 100644
> --- a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> +++ b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> @@ -26,15 +26,15 @@
>  #define GET_TX_REPORT_TYPE1_RERTY_0(__paddr)			\
>  	le16_get_bits(*(__le16 *)__paddr, GENMASK(15, 0))
>  #define GET_TX_REPORT_TYPE1_RERTY_1(__paddr)			\
> -	LE_BITS_TO_1BYTE(__paddr + 2, 0, 8)
> +	((u8 *)__paddr)[2]

Instead of doing this, I would prefer to just get rid of
GET_TX_REPORT_TYPE1_RERTY_[1234].

regards,
dan carpenter


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

* Re: [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes
  2022-06-13 14:30         ` Dan Carpenter
@ 2022-06-14  9:34           ` Greg KH
  2022-06-14 15:58             ` [PATCH v3 0/2] get rid of confusing macros Nam Cao
  0 siblings, 1 reply; 13+ messages in thread
From: Greg KH @ 2022-06-14  9:34 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Nam Cao, linux-kernel, linux-staging, phil

On Mon, Jun 13, 2022 at 05:30:24PM +0300, Dan Carpenter wrote:
> On Sun, Jun 12, 2022 at 10:11:43AM +0200, Nam Cao wrote:
> > The statement LE_BITS_TO_1BYTE(__paddr + n, 0, 8) is not obvious on
> > what it is doing, while in truth it is simply reading one byte.
> > Replace these with clearer codes.
> > 
> > Signed-off-by: Nam Cao <namcaov@gmail.com>
> > ---
> >  drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> > index 20d73ca781e8..79e4210c6b65 100644
> > --- a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> > +++ b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
> > @@ -26,15 +26,15 @@
> >  #define GET_TX_REPORT_TYPE1_RERTY_0(__paddr)			\
> >  	le16_get_bits(*(__le16 *)__paddr, GENMASK(15, 0))
> >  #define GET_TX_REPORT_TYPE1_RERTY_1(__paddr)			\
> > -	LE_BITS_TO_1BYTE(__paddr + 2, 0, 8)
> > +	((u8 *)__paddr)[2]
> 
> Instead of doing this, I would prefer to just get rid of
> GET_TX_REPORT_TYPE1_RERTY_[1234].

Yes, I agree, that's a mess and almost impossible to understand...

thanks,

greg k-h

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

* [PATCH v3 0/2] get rid of confusing macros
  2022-06-14  9:34           ` Greg KH
@ 2022-06-14 15:58             ` Nam Cao
  2022-06-14 15:58               ` [PATCH v3 1/2] staging: r8188eu: replace " Nam Cao
                                 ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-14 15:58 UTC (permalink / raw)
  To: gregkh
  Cc: dan.carpenter, linux-kernel, linux-staging, namcaov, phil,
	Larry.Finger, paskripkin

Replace some confusing macros with more explicit codes.

V3:
  - Get rid of GET_TX_REPORT_TYPE1_RERTY_0 and similar
V2:
  - Split into smaller commits so that it's easier to review

Nam Cao (2):
  staging: r8188eu: replace confusing macros
  staging: r8188eu: remove unused macros

 .../r8188eu/hal/Hal8188ERateAdaptive.c        | 12 +++----
 .../r8188eu/include/Hal8188ERateAdaptive.h    | 13 --------
 drivers/staging/r8188eu/include/basic_types.h | 31 -------------------
 3 files changed, 6 insertions(+), 50 deletions(-)

-- 
2.25.1


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

* [PATCH v3 1/2] staging: r8188eu: replace confusing macros
  2022-06-14 15:58             ` [PATCH v3 0/2] get rid of confusing macros Nam Cao
@ 2022-06-14 15:58               ` Nam Cao
  2022-06-14 15:58               ` [PATCH v3 2/2] staging: r8188eu: remove unused macros Nam Cao
  2022-06-15  8:29               ` [PATCH v3 0/2] get rid of confusing macros Dan Carpenter
  2 siblings, 0 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-14 15:58 UTC (permalink / raw)
  To: gregkh
  Cc: dan.carpenter, linux-kernel, linux-staging, namcaov, phil,
	Larry.Finger, paskripkin

The macro GET_TX_REPORT_TYPE1_RERTY_0 and similar macros are not
obvious on what they are doing. Replace them with clearer codes.

Signed-off-by: Nam Cao <namcaov@gmail.com>
---
 drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.c  | 12 ++++++------
 .../staging/r8188eu/include/Hal8188ERateAdaptive.h  | 13 -------------
 2 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.c b/drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.c
index 3cefdf90d6e0..1e04de3a6622 100644
--- a/drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.c
+++ b/drivers/staging/r8188eu/hal/Hal8188ERateAdaptive.c
@@ -614,12 +614,12 @@ void ODM_RA_TxRPT2Handle_8188E(struct odm_dm_struct *dm_odm, u8 *TxRPT_Buf, u16
 
 		pRAInfo = &dm_odm->RAInfo[MacId];
 		if (valid) {
-			pRAInfo->RTY[0] = (u16)GET_TX_REPORT_TYPE1_RERTY_0(pBuffer);
-			pRAInfo->RTY[1] = (u16)GET_TX_REPORT_TYPE1_RERTY_1(pBuffer);
-			pRAInfo->RTY[2] = (u16)GET_TX_REPORT_TYPE1_RERTY_2((u8 *)pBuffer);
-			pRAInfo->RTY[3] = (u16)GET_TX_REPORT_TYPE1_RERTY_3(pBuffer);
-			pRAInfo->RTY[4] = (u16)GET_TX_REPORT_TYPE1_RERTY_4(pBuffer);
-			pRAInfo->DROP =   (u16)GET_TX_REPORT_TYPE1_DROP_0(pBuffer);
+			pRAInfo->RTY[0] = le16_to_cpup((__le16 *)pBuffer);
+			pRAInfo->RTY[1] = pBuffer[2];
+			pRAInfo->RTY[2] = pBuffer[3];
+			pRAInfo->RTY[3] = pBuffer[4];
+			pRAInfo->RTY[4] = pBuffer[5];
+			pRAInfo->DROP = pBuffer[6];
 			pRAInfo->TOTAL = pRAInfo->RTY[0] + pRAInfo->RTY[1] +
 					 pRAInfo->RTY[2] + pRAInfo->RTY[3] +
 					 pRAInfo->RTY[4] + pRAInfo->DROP;
diff --git a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
index 20d73ca781e8..c571ad9478ea 100644
--- a/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
+++ b/drivers/staging/r8188eu/include/Hal8188ERateAdaptive.h
@@ -22,19 +22,6 @@
 	le32_to_cpu((*(__le32 *)(__rxstatusdesc + 16))
 #define GET_TX_RPT2_DESC_MACID_VALID_2_88E(__rxstatusdesc)	\
 	le32_to_cpu((*(__le32 *)(__rxstatusdesc + 20))
-
-#define GET_TX_REPORT_TYPE1_RERTY_0(__paddr)			\
-	le16_get_bits(*(__le16 *)__paddr, GENMASK(15, 0))
-#define GET_TX_REPORT_TYPE1_RERTY_1(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 2, 0, 8)
-#define GET_TX_REPORT_TYPE1_RERTY_2(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 3, 0, 8)
-#define GET_TX_REPORT_TYPE1_RERTY_3(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 4, 0, 8)
-#define GET_TX_REPORT_TYPE1_RERTY_4(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 5, 0, 8)
-#define GET_TX_REPORT_TYPE1_DROP_0(__paddr)			\
-	LE_BITS_TO_1BYTE(__paddr + 6, 0, 8)
 /*  End rate adaptive define */
 
 int ODM_RAInfo_Init_all(struct odm_dm_struct *dm_odm);
-- 
2.25.1


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

* [PATCH v3 2/2] staging: r8188eu: remove unused macros
  2022-06-14 15:58             ` [PATCH v3 0/2] get rid of confusing macros Nam Cao
  2022-06-14 15:58               ` [PATCH v3 1/2] staging: r8188eu: replace " Nam Cao
@ 2022-06-14 15:58               ` Nam Cao
  2022-06-15  8:29               ` [PATCH v3 0/2] get rid of confusing macros Dan Carpenter
  2 siblings, 0 replies; 13+ messages in thread
From: Nam Cao @ 2022-06-14 15:58 UTC (permalink / raw)
  To: gregkh
  Cc: dan.carpenter, linux-kernel, linux-staging, namcaov, phil,
	Larry.Finger, paskripkin

Remove LE_BITS_TO_1BYTE and relevant macros because they are not used
anywhere.

Signed-off-by: Nam Cao <namcaov@gmail.com>
---
 drivers/staging/r8188eu/include/basic_types.h | 31 -------------------
 1 file changed, 31 deletions(-)

diff --git a/drivers/staging/r8188eu/include/basic_types.h b/drivers/staging/r8188eu/include/basic_types.h
index cfd15ac1d9c0..0b71e2c6e41a 100644
--- a/drivers/staging/r8188eu/include/basic_types.h
+++ b/drivers/staging/r8188eu/include/basic_types.h
@@ -13,37 +13,6 @@ typedef void (*proc_t)(void *);
 /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
  * to check correctness */
 
-/*
- *	Call endian free function when
- *		1. Read/write packet content.
- *		2. Before write integer to IO.
- *		3. After read integer from IO.
-*/
-
-/* Convert little data endian to host ordering */
-#define EF1BYTE(_val)		\
-	((u8)(_val))
-
-/* Create a bit mask  */
-#define BIT_LEN_MASK_8(__bitlen) \
-	(0xFF >> (8 - (__bitlen)))
-
-/*Description:
- * Return 4-byte value in host byte ordering from
- * 4-byte pointer in little-endian system.
- */
-#define LE_P1BYTE_TO_HOST_1BYTE(__pstart) \
-	(EF1BYTE(*((u8 *)(__pstart))))
-
-/*Description:
-Translate subfield (continuous bits in little-endian) of 4-byte
-value to host byte ordering.*/
-#define LE_BITS_TO_1BYTE(__pstart, __bitoffset, __bitlen) \
-	( \
-		(LE_P1BYTE_TO_HOST_1BYTE(__pstart) >> (__bitoffset)) & \
-		BIT_LEN_MASK_8(__bitlen) \
-	)
-
 #define	N_BYTE_ALIGMENT(__value, __aligment) ((__aligment == 1) ? \
 	(__value) : (((__value + __aligment - 1) / __aligment) * __aligment))
 
-- 
2.25.1


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

* Re: [PATCH v3 0/2] get rid of confusing macros
  2022-06-14 15:58             ` [PATCH v3 0/2] get rid of confusing macros Nam Cao
  2022-06-14 15:58               ` [PATCH v3 1/2] staging: r8188eu: replace " Nam Cao
  2022-06-14 15:58               ` [PATCH v3 2/2] staging: r8188eu: remove unused macros Nam Cao
@ 2022-06-15  8:29               ` Dan Carpenter
  2 siblings, 0 replies; 13+ messages in thread
From: Dan Carpenter @ 2022-06-15  8:29 UTC (permalink / raw)
  To: Nam Cao
  Cc: gregkh, linux-kernel, linux-staging, phil, Larry.Finger, paskripkin

On Tue, Jun 14, 2022 at 05:58:43PM +0200, Nam Cao wrote:
> Replace some confusing macros with more explicit codes.
> 
> V3:
>   - Get rid of GET_TX_REPORT_TYPE1_RERTY_0 and similar
> V2:
>   - Split into smaller commits so that it's easier to review
> 
> Nam Cao (2):
>   staging: r8188eu: replace confusing macros
>   staging: r8188eu: remove unused macros

So much better!  Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter


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

end of thread, other threads:[~2022-06-15  8:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-12  1:05 [PATCH 0/2] Clean up some macros Nam Cao
2022-06-12  1:05 ` [PATCH 1/2] staging: r8188eu: simplify " Nam Cao
2022-06-12  4:56   ` Greg KH
2022-06-12  8:11     ` [PATCH v2 0/2] " Nam Cao
2022-06-12  8:11       ` [PATCH v2 1/2] staging: r8188eu: replace LE_BITS_TO_1BYTE with clearer codes Nam Cao
2022-06-13 14:30         ` Dan Carpenter
2022-06-14  9:34           ` Greg KH
2022-06-14 15:58             ` [PATCH v3 0/2] get rid of confusing macros Nam Cao
2022-06-14 15:58               ` [PATCH v3 1/2] staging: r8188eu: replace " Nam Cao
2022-06-14 15:58               ` [PATCH v3 2/2] staging: r8188eu: remove unused macros Nam Cao
2022-06-15  8:29               ` [PATCH v3 0/2] get rid of confusing macros Dan Carpenter
2022-06-12  8:11       ` [PATCH v2 2/2] staging: r8188eu: remove unused macros Nam Cao
2022-06-12  1:05 ` [PATCH 2/2] staging: r8188eu: replace FIELD_OFFSET with offsetof Nam Cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).