Re: [PATCH 6/6] staging: ks7010: Factor out repeated request initialization code.

2018-03-22 Thread Greg KH
On Mon, Mar 19, 2018 at 10:58:15PM -0700, Quytelda Kahja wrote:
> The code to initialize various different types of request structs
> is repeated multiple times.  Factor this code out into a macro
> called INIT_REQUEST.
> 
> Signed-off-by: Quytelda Kahja 
> ---
>  drivers/staging/ks7010/ks_hostif.c | 55 
> +++---
>  1 file changed, 16 insertions(+), 39 deletions(-)
> 
> diff --git a/drivers/staging/ks7010/ks_hostif.c 
> b/drivers/staging/ks7010/ks_hostif.c
> index 6fc2c3647908..3e5016aad029 100644
> --- a/drivers/staging/ks7010/ks_hostif.c
> +++ b/drivers/staging/ks7010/ks_hostif.c
> @@ -40,6 +40,17 @@ static inline unsigned int cnt_smeqbody(struct 
> ks_wlan_private *priv)
>  
>  #define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
>  
> +#define INIT_REQUEST(pp, priv)

Ick, please make it a function if you really want to do something like
this.

thanks,

greg k-h
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/6] staging: ks7010: Factor out repeated request initialization code.

2018-03-19 Thread Quytelda Kahja
The code to initialize various different types of request structs
is repeated multiple times.  Factor this code out into a macro
called INIT_REQUEST.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c | 55 +++---
 1 file changed, 16 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 6fc2c3647908..3e5016aad029 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -40,6 +40,17 @@ static inline unsigned int cnt_smeqbody(struct 
ks_wlan_private *priv)
 
 #define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
 
+#define INIT_REQUEST(pp, priv)
+{(
+   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
+   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
+   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
+   pp->rate_set.size = priv->reg.rate_set.size;
+   pp->capability = ks_wlan_cap(priv);
+   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
+  priv->reg.rate_set.size);
+)}
+
 static
 inline u8 get_BYTE(struct ks_wlan_private *priv)
 {
@@ -1412,14 +1423,7 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private 
*priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-   pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
-   pp->rate_set.size = priv->reg.rate_set.size;
-   pp->capability = ks_wlan_cap(priv);
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
 
/* send to device request */
ps_confirm_wait_inc(priv);
@@ -1437,16 +1441,9 @@ void hostif_infrastructure_set_request(struct 
ks_wlan_private *priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-   pp->capability = ks_wlan_cap(priv);
pp->beacon_lost_count =
cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
@@ -1486,16 +1483,9 @@ static void hostif_infrastructure_set2_request(struct 
ks_wlan_private *priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-   pp->capability = ks_wlan_cap(priv);
pp->beacon_lost_count =
cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
@@ -1538,16 +1528,9 @@ void hostif_adhoc_set_request(struct ks_wlan_private 
*priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-   pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-   pp->capability = ks_wlan_cap(priv);
 
/* send to device request */
ps_confirm_wait_inc(priv);
@@ -1565,15 +1548,9 @@ void hostif_adhoc_set2_request(struct ks_wlan_private 
*priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = 

[PATCH 6/6] staging: ks7010: Factor out repeated request initialization code.

2018-03-16 Thread Quytelda Kahja
The code to initialize various different types of request structs
is repeated multiple times.  Factor this code out into a macro
called INIT_REQUEST.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c | 55 +++---
 1 file changed, 16 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 6fc2c3647908..3e5016aad029 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -40,6 +40,17 @@ static inline unsigned int cnt_smeqbody(struct 
ks_wlan_private *priv)
 
 #define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
 
+#define INIT_REQUEST(pp, priv)
+{(
+   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
+   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
+   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
+   pp->rate_set.size = priv->reg.rate_set.size;
+   pp->capability = ks_wlan_cap(priv);
+   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
+  priv->reg.rate_set.size);
+)}
+
 static
 inline u8 get_BYTE(struct ks_wlan_private *priv)
 {
@@ -1412,14 +1423,7 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private 
*priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-   pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
-   pp->rate_set.size = priv->reg.rate_set.size;
-   pp->capability = ks_wlan_cap(priv);
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
 
/* send to device request */
ps_confirm_wait_inc(priv);
@@ -1437,16 +1441,9 @@ void hostif_infrastructure_set_request(struct 
ks_wlan_private *priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-   pp->capability = ks_wlan_cap(priv);
pp->beacon_lost_count =
cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
@@ -1486,16 +1483,9 @@ static void hostif_infrastructure_set2_request(struct 
ks_wlan_private *priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-   pp->capability = ks_wlan_cap(priv);
pp->beacon_lost_count =
cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count));
pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type));
@@ -1538,16 +1528,9 @@ void hostif_adhoc_set_request(struct ks_wlan_private 
*priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-   pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel));
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-   pp->capability = ks_wlan_cap(priv);
 
/* send to device request */
ps_confirm_wait_inc(priv);
@@ -1565,15 +1548,9 @@ void hostif_adhoc_set2_request(struct ks_wlan_private 
*priv)
if (!pp)
return;
 
-   pp->phy_type = cpu_to_le16((uint16_t)(priv->reg.phy_type));
-   pp->cts_mode = cpu_to_le16((uint16_t)(priv->reg.cts_mode));
-   pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type));
-   pp->rate_set.size = priv->reg.rate_set.size;
-   memcpy(>rate_set.body[0], >reg.rate_set.body[0],
-  priv->reg.rate_set.size);
+   INIT_REQUEST(pp, priv);
pp->ssid.size =