Re: [PATCH 3/5] staging: ks7010: Factor out repeated code into function 'ks_wlan_cap()'.

2018-02-28 Thread Tobin C. Harding
On Wed, Feb 28, 2018 at 09:19:09PM -0800, Quytelda Kahja wrote:
> The code that generates a WLAN capability mask is repeated in five
> functions.  This change refactors that code into a new function, which is
> called now in each of those functions.

Perhaps in future something like:

Code to generate the WLAN capability mask is duplicated five times

Add helper function to generate WLAN capability mask, refactor code to
use newly defined function.


See Documentation/process/submitting-patches.rst section 2 for more info.

2) Describe your changes

Hope this helps,
Tobin.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/5] staging: ks7010: Use constants from ieee80211_eid instead of literal ints.

2018-02-28 Thread Tobin C. Harding
On Wed, Feb 28, 2018 at 09:19:07PM -0800, Quytelda Kahja wrote:
...

I would normally respond to the cover letter but here goes.

Reviewed-by: Tobin C. Harding 

thanks,
Tobin.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/5] staging: ks7010: Use constants from ieee80211_eid instead of literal ints.

2018-02-28 Thread Tobin C. Harding
On Wed, Feb 28, 2018 at 09:19:07PM -0800, Quytelda Kahja wrote:
> The case statement in get_ap_information() should not use literal integers
> to parse information element IDs when these values are provided by name
> in 'enum ieee80211_eid' in the header 'linux/ieee80211.h'.

Nice.  Magic number removal, I like it.

> Signed-off-by: Quytelda Kahja 
> ---
>  drivers/staging/ks7010/ks_hostif.c | 31 +++
>  drivers/staging/ks7010/ks_hostif.h |  1 +
>  2 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/staging/ks7010/ks_hostif.c 
> b/drivers/staging/ks7010/ks_hostif.c
> index 74a08417bd0b..67cf32433023 100644
> --- a/drivers/staging/ks7010/ks_hostif.c
> +++ b/drivers/staging/ks7010/ks_hostif.c
> @@ -251,9 +251,8 @@ int get_ap_information(struct ks_wlan_private *priv, 
> struct ap_info_t *ap_info,
>   offset = 0;
>  
>   while (bsize > offset) {
> - /* DPRINTK(4, "Element ID=%d\n",*bp); */

nit: Probably shouldn't remove debugging output in the same patch as
doing magic number removal.  (super nit-picky though.)

> - switch (*bp) {
> - case 0: /* ssid */
> + switch (*bp) { /* Information Element ID */
> + case WLAN_EID_SSID:
>   if (*(bp + 1) <= SSID_MAX_SIZE) {
>   ap->ssid.size = *(bp + 1);
>   } else {
> @@ -263,8 +262,8 @@ int get_ap_information(struct ks_wlan_private *priv, 
> struct ap_info_t *ap_info,
>   }
>   memcpy(ap->ssid.body, bp + 2, ap->ssid.size);
>   break;
> - case 1: /* rate */
> - case 50:/* ext rate */
> + case WLAN_EID_SUPP_RATES:
> + case WLAN_EID_EXT_SUPP_RATES:
>   if ((*(bp + 1) + ap->rate_set.size) <=
>   RATE_SET_MAX_SIZE) {
>   memcpy(>rate_set.body[ap->rate_set.size],
> @@ -280,9 +279,9 @@ int get_ap_information(struct ks_wlan_private *priv, 
> struct ap_info_t *ap_info,
>   (RATE_SET_MAX_SIZE - ap->rate_set.size);
>   }
>   break;
> - case 3: /* DS parameter */
> + case WLAN_EID_DS_PARAMS:
>   break;
> - case 48:/* RSN(WPA2) */
> + case WLAN_EID_RSN:
>   ap->rsn_ie.id = *bp;
>   if (*(bp + 1) <= RSN_IE_BODY_MAX) {
>   ap->rsn_ie.size = *(bp + 1);
> @@ -293,8 +292,8 @@ int get_ap_information(struct ks_wlan_private *priv, 
> struct ap_info_t *ap_info,
>   }
>   memcpy(ap->rsn_ie.body, bp + 2, ap->rsn_ie.size);
>   break;
> - case 221:   /* WPA */
> - if (memcmp(bp + 2, "\x00\x50\xf2\x01", 4) == 0) {   
> /* WPA OUI check */
> + case WLAN_EID_VENDOR_SPECIFIC: /* WPA */
> + if (memcmp(bp + 2, "\x00\x50\xf2\x01", 4) == 0) { /* 
> WPA OUI check */

Shouldn't have this line (unnecessary white space change)

>   ap->wpa_ie.id = *bp;
>   if (*(bp + 1) <= RSN_IE_BODY_MAX) {
>   ap->wpa_ie.size = *(bp + 1);
> @@ -309,18 +308,18 @@ int get_ap_information(struct ks_wlan_private *priv, 
> struct ap_info_t *ap_info,
>   }
>   break;
>  
> - case 2: /* FH parameter */
> - case 4: /* CF parameter */
> - case 5: /* TIM */
> - case 6: /* IBSS parameter */
> - case 7: /* Country */
> - case 42:/* ERP information */
> - case 47:/* Reserve ID 47 Broadcom AP */
> + case WLAN_EID_FH_PARAMS:
> + case WLAN_EID_CF_PARAMS:
> + case WLAN_EID_TIM:
> + case WLAN_EID_IBSS_PARAMS:
> + case WLAN_EID_COUNTRY:
> + case WLAN_EID_ERP_INFO:
>   break;
>   default:
>   DPRINTK(4, "unknown Element ID=%d\n", *bp);
>   break;
>   }
> +

FTR try not to include unrelated whitespace changes.  I see you changed
the case statement but the whitespace is after it and not really
related.  Again quite nit-picky but I'm guessing you are in staging to
learn so might as well learn it now than when you are patching the core
kernel :)


Good work,
Tobin.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/5] staging: ks7010: Replace SSID_MAX_SIZE with IEEE80211_MAX_SSID_LEN.

2018-02-28 Thread Quytelda Kahja
SSID_MAX_SIZE is a constant defined locally in ks_hostif.h, but it should
be replaced with IEEE80211_MAX_SSID_LEN from the kernel's 802.11 header,
of which it is just a copy.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c | 4 ++--
 drivers/staging/ks7010/ks_hostif.h | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 67cf32433023..59f7c4e422d3 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -253,12 +253,12 @@ int get_ap_information(struct ks_wlan_private *priv, 
struct ap_info_t *ap_info,
while (bsize > offset) {
switch (*bp) { /* Information Element ID */
case WLAN_EID_SSID:
-   if (*(bp + 1) <= SSID_MAX_SIZE) {
+   if (*(bp + 1) <= IEEE80211_MAX_SSID_LEN) {
ap->ssid.size = *(bp + 1);
} else {
DPRINTK(1, "size over :: ssid size=%d\n",
*(bp + 1));
-   ap->ssid.size = SSID_MAX_SIZE;
+   ap->ssid.size = IEEE80211_MAX_SSID_LEN;
}
memcpy(ap->ssid.body, bp + 2, ap->ssid.size);
break;
diff --git a/drivers/staging/ks7010/ks_hostif.h 
b/drivers/staging/ks7010/ks_hostif.h
index 9ac317e4b507..b46aa94c0d48 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -225,10 +225,9 @@ struct hostif_start_confirm_t {
__le16 result_code;
 } __packed;
 
-#define SSID_MAX_SIZE 32
 struct ssid_t {
u8 size;
-   u8 body[SSID_MAX_SIZE];
+   u8 body[IEEE80211_MAX_SSID_LEN];
u8 ssid_pad;
 } __packed;
 
-- 
2.16.2

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


[PATCH 4/5] staging: ks7010: Replace local capability constants with kernel constants.

2018-02-28 Thread Quytelda Kahja
This driver defined constants BSS_CAP_* to represent WLAN capability
codes; however, these constants are already defined in the header
'linux/ieee80211.h' as WLAN_CAPABILITY_*.  This change removes the locally
defined constants and substitutes the kernel's constants.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c   |  8 
 drivers/staging/ks7010/ks_hostif.h   | 10 --
 drivers/staging/ks7010/ks_wlan_net.c |  6 +++---
 3 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 4d11627a3d72..f425975fbcbc 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -1386,14 +1386,14 @@ static __le16 ks_wlan_cap(struct ks_wlan_private *priv)
u16 capability = 0x;
 
if (priv->reg.preamble == SHORT_PREAMBLE) {
-   capability |= BSS_CAP_SHORT_PREAMBLE;
+   capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
}
 
-   capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
+   capability &= ~(WLAN_CAPABILITY_PBCC);  /* pbcc not support */
 
if (priv->reg.phy_type != D_11B_ONLY_MODE) {
-   capability |= BSS_CAP_SHORT_SLOT_TIME;
-   capability &= ~(BSS_CAP_DSSS_OFDM);
+   capability |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
+   capability &= ~(WLAN_CAPABILITY_DSSS_OFDM);
}
 
return cpu_to_le16((uint16_t)capability);
diff --git a/drivers/staging/ks7010/ks_hostif.h 
b/drivers/staging/ks7010/ks_hostif.h
index b46aa94c0d48..8f08e1e58991 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -284,16 +284,6 @@ struct ap_info_t {
u8 pad0;/* +09 */
__le16 beacon_period;   /* +10 */
__le16 capability;  /* +12 */
-#define BSS_CAP_ESS BIT(0)
-#define BSS_CAP_IBSSBIT(1)
-#define BSS_CAP_CF_POLABLE  BIT(2)
-#define BSS_CAP_CF_POLL_REQ BIT(3)
-#define BSS_CAP_PRIVACY BIT(4)
-#define BSS_CAP_SHORT_PREAMBLE  BIT(5)
-#define BSS_CAP_PBCCBIT(6)
-#define BSS_CAP_CHANNEL_AGILITY BIT(7)
-#define BSS_CAP_SHORT_SLOT_TIME BIT(10)
-#define BSS_CAP_DSSS_OFDM   BIT(13)
u8 frame_type;  /* +14 */
u8 ch_info; /* +15 */
 #define FRAME_TYPE_BEACON  0x80
diff --git a/drivers/staging/ks7010/ks_wlan_net.c 
b/drivers/staging/ks7010/ks_wlan_net.c
index e48c55769c94..91acf87ab8dd 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -1366,8 +1366,8 @@ static inline char *ks_wlan_translate_scan(struct 
net_device *dev,
/* Add mode */
iwe.cmd = SIOCGIWMODE;
capabilities = ap->capability;
-   if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
-   if (capabilities & BSS_CAP_ESS)
+   if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
+   if (capabilities & WLAN_CAPABILITY_ESS)
iwe.u.mode = IW_MODE_INFRA;
else
iwe.u.mode = IW_MODE_ADHOC;
@@ -1396,7 +1396,7 @@ static inline char *ks_wlan_translate_scan(struct 
net_device *dev,
 
/* Add encryption capability */
iwe.cmd = SIOCGIWENCODE;
-   if (capabilities & BSS_CAP_PRIVACY)
+   if (capabilities & WLAN_CAPABILITY_PRIVACY)
iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
else
iwe.u.data.flags = IW_ENCODE_DISABLED;
-- 
2.16.2

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


[PATCH 1/5] staging: ks7010: Use constants from ieee80211_eid instead of literal ints.

2018-02-28 Thread Quytelda Kahja
The case statement in get_ap_information() should not use literal integers
to parse information element IDs when these values are provided by name
in 'enum ieee80211_eid' in the header 'linux/ieee80211.h'.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c | 31 +++
 drivers/staging/ks7010/ks_hostif.h |  1 +
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 74a08417bd0b..67cf32433023 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -251,9 +251,8 @@ int get_ap_information(struct ks_wlan_private *priv, struct 
ap_info_t *ap_info,
offset = 0;
 
while (bsize > offset) {
-   /* DPRINTK(4, "Element ID=%d\n",*bp); */
-   switch (*bp) {
-   case 0: /* ssid */
+   switch (*bp) { /* Information Element ID */
+   case WLAN_EID_SSID:
if (*(bp + 1) <= SSID_MAX_SIZE) {
ap->ssid.size = *(bp + 1);
} else {
@@ -263,8 +262,8 @@ int get_ap_information(struct ks_wlan_private *priv, struct 
ap_info_t *ap_info,
}
memcpy(ap->ssid.body, bp + 2, ap->ssid.size);
break;
-   case 1: /* rate */
-   case 50:/* ext rate */
+   case WLAN_EID_SUPP_RATES:
+   case WLAN_EID_EXT_SUPP_RATES:
if ((*(bp + 1) + ap->rate_set.size) <=
RATE_SET_MAX_SIZE) {
memcpy(>rate_set.body[ap->rate_set.size],
@@ -280,9 +279,9 @@ int get_ap_information(struct ks_wlan_private *priv, struct 
ap_info_t *ap_info,
(RATE_SET_MAX_SIZE - ap->rate_set.size);
}
break;
-   case 3: /* DS parameter */
+   case WLAN_EID_DS_PARAMS:
break;
-   case 48:/* RSN(WPA2) */
+   case WLAN_EID_RSN:
ap->rsn_ie.id = *bp;
if (*(bp + 1) <= RSN_IE_BODY_MAX) {
ap->rsn_ie.size = *(bp + 1);
@@ -293,8 +292,8 @@ int get_ap_information(struct ks_wlan_private *priv, struct 
ap_info_t *ap_info,
}
memcpy(ap->rsn_ie.body, bp + 2, ap->rsn_ie.size);
break;
-   case 221:   /* WPA */
-   if (memcmp(bp + 2, "\x00\x50\xf2\x01", 4) == 0) {   
/* WPA OUI check */
+   case WLAN_EID_VENDOR_SPECIFIC: /* WPA */
+   if (memcmp(bp + 2, "\x00\x50\xf2\x01", 4) == 0) { /* 
WPA OUI check */
ap->wpa_ie.id = *bp;
if (*(bp + 1) <= RSN_IE_BODY_MAX) {
ap->wpa_ie.size = *(bp + 1);
@@ -309,18 +308,18 @@ int get_ap_information(struct ks_wlan_private *priv, 
struct ap_info_t *ap_info,
}
break;
 
-   case 2: /* FH parameter */
-   case 4: /* CF parameter */
-   case 5: /* TIM */
-   case 6: /* IBSS parameter */
-   case 7: /* Country */
-   case 42:/* ERP information */
-   case 47:/* Reserve ID 47 Broadcom AP */
+   case WLAN_EID_FH_PARAMS:
+   case WLAN_EID_CF_PARAMS:
+   case WLAN_EID_TIM:
+   case WLAN_EID_IBSS_PARAMS:
+   case WLAN_EID_COUNTRY:
+   case WLAN_EID_ERP_INFO:
break;
default:
DPRINTK(4, "unknown Element ID=%d\n", *bp);
break;
}
+
offset += 2;/* id & size field */
offset += *(bp + 1);/* +size offset */
bp += (*(bp + 1) + 2);  /* pointer update */
diff --git a/drivers/staging/ks7010/ks_hostif.h 
b/drivers/staging/ks7010/ks_hostif.h
index 5bae8d468e23..9ac317e4b507 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -13,6 +13,7 @@
 #define _KS_HOSTIF_H_
 
 #include 
+#include 
 
 /*
  * HOST-MAC I/F events
-- 
2.16.2

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


[PATCH 5/5] staging: ks7010: Replace local frame type constants with kernel constants.

2018-02-28 Thread Quytelda Kahja
This driver defined constants FRAME_TYPE_* to represent frame control
field codes; however, these constants are already defined in the header
'linux/ieee80211.h' as  IEEE80211_STYPE_*.  This change removes the locally
defined constants and substitutes the kernel's constants.

Signed-off-by: Quytelda Kahja 
---
 drivers/staging/ks7010/ks_hostif.c | 2 +-
 drivers/staging/ks7010/ks_hostif.h | 6 --
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index f425975fbcbc..7935ba56bb1d 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -847,7 +847,7 @@ void hostif_scan_indication(struct ks_wlan_private *priv)
   priv->aplist.ap[i].bssid, ETH_ALEN) != 0)
continue;
 
-   if (ap_info->frame_type == FRAME_TYPE_PROBE_RESP)
+   if (ap_info->frame_type == IEEE80211_STYPE_PROBE_RESP)
get_ap_information(priv, ap_info,
   >aplist.ap[i]);
return;
diff --git a/drivers/staging/ks7010/ks_hostif.h 
b/drivers/staging/ks7010/ks_hostif.h
index 8f08e1e58991..166d83e4885c 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -286,8 +286,6 @@ struct ap_info_t {
__le16 capability;  /* +12 */
u8 frame_type;  /* +14 */
u8 ch_info; /* +15 */
-#define FRAME_TYPE_BEACON  0x80
-#define FRAME_TYPE_PROBE_RESP  0x50
__le16 body_size;   /* +16 */
u8 body[1024];  /* +18 */
/* +1032 */
@@ -465,8 +463,6 @@ struct last_associate_t {
 
 struct association_request_t {
u8 type;
-#define FRAME_TYPE_ASSOC_REQ   0x00
-#define FRAME_TYPE_REASSOC_REQ 0x20
u8 pad;
__le16 capability;
__le16 listen_interval;
@@ -476,8 +472,6 @@ struct association_request_t {
 
 struct association_response_t {
u8 type;
-#define FRAME_TYPE_ASSOC_RESP  0x10
-#define FRAME_TYPE_REASSOC_RESP0x30
u8 pad;
__le16 capability;
__le16 status;
-- 
2.16.2

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


[PATCH 3/5] staging: ks7010: Factor out repeated code into function 'ks_wlan_cap()'.

2018-02-28 Thread Quytelda Kahja
The code that generates a WLAN capability mask is repeated in five
functions.  This change refactors that code into a new function, which is
called now in each of those functions.

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

diff --git a/drivers/staging/ks7010/ks_hostif.c 
b/drivers/staging/ks7010/ks_hostif.c
index 59f7c4e422d3..4d11627a3d72 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -1381,11 +1381,28 @@ void hostif_start_request(struct ks_wlan_private *priv, 
unsigned char mode)
priv->scan_ind_count = 0;
 }
 
+static __le16 ks_wlan_cap(struct ks_wlan_private *priv)
+{
+   u16 capability = 0x;
+
+   if (priv->reg.preamble == SHORT_PREAMBLE) {
+   capability |= BSS_CAP_SHORT_PREAMBLE;
+   }
+
+   capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
+
+   if (priv->reg.phy_type != D_11B_ONLY_MODE) {
+   capability |= BSS_CAP_SHORT_SLOT_TIME;
+   capability &= ~(BSS_CAP_DSSS_OFDM);
+   }
+
+   return cpu_to_le16((uint16_t)capability);
+}
+
 static
 void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
 {
struct hostif_ps_adhoc_set_request_t *pp;
-   u16 capability;
 
DPRINTK(3, "\n");
 
@@ -1398,21 +1415,10 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private 
*priv)
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);
 
-   capability = 0x;
-   if (priv->reg.preamble == SHORT_PREAMBLE) {
-   /* short preamble */
-   capability |= BSS_CAP_SHORT_PREAMBLE;
-   }
-   capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
-   if (priv->reg.phy_type != D_11B_ONLY_MODE) {
-   capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime 
support */
-   capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM */
-   }
-   pp->capability = cpu_to_le16((uint16_t)capability);
-
/* send to device request */
ps_confirm_wait_inc(priv);
ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL);
@@ -1422,7 +1428,6 @@ static
 void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
 {
struct hostif_infrastructure_set_request_t *pp;
-   u16 capability;
 
DPRINTK(3, "ssid.size=%d\n", priv->reg.ssid.size);
 
@@ -1439,18 +1444,7 @@ void hostif_infrastructure_set_request(struct 
ks_wlan_private *priv)
   priv->reg.rate_set.size);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-
-   capability = 0x;
-   if (priv->reg.preamble == SHORT_PREAMBLE) {
-   /* short preamble */
-   capability |= BSS_CAP_SHORT_PREAMBLE;
-   }
-   capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
-   if (priv->reg.phy_type != D_11B_ONLY_MODE) {
-   capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime 
support */
-   capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not 
support */
-   }
-   pp->capability = cpu_to_le16((uint16_t)capability);
+   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));
@@ -1483,7 +1477,6 @@ void hostif_infrastructure_set_request(struct 
ks_wlan_private *priv)
 static void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
 {
struct hostif_infrastructure_set2_request_t *pp;
-   u16 capability;
 
DPRINTK(2, "ssid.size=%d\n", priv->reg.ssid.size);
 
@@ -1500,18 +1493,7 @@ static void hostif_infrastructure_set2_request(struct 
ks_wlan_private *priv)
   priv->reg.rate_set.size);
pp->ssid.size = priv->reg.ssid.size;
memcpy(>ssid.body[0], >reg.ssid.body[0], priv->reg.ssid.size);
-
-   capability = 0x;
-   if (priv->reg.preamble == SHORT_PREAMBLE) {
-   /* short preamble */
-   capability |= BSS_CAP_SHORT_PREAMBLE;
-   }
-   capability &= ~(BSS_CAP_PBCC);  /* pbcc not support */
-   if (priv->reg.phy_type != D_11B_ONLY_MODE) {
-   capability |= BSS_CAP_SHORT_SLOT_TIME;  /* ShortSlotTime 
support */
-   capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not 
support */
-   }
-   pp->capability = cpu_to_le16((uint16_t)capability);
+   pp->capability = ks_wlan_cap(priv);
pp->beacon_lost_count =

[RFC] android: ion: How to properly clean caches for uncached allocations

2018-02-28 Thread Liam Mark
The issue:

Currently in ION if you allocate uncached memory it is possible that there
are still dirty lines in the cache.  And often these dirty lines in the
cache are the zeros which were meant to clear out any sensitive kernel
data.

What this means is that if you allocate uncached memory from ION, and then
subsequently write to that buffer (using the uncached mapping you are
provided by ION) then the data you have written could be corrupted at some
point in the future if a dirty line is evicted from the cache.

Also this means there is a potential security issue.  If an un-privileged
userspace user allocated uncached memory (for example from the system heap)
and then if they were to read from that buffer (through the un-cached
mapping they are provided by ION), and if some of the zeros which were
written to that memory are still in the cache then this un-privileged
userspace user could read potentially sensitive kernel data.


An unacceptable fix:

I have included some sample code which should resolve this issue for the
system heap and the cma heap on some architectures, however this code
would not be acceptable for upstreaming since it uses hacks to clean
the cache.
Similar changes would need to be made to carveout heap and chunk heap.

I would appreciate some feedback on the proper way for ION to clean the
caches for memory it has allocated that is intended for uncached access.

I realize that it may be tempting, as a solution to this problem, to
simply strip uncached support from ION. I hope that we can try to find a
solution which preserves uncached memory support as ION uncached memory
is often used (though perhaps not in upstreamed code) in cases such as
multimedia use cases where there is no CPU access required, in secure
heap allocations, and in some cases where there is minimal CPU access
and therefore uncached memory performs better.

Signed-off-by: Liam Mark 
---
 drivers/staging/android/ion/ion.c | 16 
 drivers/staging/android/ion/ion.h |  5 -
 drivers/staging/android/ion/ion_cma_heap.c|  3 +++
 drivers/staging/android/ion/ion_page_pool.c   |  8 ++--
 drivers/staging/android/ion/ion_system_heap.c |  7 ++-
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/android/ion/ion.c 
b/drivers/staging/android/ion/ion.c
index 57e0d8035b2e..10e967b0a0f4 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -38,6 +38,22 @@ bool ion_buffer_cached(struct ion_buffer *buffer)
return !!(buffer->flags & ION_FLAG_CACHED);
 }
 
+void ion_pages_sync_for_device(struct page *page, size_t size,
+  enum dma_data_direction dir)
+{
+   struct scatterlist sg;
+   struct device dev = {0};
+
+   /* hack, use dummy device */
+   arch_setup_dma_ops(, 0, 0, NULL, false);
+
+   sg_init_table(, 1);
+   sg_set_page(, page, size, 0);
+   /* hack, use phys address for dma address */
+   sg_dma_address() = page_to_phys(page);
+   dma_sync_sg_for_device(, , 1, dir);
+}
+
 /* this function should only be called while dev->lock is held */
 static void ion_buffer_add(struct ion_device *dev,
   struct ion_buffer *buffer)
diff --git a/drivers/staging/android/ion/ion.h 
b/drivers/staging/android/ion/ion.h
index a238f23c9116..227b9928d185 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -192,6 +192,9 @@ struct ion_heap {
  */
 bool ion_buffer_cached(struct ion_buffer *buffer);
 
+void ion_pages_sync_for_device(struct page *page, size_t size,
+  enum dma_data_direction dir);
+
 /**
  * ion_buffer_fault_user_mappings - fault in user mappings of this buffer
  * @buffer:buffer
@@ -333,7 +336,7 @@ struct ion_page_pool {
 struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order,
   bool cached);
 void ion_page_pool_destroy(struct ion_page_pool *pool);
-struct page *ion_page_pool_alloc(struct ion_page_pool *pool);
+struct page *ion_page_pool_alloc(struct ion_page_pool *pool, bool *from_pool);
 void ion_page_pool_free(struct ion_page_pool *pool, struct page *page);
 
 /** ion_page_pool_shrink - shrinks the size of the memory cached in the pool
diff --git a/drivers/staging/android/ion/ion_cma_heap.c 
b/drivers/staging/android/ion/ion_cma_heap.c
index 49718c96bf9e..82e80621d114 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -59,6 +59,9 @@ static int ion_cma_allocate(struct ion_heap *heap, struct 
ion_buffer *buffer,
memset(page_address(pages), 0, size);
}
 
+   if (!ion_buffer_cached(buffer))
+   ion_pages_sync_for_device(pages, size, DMA_BIDIRECTIONAL);
+
table = kmalloc(sizeof(*table), GFP_KERNEL);
if (!table)
goto err;
diff --git 

[PATCH] staging/imx: Fix inconsistent IS_ERR and PTR_ERR

2018-02-28 Thread Gustavo A. R. Silva
Fix inconsistent IS_ERR and PTR_ERR in imx_csi_probe.
The proper pointer to be passed as argument is pinctrl
instead of priv->vdev.

This issue was detected with the help of Coccinelle.

Fixes: 52e17089d185 ("media: imx: Don't initialize vars that won't be used")
Signed-off-by: Gustavo A. R. Silva 
---
 drivers/staging/media/imx/imx-media-csi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/imx/imx-media-csi.c 
b/drivers/staging/media/imx/imx-media-csi.c
index 5a195f8..4f290a0 100644
--- a/drivers/staging/media/imx/imx-media-csi.c
+++ b/drivers/staging/media/imx/imx-media-csi.c
@@ -1798,7 +1798,7 @@ static int imx_csi_probe(struct platform_device *pdev)
priv->dev->of_node = pdata->of_node;
pinctrl = devm_pinctrl_get_select_default(priv->dev);
if (IS_ERR(pinctrl)) {
-   ret = PTR_ERR(priv->vdev);
+   ret = PTR_ERR(pinctrl);
goto free;
}
 
-- 
2.7.4

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


[PATCH] staging: rtl8192u: return -ENOMEM on failed allocation of priv->oldaddr

2018-02-28 Thread Colin King
From: Colin Ian King 

Currently the allocation of priv->oldaddr is not null checked which will
lead to subsequent errors when accessing priv->oldaddr.  Fix this with
a null pointer check and a return of -ENOMEM on allocation failure.

Detected with Coccinelle:
drivers/staging/rtl8192u/r8192U_core.c:1708:2-15: alloc with no test,
possible model on line 1723

Fixes: 8fc8598e61f6 ("Staging: Added Realtek rtl8192u driver to staging")
Signed-off-by: Colin Ian King 
---
 drivers/staging/rtl8192u/r8192U_core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 3c300f7b6a62..d607c59761cf 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -1706,6 +1706,8 @@ static short rtl8192_usb_initendpoints(struct net_device 
*dev)
 
priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
priv->oldaddr = kmalloc(16, GFP_KERNEL);
+   if (!priv->oldaddr)
+   return -ENOMEM;
oldaddr = priv->oldaddr;
align = ((long)oldaddr) & 3;
if (align) {
-- 
2.15.1

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