[PATCH v2 4/4] staging: rtl8188eu: remove unused function parameters

2021-04-19 Thread Martin Kaiser
The Enable and Linked parameters of _BeaconFunctionEnable are not used.
Remove them.

Signed-off-by: Martin Kaiser 
---
v2:
 - no change, re-sending the entire series

 drivers/staging/rtl8188eu/hal/usb_halinit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c 
b/drivers/staging/rtl8188eu/hal/usb_halinit.c
index abe58cf2de16..80cdcf6f7879 100644
--- a/drivers/staging/rtl8188eu/hal/usb_halinit.c
+++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c
@@ -574,8 +574,7 @@ static void _InitBeaconParameters(struct adapter *Adapter)
haldata->RegCR_1 = usb_read8(Adapter, REG_CR + 1);
 }
 
-static void _BeaconFunctionEnable(struct adapter *Adapter,
- bool Enable, bool Linked)
+static void _BeaconFunctionEnable(struct adapter *Adapter)
 {
usb_write8(Adapter, REG_BCN_CTRL, (BIT(4) | BIT(3) | BIT(1)));
 
@@ -1961,7 +1960,7 @@ void beacon_timing_control(struct adapter *adapt)
usb_write8(adapt,  REG_RXTSF_OFFSET_CCK, 0x50);
usb_write8(adapt, REG_RXTSF_OFFSET_OFDM, 0x50);
 
-   _BeaconFunctionEnable(adapt, true, true);
+   _BeaconFunctionEnable(adapt);
 
ResumeTxBeacon(adapt);
 
-- 
2.20.1



[PATCH v2 3/4] staging: rtl8188eu: cmdThread is a task_struct

2021-04-19 Thread Martin Kaiser
cmdThread is the return value of kthread_run, i.e. a struct task_struct.

Signed-off-by: Martin Kaiser 
---
v2:
 - no change, re-sending the entire series

 drivers/staging/rtl8188eu/include/drv_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/include/drv_types.h 
b/drivers/staging/rtl8188eu/include/drv_types.h
index 0a3acb378d6d..4116051a9a65 100644
--- a/drivers/staging/rtl8188eu/include/drv_types.h
+++ b/drivers/staging/rtl8188eu/include/drv_types.h
@@ -150,7 +150,7 @@ struct adapter {
 
u8  hw_init_completed;
 
-   void *cmdThread;
+   struct task_struct *cmdThread;
struct  net_device *pnetdev;
struct  net_device *pmondev;
 
-- 
2.20.1



[PATCH v2 2/4] staging: rtl8188eu: remove constant variable and dead code

2021-04-19 Thread Martin Kaiser
g_wifi_on is always true. Remove the variable and the code that would
be run only if g_wifi_on was false.

While at it, remove a pointlesss comment that starts with /** and is
misinterpreted as a kernel-doc comment.

Signed-off-by: Martin Kaiser 
Reported-by: kernel test robot 
---
v2:
 - fix compiler warning, remove a comment that looks like kernel-doc

 drivers/staging/rtl8188eu/os_dep/rtw_android.c | 17 -
 1 file changed, 17 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/rtw_android.c 
b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
index f5763a9d70c5..f1470ac56874 100644
--- a/drivers/staging/rtl8188eu/os_dep/rtw_android.c
+++ b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
@@ -52,16 +52,6 @@ struct android_wifi_priv_cmd {
int total_len;
 };
 
-/**
- * Local (static) functions and variables
- */
-
-/* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
- * time (only) in dhd_open, subsequential wifi on will be handled by
- * wl_android_wifi_on
- */
-static int g_wifi_on = true;
-
 int rtw_android_cmdstr_to_num(char *cmdstr)
 {
int cmd_num;
@@ -154,12 +144,6 @@ int rtw_android_priv_cmd(struct net_device *net, struct 
ifreq *ifr, int cmd)
case ANDROID_WIFI_CMD_SETFWPATH:
goto response;
}
-   if (!g_wifi_on) {
-   DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
-   __func__, command, ifr->ifr_name);
-   ret = 0;
-   goto free;
-   }
switch (cmd_num) {
case ANDROID_WIFI_CMD_STOP:
break;
@@ -244,7 +228,6 @@ int rtw_android_priv_cmd(struct net_device *net, struct 
ifreq *ifr, int cmd)
} else {
ret = bytes_written;
}
-free:
kfree(command);
return ret;
 }
-- 
2.20.1



[PATCH v2 1/4] staging: rtl8188eu: change bLeisurePs' type to bool

2021-04-19 Thread Martin Kaiser
bLeisurePs is used as a boolean variable. Change its type from
u8 to bool.

Signed-off-by: Martin Kaiser 
---
v2:
 - no change, re-sending the entire series

 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h 
b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
index 06062643c868..4345dc0c7cf9 100644
--- a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
+++ b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
@@ -171,7 +171,7 @@ struct pwrctrl_priv {
unsigned long ips_deny_time; /* will deny IPS when system time less 
than this */
u8 ps_processing; /* temp used to mark whether in rtw_ps_processor */
 
-   u8  bLeisurePs;
+   boolbLeisurePs;
u8  LpsIdleCount;
u8  power_mgnt;
u8  bFwCurrentInPSMode;
-- 
2.20.1



[PATCH 1/4] staging: rtl8188eu: change bLeisurePs' type to bool

2021-04-17 Thread Martin Kaiser
bLeisurePs is used as a boolean variable. Change its type from
u8 to bool.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h 
b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
index 06062643c868..4345dc0c7cf9 100644
--- a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
+++ b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
@@ -171,7 +171,7 @@ struct pwrctrl_priv {
unsigned long ips_deny_time; /* will deny IPS when system time less 
than this */
u8 ps_processing; /* temp used to mark whether in rtw_ps_processor */
 
-   u8  bLeisurePs;
+   boolbLeisurePs;
u8  LpsIdleCount;
u8  power_mgnt;
u8  bFwCurrentInPSMode;
-- 
2.20.1



[PATCH 3/4] staging: rtl8188eu: cmdThread is a task_struct

2021-04-17 Thread Martin Kaiser
cmdThread is the return value of kthread_run, i.e. a struct task_struct.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/drv_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/include/drv_types.h 
b/drivers/staging/rtl8188eu/include/drv_types.h
index 0a3acb378d6d..4116051a9a65 100644
--- a/drivers/staging/rtl8188eu/include/drv_types.h
+++ b/drivers/staging/rtl8188eu/include/drv_types.h
@@ -150,7 +150,7 @@ struct adapter {
 
u8  hw_init_completed;
 
-   void *cmdThread;
+   struct task_struct *cmdThread;
struct  net_device *pnetdev;
struct  net_device *pmondev;
 
-- 
2.20.1



[PATCH 4/4] staging: rtl8188eu: remove unused function parameters

2021-04-17 Thread Martin Kaiser
The Enable and Linked parameters of _BeaconFunctionEnable are not used.
Remove them.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/hal/usb_halinit.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c 
b/drivers/staging/rtl8188eu/hal/usb_halinit.c
index abe58cf2de16..80cdcf6f7879 100644
--- a/drivers/staging/rtl8188eu/hal/usb_halinit.c
+++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c
@@ -574,8 +574,7 @@ static void _InitBeaconParameters(struct adapter *Adapter)
haldata->RegCR_1 = usb_read8(Adapter, REG_CR + 1);
 }
 
-static void _BeaconFunctionEnable(struct adapter *Adapter,
- bool Enable, bool Linked)
+static void _BeaconFunctionEnable(struct adapter *Adapter)
 {
usb_write8(Adapter, REG_BCN_CTRL, (BIT(4) | BIT(3) | BIT(1)));
 
@@ -1961,7 +1960,7 @@ void beacon_timing_control(struct adapter *adapt)
usb_write8(adapt,  REG_RXTSF_OFFSET_CCK, 0x50);
usb_write8(adapt, REG_RXTSF_OFFSET_OFDM, 0x50);
 
-   _BeaconFunctionEnable(adapt, true, true);
+   _BeaconFunctionEnable(adapt);
 
ResumeTxBeacon(adapt);
 
-- 
2.20.1



[PATCH 2/4] staging: rtl8188eu: remove constant variable and dead code

2021-04-17 Thread Martin Kaiser
g_wifi_on is always true. Remove the variable and the code that would
be run only if g_wifi_on was false.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/rtw_android.c | 15 +--
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/rtw_android.c 
b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
index f5763a9d70c5..2d21767bc1a3 100644
--- a/drivers/staging/rtl8188eu/os_dep/rtw_android.c
+++ b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
@@ -53,15 +53,9 @@ struct android_wifi_priv_cmd {
 };
 
 /**
- * Local (static) functions and variables
+ * Local (static) functions
  */
 
-/* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
- * time (only) in dhd_open, subsequential wifi on will be handled by
- * wl_android_wifi_on
- */
-static int g_wifi_on = true;
-
 int rtw_android_cmdstr_to_num(char *cmdstr)
 {
int cmd_num;
@@ -154,12 +148,6 @@ int rtw_android_priv_cmd(struct net_device *net, struct 
ifreq *ifr, int cmd)
case ANDROID_WIFI_CMD_SETFWPATH:
goto response;
}
-   if (!g_wifi_on) {
-   DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
-   __func__, command, ifr->ifr_name);
-   ret = 0;
-   goto free;
-   }
switch (cmd_num) {
case ANDROID_WIFI_CMD_STOP:
break;
@@ -244,7 +232,6 @@ int rtw_android_priv_cmd(struct net_device *net, struct 
ifreq *ifr, int cmd)
} else {
ret = bytes_written;
}
-free:
kfree(command);
return ret;
 }
-- 
2.20.1



[PATCH 11/12] staging: rtl8188eu: remove a dead assignment

2021-04-08 Thread Martin Kaiser
There's no need to set cmd_hdl to NULL after it's used. It will be set
again before the next command is processed.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index e1bf4ce9ab9d..9d358dce5296 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -217,8 +217,6 @@ int rtw_cmd_thread(void *context)
} else {
pcmd->res = H2C_PARAMETERS_ERROR;
}
-
-   cmd_hdl = NULL;
}
 
/* call callback function for post-processed */
-- 
2.20.1



[PATCH 12/12] staging: rtl8188eu: simplify rtw_cmd_thread's main loop

2021-04-08 Thread Martin Kaiser
In rtw_cmd_thread's main loop, we wait until there's a command in the
queue. To skip this wait statement in subsequent iterations, the driver
uses a label and goto instead of the actual loop. We only get back to the
initial wait if the queue is empty when we read it.

Basically, all we want to do is check if there's a command in the queue.
If yes, we process it. If not, we wait until someone enqueues a command.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 9d358dce5296..6728391d39e3 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -188,10 +188,6 @@ int rtw_cmd_thread(void *context)
 ("start r871x %s \n", __func__));
 
while (1) {
-   if 
(wait_for_completion_interruptible(>cmd_queue_comp))
-   break;
-
-_next:
if (padapter->bDriverStopped ||
padapter->bSurpriseRemoved) {
DBG_88E("%s: DriverStopped(%d) SurpriseRemoved(%d) 
break at line %d\n",
@@ -201,8 +197,13 @@ int rtw_cmd_thread(void *context)
}
 
pcmd = rtw_dequeue_cmd(>cmd_queue);
-   if (!pcmd)
+   if (!pcmd) {
+   /* The queue is empty. Wait until someone enqueues a 
command. */
+   if 
(wait_for_completion_interruptible(>cmd_queue_comp))
+   break;
+
continue;
+   }
 
if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) {
pcmd->res = H2C_DROPPED;
@@ -239,8 +240,6 @@ int rtw_cmd_thread(void *context)
 
if (signal_pending(current))
flush_signals(current);
-
-   goto _next;
}
pcmdpriv->cmdthd_running = false;
 
-- 
2.20.1



[PATCH 10/12] staging: rtl8188eu: remove duplicate if statement

2021-04-08 Thread Martin Kaiser
There's two identical checks if the device was stopped or unplugged.
Remove one of them.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 4e4cac1ad6be..e1bf4ce9ab9d 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -191,13 +191,6 @@ int rtw_cmd_thread(void *context)
if 
(wait_for_completion_interruptible(>cmd_queue_comp))
break;
 
-   if (padapter->bDriverStopped ||
-   padapter->bSurpriseRemoved) {
-   DBG_88E("%s: DriverStopped(%d) SurpriseRemoved(%d) 
break at line %d\n",
-   __func__, padapter->bDriverStopped,
-   padapter->bSurpriseRemoved, __LINE__);
-   break;
-   }
 _next:
if (padapter->bDriverStopped ||
padapter->bSurpriseRemoved) {
-- 
2.20.1



[PATCH 09/12] staging: rtl8188eu: always free cmd_obj in the cmd thread

2021-04-08 Thread Martin Kaiser
The rtl8188 driver starts a command thread that reads commands from a queue
and processes them. Each command consists of a struct cmd_obj. The command
thread may call a function to process the current command and optionally a
post-processing function. Eventually, the command's cmd_obj must be freed.

At the moment, if there's a post-processing function for the current
command, this function has to free the cmd_obj. If there's no
post-processing function, the command thread frees cmd_obj.

It's much simpler if we always leave it to the command thread to free
cmd_obj.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c | 24 +++-
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 0bbe5ee918ce..4e4cac1ad6be 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -235,17 +235,16 @@ int rtw_cmd_thread(void *context)
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
 ("mlme_cmd_hdl(): pcmd_callback = 
0x%p, cmdcode = 0x%x\n",
  pcmd_callback, pcmd->cmdcode));
-   rtw_free_cmd_obj(pcmd);
} else {
/* todo: !!! fill rsp_buf to pcmd->rsp if 
(pcmd->rsp!= NULL) */
-   pcmd_callback(pcmd->padapter, pcmd);/* need 
consider that free cmd_obj in rtw_cmd_callback */
+   pcmd_callback(pcmd->padapter, pcmd);
}
} else {
RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
 ("%s: cmdcode = 0x%x callback not defined!\n",
  __func__, pcmd->cmdcode));
-   rtw_free_cmd_obj(pcmd);
}
+   rtw_free_cmd_obj(pcmd);
 
if (signal_pending(current))
flush_signals(current);
@@ -1186,9 +1185,6 @@ void rtw_survey_cmd_callback(struct adapter *padapter,  
struct cmd_obj *pcmd)
RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
 ("\n Error: 
MgntActrtw_set_802_11_bssid_LIST_SCAN Fail \n\n."));
}
-
-   /*  free cmd */
-   rtw_free_cmd_obj(pcmd);
 }
 
 void rtw_disassoc_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
@@ -1202,11 +1198,7 @@ void rtw_disassoc_cmd_callback(struct adapter *padapter, 
struct cmd_obj *pcmd)
 
RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
 ("\n ***Error: disconnect_cmd_callback Fail ***\n."));
-   return;
}
-
-   /*  free cmd */
-   rtw_free_cmd_obj(pcmd);
 }
 
 void rtw_joinbss_cmd_callback(struct adapter *padapter,  struct cmd_obj *pcmd)
@@ -1224,8 +1216,6 @@ void rtw_joinbss_cmd_callback(struct adapter *padapter,  
struct cmd_obj *pcmd)
mod_timer(>assoc_timer,
  jiffies + msecs_to_jiffies(1));
}
-
-   rtw_free_cmd_obj(pcmd);
 }
 
 void rtw_createbss_cmd_callback(struct adapter *padapter, struct cmd_obj *pcmd)
@@ -1292,8 +1282,6 @@ void rtw_createbss_cmd_callback(struct adapter *padapter, 
struct cmd_obj *pcmd)
 createbss_cmd_fail:
 
spin_unlock_bh(>lock);
-
-   rtw_free_cmd_obj(pcmd);
 }
 
 void rtw_setstaKey_cmdrsp_callback(struct adapter *padapter,  struct cmd_obj 
*pcmd)
@@ -1305,10 +1293,7 @@ void rtw_setstaKey_cmdrsp_callback(struct adapter 
*padapter,  struct cmd_obj *pc
if (!psta) {
RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
 ("\nERROR: %s => can't get sta_info\n\n", __func__));
-   goto exit;
}
-exit:
-   rtw_free_cmd_obj(pcmd);
 }
 
 void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter,  struct cmd_obj 
*pcmd)
@@ -1322,7 +1307,7 @@ void rtw_setassocsta_cmdrsp_callback(struct adapter 
*padapter,  struct cmd_obj *
if (!psta) {
RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
 ("\nERROR: %s => can't get sta_info\n\n", __func__));
-   goto exit;
+   return;
}
 
psta->aid = passocsta_rsp->cam_id;
@@ -1332,7 +1317,4 @@ void rtw_setassocsta_cmdrsp_callback(struct adapter 
*padapter,  struct cmd_obj *
 
set_fwstate(pmlmepriv, _FW_LINKED);
spin_unlock_bh(>lock);
-
-exit:
-   rtw_free_cmd_obj(pcmd);
 }
-- 
2.20.1



[PATCH 08/12] staging: rtl8188eu: move another static array from .h to .c

2021-04-08 Thread Martin Kaiser
Move the declaration of the rtw_cmd_callback array from rtw_cmd.h to
rtw_cmd.c.

The _RTW_CMD_C_ symbol is now obsolete and can be removed.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c| 19 ++-
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 20 
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index bf1e49404e64..0bbe5ee918ce 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -4,7 +4,6 @@
  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
  *
  
**/
-#define _RTW_CMD_C_
 
 #include 
 #include 
@@ -30,6 +29,24 @@ static struct cmd_hdl wlancmds[] = {
{sizeof(struct SetChannelPlan_param), set_chplan_hdl}
 };
 
+static struct _cmd_callback rtw_cmd_callback[] = {
+   {_JoinBss_CMD_, _joinbss_cmd_callback},
+   {_DisConnect_CMD_, _disassoc_cmd_callback},
+   {_CreateBss_CMD_, _createbss_cmd_callback},
+   {_SetOpMode_CMD_, NULL},
+   {_SiteSurvey_CMD_, _survey_cmd_callback},
+   {_SetAuth_CMD_, NULL},
+   {_SetKey_CMD_, NULL},
+   {_SetStaKey_CMD_, _setstaKey_cmdrsp_callback},
+   {_SetAssocSta_CMD_, _setassocsta_cmdrsp_callback},
+   {_AddBAReq_CMD_, NULL},
+   {_SetChannel_CMD_, NULL},
+   {_TX_Beacon_CMD_, NULL},
+   {_Set_MLME_EVT_CMD_, NULL},
+   {_Set_Drv_Extra_CMD_, NULL},
+   {_SetChannelPlan_CMD_, NULL},
+};
+
 /*
  * Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
  * No irqsave is necessary.
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 002a797c6d0a..68b8ad1a412f 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -361,24 +361,4 @@ enum rtw_h2c_cmd {
MAX_H2CCMD
 };
 
-#ifdef _RTW_CMD_C_
-static struct _cmd_callbackrtw_cmd_callback[] = {
-   {_JoinBss_CMD_, _joinbss_cmd_callback},
-   {_DisConnect_CMD_, _disassoc_cmd_callback},
-   {_CreateBss_CMD_, _createbss_cmd_callback},
-   {_SetOpMode_CMD_, NULL},
-   {_SiteSurvey_CMD_, _survey_cmd_callback},
-   {_SetAuth_CMD_, NULL},
-   {_SetKey_CMD_, NULL},
-   {_SetStaKey_CMD_, _setstaKey_cmdrsp_callback},
-   {_SetAssocSta_CMD_, _setassocsta_cmdrsp_callback},
-   {_AddBAReq_CMD_, NULL},
-   {_SetChannel_CMD_, NULL},
-   {_TX_Beacon_CMD_, NULL},
-   {_Set_MLME_EVT_CMD_, NULL},
-   {_Set_Drv_Extra_CMD_, NULL},
-   {_SetChannelPlan_CMD_, NULL},
-};
-#endif
-
 #endif /*  _CMD_H_ */
-- 
2.20.1



[PATCH 07/12] staging: rtl8188eu: move static array from .h to .c

2021-04-08 Thread Martin Kaiser
Declaring a static array in a header file is likely to cause name conflicts
if the declaration is pulled in multiple times.

The rtl8188 driver protects the declaration of the wlancmds array in
rtw_mlme_ext.h with ifdef _RTW_CMD_C_, which is defined only in rtw_cmd.c.
It makes more sense to declare the array in the .c file.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c  | 18 +++
 .../staging/rtl8188eu/include/rtw_mlme_ext.h  | 22 ---
 2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 1724dfd7edbc..bf1e49404e64 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -12,6 +12,24 @@
 #include 
 #include 
 
+static struct cmd_hdl wlancmds[] = {
+   {sizeof(struct wlan_bssid_ex), join_cmd_hdl},
+   {sizeof(struct disconnect_parm), disconnect_hdl},
+   {sizeof(struct wlan_bssid_ex), createbss_hdl},
+   {sizeof(struct setopmode_parm), setopmode_hdl},
+   {sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl},
+   {sizeof(struct setauth_parm), setauth_hdl},
+   {sizeof(struct setkey_parm), setkey_hdl},
+   {sizeof(struct set_stakey_parm), set_stakey_hdl},
+   {sizeof(struct set_assocsta_parm), NULL},
+   {sizeof(struct addBaReq_parm), add_ba_hdl},
+   {sizeof(struct set_ch_parm), set_ch_hdl},
+   {sizeof(struct wlan_bssid_ex), tx_beacon_hdl},
+   {0, mlme_evt_hdl},
+   {0, rtw_drvextra_cmd_hdl},
+   {sizeof(struct SetChannelPlan_param), set_chplan_hdl}
+};
+
 /*
  * Caller and the rtw_cmd_thread can protect cmd_q by spin_lock.
  * No irqsave is necessary.
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h 
b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
index b11a6886a083..77eb5e3ef172 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
@@ -606,28 +606,6 @@ u8 led_blink_hdl(struct adapter *padapter, unsigned char 
*pbuf);
 u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf);
 u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf);
 
-#ifdef _RTW_CMD_C_
-
-static struct cmd_hdl wlancmds[] = {
-   {sizeof(struct wlan_bssid_ex), join_cmd_hdl},
-   {sizeof(struct disconnect_parm), disconnect_hdl},
-   {sizeof(struct wlan_bssid_ex), createbss_hdl},
-   {sizeof(struct setopmode_parm), setopmode_hdl},
-   {sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl},
-   {sizeof(struct setauth_parm), setauth_hdl},
-   {sizeof(struct setkey_parm), setkey_hdl},
-   {sizeof(struct set_stakey_parm), set_stakey_hdl},
-   {sizeof(struct set_assocsta_parm), NULL},
-   {sizeof(struct addBaReq_parm), add_ba_hdl},
-   {sizeof(struct set_ch_parm), set_ch_hdl},
-   {sizeof(struct wlan_bssid_ex), tx_beacon_hdl},
-   {0, mlme_evt_hdl},
-   {0, rtw_drvextra_cmd_hdl},
-   {sizeof(struct SetChannelPlan_param), set_chplan_hdl}
-};
-
-#endif
-
 struct C2HEvent_Header {
 #ifdef __LITTLE_ENDIAN
unsigned int len:16;
-- 
2.20.1



[PATCH 06/12] staging: rtl8188eu: remove a constant variable

2021-04-08 Thread Martin Kaiser
enqueue is always 0.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index c3c1cf67cf7e..4d507d9faec2 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -480,10 +480,9 @@ void LPS_Leave(struct adapter *padapter)
 void LeaveAllPowerSaveMode(struct adapter *Adapter)
 {
struct mlme_priv *pmlmepriv = >mlmepriv;
-   u8 enqueue = 0;
 
if (check_fwstate(pmlmepriv, _FW_LINKED))
-   rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, enqueue);
+   rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, 0);
 }
 
 void rtw_init_pwrctrl_priv(struct adapter *padapter)
-- 
2.20.1



[PATCH 05/12] staging: rtl8188eu: remove unused function parameter

2021-04-08 Thread Martin Kaiser
The struct adapter parameter of rtw_os_recvbuf_resource_alloc is not used.
Remove it.

While at it, use the same parameter name in the prototype and the function
definition.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c | 2 +-
 drivers/staging/rtl8188eu/include/recv_osdep.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/recv_linux.c  | 3 +--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c 
b/drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c
index 25f46b2f4920..09bc915994db 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c
@@ -38,7 +38,7 @@ int rtw_hal_init_recv_priv(struct adapter *padapter)
precvbuf = precvpriv->precv_buf;
 
for (i = 0; i < NR_RECVBUFF; i++) {
-   res = rtw_os_recvbuf_resource_alloc(padapter, precvbuf);
+   res = rtw_os_recvbuf_resource_alloc(precvbuf);
if (res == _FAIL)
break;
precvbuf->adapter = padapter;
diff --git a/drivers/staging/rtl8188eu/include/recv_osdep.h 
b/drivers/staging/rtl8188eu/include/recv_osdep.h
index 3b771702810d..614245d4b179 100644
--- a/drivers/staging/rtl8188eu/include/recv_osdep.h
+++ b/drivers/staging/rtl8188eu/include/recv_osdep.h
@@ -19,7 +19,7 @@ int rtw_recv_indicatepkt(struct adapter *adapter,
 
 void rtw_handle_tkip_mic_err(struct adapter *padapter, u8 bgroup);
 
-int rtw_os_recvbuf_resource_alloc(struct adapter *adapt, struct recv_buf *buf);
+int rtw_os_recvbuf_resource_alloc(struct recv_buf *precvbuf);
 
 void rtw_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl);
 
diff --git a/drivers/staging/rtl8188eu/os_dep/recv_linux.c 
b/drivers/staging/rtl8188eu/os_dep/recv_linux.c
index 9c9339863a4a..a647cdc330e4 100644
--- a/drivers/staging/rtl8188eu/os_dep/recv_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/recv_linux.c
@@ -14,8 +14,7 @@
 #include 
 
 /* alloc os related resource in struct recv_buf */
-int rtw_os_recvbuf_resource_alloc(struct adapter *padapter,
- struct recv_buf *precvbuf)
+int rtw_os_recvbuf_resource_alloc(struct recv_buf *precvbuf)
 {
precvbuf->pskb = NULL;
precvbuf->reuse = false;
-- 
2.20.1



[PATCH 04/12] staging: rtl8188eu: replace switch-case with if

2021-04-08 Thread Martin Kaiser
This switch has only one case. Replace it with an if statement.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 56ba0b8a4c87..e8222ffb6fea 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -675,13 +675,9 @@ u32 usb_write_port(struct adapter *padapter, u32 addr, u32 
cnt, struct xmit_buf
 ("%s(): usb_submit_urb, status =%x\n",
  __func__, status));
 
-   switch (status) {
-   case -ENODEV:
+   if (status == -ENODEV)
padapter->bDriverStopped = true;
-   break;
-   default:
-   break;
-   }
+
goto exit;
}
 
-- 
2.20.1



[PATCH 03/12] staging: rtl8188eu: make ffaddr2pipehdl static

2021-04-08 Thread Martin Kaiser
This function is used only inside usb_ops_linux.c.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/usb_ops_linux.h | 2 --
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c  | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index bd9c7716c440..19c6e76d747e 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -10,8 +10,6 @@
 #define USB_HIGH_SPEED_BULK_SIZE   512
 #define USB_FULL_SPEED_BULK_SIZE   64
 
-unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr);
-
 u8 usb_read8(struct adapter *adapter, u32 addr);
 u16 usb_read16(struct adapter *adapter, u32 addr);
 u32 usb_read32(struct adapter *adapter, u32 addr);
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 28655f41a75b..56ba0b8a4c87 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -195,7 +195,7 @@ static int recvbuf2recvframe(struct adapter *adapt, struct 
sk_buff *pskb)
return _SUCCESS;
 }
 
-unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr)
+static unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr)
 {
unsigned int pipe = 0, ep_num = 0;
struct usb_device *pusbd = pdvobj->pusbdev;
-- 
2.20.1



[PATCH 02/12] staging: rtl8188eu: remove prototype for non-existing function

2021-04-08 Thread Martin Kaiser
There's no usb_read_port_cancel function in this driver. Remove its
prototype.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/usb_ops_linux.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index 0262ace52e71..bd9c7716c440 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -17,7 +17,6 @@ u16 usb_read16(struct adapter *adapter, u32 addr);
 u32 usb_read32(struct adapter *adapter, u32 addr);
 
 u32 usb_read_port(struct adapter *adapter, u32 addr, struct recv_buf 
*precvbuf);
-void usb_read_port_cancel(struct adapter *adapter);
 
 int usb_write8(struct adapter *adapter, u32 addr, u8 val);
 int usb_write16(struct adapter *adapter, u32 addr, u16 val);
-- 
2.20.1



[PATCH 01/12] staging: rtl8188eu: remove the last urb callback macros

2021-04-08 Thread Martin Kaiser
Both usb_read_port_complete and usb_write_port_complete have a regs
parameter that is not used.

When this parameter is removed, the functions can be used as urb
completion callbacks directly. There's no need for the macros that
strip the second parameter.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/usb_ops_linux.h | 5 -
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c  | 4 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index 2f4976d251a1..0262ace52e71 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -10,11 +10,6 @@
 #define USB_HIGH_SPEED_BULK_SIZE   512
 #define USB_FULL_SPEED_BULK_SIZE   64
 
-#define usb_write_port_complete(purb, regs)\
-   usb_write_port_complete(purb)
-#define usb_read_port_complete(purb, regs) \
-   usb_read_port_complete(purb)
-
 unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr);
 
 u8 usb_read8(struct adapter *adapter, u32 addr);
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index f2fa4fb3595f..28655f41a75b 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -334,7 +334,7 @@ u32 usb_read32(struct adapter *adapter, u32 addr)
return le32_to_cpu(data);
 }
 
-static void usb_read_port_complete(struct urb *purb, struct pt_regs *regs)
+static void usb_read_port_complete(struct urb *purb)
 {
struct recv_buf *precvbuf = (struct recv_buf *)purb->context;
struct adapter *adapt = (struct adapter *)precvbuf->adapter;
@@ -519,7 +519,7 @@ int usb_write32(struct adapter *adapter, u32 addr, u32 val)
return usbctrl_vendorreq(adapter, wvalue, , 4, 
REALTEK_USB_VENQT_WRITE);
 }
 
-static void usb_write_port_complete(struct urb *purb, struct pt_regs *regs)
+static void usb_write_port_complete(struct urb *purb)
 {
struct xmit_buf *pxmitbuf = (struct xmit_buf *)purb->context;
struct adapter *padapter = pxmitbuf->padapter;
-- 
2.20.1



Re: [PATCH 01/10] staging: rtl8188eu: remove unused macros

2021-04-08 Thread Martin Kaiser
Thus wrote Greg Kroah-Hartman (gre...@linuxfoundation.org):

> Wow, that's there for a really old kernel version and should not be
> needed anymore at all.  I'll take this, but please remove the other ones
> here, they are not necessary.

Ok, I see what you mean. New patch is on the way.

Best regards,
Martin


[PATCH 09/10] staging: rtl8188eu: make usb_dvobj_init return a status

2021-04-07 Thread Martin Kaiser
usb_dvobj_init populates a struct dvobj_priv and installs it as interface
data of the usb interface. There's no point in returning this struct to the
caller, it makes more sense to return an error status.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 26 -
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 301dab65b571..71ef7941f688 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -48,7 +48,7 @@ static const struct usb_device_id rtw_usb_id_tbl[] = {
 
 MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
 
-static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
+static int usb_dvobj_init(struct usb_interface *usb_intf)
 {
int i;
struct dvobj_priv *pdvobjpriv;
@@ -61,7 +61,7 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface 
*usb_intf)
 
pdvobjpriv = kzalloc(sizeof(*pdvobjpriv), GFP_KERNEL);
if (!pdvobjpriv)
-   return NULL;
+   return -ENOMEM;
 
pdvobjpriv->pusbintf = usb_intf;
pusbd = interface_to_usbdev(usb_intf);
@@ -108,7 +108,7 @@ static struct dvobj_priv *usb_dvobj_init(struct 
usb_interface *usb_intf)
mutex_init(>usb_vendor_req_mutex);
usb_get_dev(pusbd);
 
-   return pdvobjpriv;
+   return 0;
 }
 
 static void usb_dvobj_deinit(struct usb_interface *usb_intf)
@@ -450,27 +450,21 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
 
 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct 
usb_device_id *pdid)
 {
-   struct dvobj_priv *dvobj;
+   int err;
 
-   /* Initialize dvobj_priv */
-   dvobj = usb_dvobj_init(pusb_intf);
-   if (!dvobj) {
-   RT_TRACE(_module_hci_intfs_c_, _drv_err_,
-("initialize device object priv Failed!\n"));
-   goto exit;
+   err = usb_dvobj_init(pusb_intf);
+   if (err) {
+   pr_debug("usb_dvobj_init failed\n");
+   return err;
}
 
if (!rtw_usb_if1_init(pusb_intf)) {
pr_debug("rtw_usb_if1_init failed\n");
-   goto free_dvobj;
+   usb_dvobj_deinit(pusb_intf);
+   return -ENODEV;
}
 
return 0;
-
-free_dvobj:
-   usb_dvobj_deinit(pusb_intf);
-exit:
-   return -ENODEV;
 }
 
 /*
-- 
2.20.1



[PATCH 10/10] staging: rtl8188eu: make rtw_usb_if1_init return a status

2021-04-07 Thread Martin Kaiser
Return an error status instead of the struct adapter that was allocated
and filled. This is more useful for the probe function, who calls
rtw_usb_if1_init.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 28 ++---
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 71ef7941f688..3a970d67aa8c 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -322,17 +322,17 @@ static int rtw_resume(struct usb_interface *pusb_intf)
  *We accept the new device by returning 0.
  */
 
-static struct adapter *rtw_usb_if1_init(struct usb_interface *pusb_intf)
+static int rtw_usb_if1_init(struct usb_interface *pusb_intf)
 {
struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
struct adapter *padapter;
struct net_device *pnetdev;
struct net_device *pmondev;
-   int status = _FAIL;
+   int err = 0;
 
pnetdev = rtw_init_netdev();
if (!pnetdev)
-   return NULL;
+   return -ENOMEM;
SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
 
padapter = netdev_priv(pnetdev);
@@ -352,6 +352,7 @@ static struct adapter *rtw_usb_if1_init(struct 
usb_interface *pusb_intf)
padapter->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
if (!padapter->HalData) {
DBG_88E("Failed to allocate memory for HAL data\n");
+   err = -ENOMEM;
goto free_adapter;
}
 
@@ -368,6 +369,7 @@ static struct adapter *rtw_usb_if1_init(struct 
usb_interface *pusb_intf)
if (rtw_init_drv_sw(padapter) == _FAIL) {
RT_TRACE(_module_hci_intfs_c_, _drv_err_,
 ("Initialize driver software resource Failed!\n"));
+   err = -ENOMEM;
goto free_hal_data;
}
 
@@ -397,7 +399,8 @@ static struct adapter *rtw_usb_if1_init(struct 
usb_interface *pusb_intf)
 pnetdev->dev_addr);
 
/* step 6. Tell the network stack we exist */
-   if (register_netdev(pnetdev) != 0) {
+   err = register_netdev(pnetdev);
+   if (err) {
RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("register_netdev() 
failed\n"));
goto free_hal_data;
}
@@ -409,17 +412,13 @@ static struct adapter *rtw_usb_if1_init(struct 
usb_interface *pusb_intf)
, padapter->hw_init_completed
);
 
-   status = _SUCCESS;
+   return 0;
 
 free_hal_data:
-   if (status != _SUCCESS)
-   kfree(padapter->HalData);
+   kfree(padapter->HalData);
 free_adapter:
-   if (status != _SUCCESS) {
-   free_netdev(pnetdev);
-   padapter = NULL;
-   }
-   return padapter;
+   free_netdev(pnetdev);
+   return err;
 }
 
 static void rtw_usb_if1_deinit(struct adapter *if1)
@@ -458,10 +457,11 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, 
const struct usb_device
return err;
}
 
-   if (!rtw_usb_if1_init(pusb_intf)) {
+   err = rtw_usb_if1_init(pusb_intf);
+   if (err) {
pr_debug("rtw_usb_if1_init failed\n");
usb_dvobj_deinit(pusb_intf);
-   return -ENODEV;
+   return err;
}
 
return 0;
-- 
2.20.1



[PATCH 08/10] staging: rtl8188eu: rtw_usb_if1_init needs no dvobj parameter

2021-04-07 Thread Martin Kaiser
rtw_usb_if1_init receives a pointer to struct usb_interface. dvobj is the
interface data for this interface.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index f173db5e7db9..301dab65b571 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -322,9 +322,9 @@ static int rtw_resume(struct usb_interface *pusb_intf)
  *We accept the new device by returning 0.
  */
 
-static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
-   struct usb_interface *pusb_intf)
+static struct adapter *rtw_usb_if1_init(struct usb_interface *pusb_intf)
 {
+   struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
struct adapter *padapter;
struct net_device *pnetdev;
struct net_device *pmondev;
@@ -460,7 +460,7 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, 
const struct usb_device
goto exit;
}
 
-   if (!rtw_usb_if1_init(dvobj, pusb_intf)) {
+   if (!rtw_usb_if1_init(pusb_intf)) {
pr_debug("rtw_usb_if1_init failed\n");
goto free_dvobj;
}
-- 
2.20.1



[PATCH 06/10] staging: rtl8188eu: clean up rtw_recv_entry

2021-04-07 Thread Martin Kaiser
Change the return type to int, the function returns 0 or 1.
Remove the goto statement, we're not doing any cleanup on exit.
Summarize variable declarations and assignments.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 23 +++
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c 
b/drivers/staging/rtl8188eu/core/rtw_recv.c
index b9b4bc435037..b2fe448d999d 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -1962,27 +1962,18 @@ static int recv_func(struct adapter *padapter, struct 
recv_frame *rframe)
return ret;
 }
 
-s32 rtw_recv_entry(struct recv_frame *precvframe)
+int rtw_recv_entry(struct recv_frame *precvframe)
 {
-   struct adapter *padapter;
-   struct recv_priv *precvpriv;
-   s32 ret = _SUCCESS;
-
-   padapter = precvframe->adapter;
-
-   precvpriv = >recvpriv;
+   struct adapter *padapter = precvframe->adapter;
+   struct recv_priv *precvpriv = >recvpriv;
+   int ret;
 
ret = recv_func(padapter, precvframe);
-   if (ret == _FAIL) {
+   if (ret == _SUCCESS)
+   precvpriv->rx_pkts++;
+   else
RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("%s: recv_func 
return fail!!!\n", __func__));
-   goto _recv_entry_drop;
-   }
-
-   precvpriv->rx_pkts++;
-
-   return ret;
 
-_recv_entry_drop:
return ret;
 }
 
-- 
2.20.1



[PATCH 07/10] staging: rtl8188eu: remove unnecessary variable

2021-04-07 Thread Martin Kaiser
We just want to check if rtw_usb_if1_init returns NULL, which means there
was an error.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index fba0af36d302..f173db5e7db9 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -450,7 +450,6 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
 
 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct 
usb_device_id *pdid)
 {
-   struct adapter *if1 = NULL;
struct dvobj_priv *dvobj;
 
/* Initialize dvobj_priv */
@@ -461,9 +460,8 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, 
const struct usb_device
goto exit;
}
 
-   if1 = rtw_usb_if1_init(dvobj, pusb_intf);
-   if (!if1) {
-   pr_debug("rtw_init_primarystruct adapter Failed!\n");
+   if (!rtw_usb_if1_init(dvobj, pusb_intf)) {
+   pr_debug("rtw_usb_if1_init failed\n");
goto free_dvobj;
}
 
-- 
2.20.1



[PATCH 05/10] staging: rtl8188eu: set pipe only once

2021-04-07 Thread Martin Kaiser
Set the pipe for reading or writing in usbctrl_vendorreq only once. There's
no need to set it again for every retry.

Signed-off-by: Martin Kaiser 
---
 .../staging/rtl8188eu/os_dep/usb_ops_linux.c  | 22 ++-
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 13d2733b2b1b..f2fa4fb3595f 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -249,18 +249,20 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, void 
*pdata, u16 len, u8 req
goto release_mutex;
}
 
-   while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) {
-   memset(pIo_buf, 0, len);
+   if (reqtype == REALTEK_USB_VENQT_READ) {
+   pipe = usb_rcvctrlpipe(udev, 0);
+   } else if (reqtype == REALTEK_USB_VENQT_WRITE) {
+   pipe = usb_sndctrlpipe(udev, 0);
+   } else {
+   status = -EINVAL;
+   goto free_buf;
+   }
 
-   if (reqtype == REALTEK_USB_VENQT_READ) {
-   pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
-   } else if (reqtype == REALTEK_USB_VENQT_WRITE) {
-   pipe = usb_sndctrlpipe(udev, 0);/* write_out */
+   while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) {
+   if (reqtype == REALTEK_USB_VENQT_READ)
+   memset(pIo_buf, 0, len);
+   else
memcpy(pIo_buf, pdata, len);
-   } else {
-   status = -EINVAL;
-   goto free_buf;
-   }
 
status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
 reqtype, value, 
REALTEK_USB_VENQT_CMD_IDX,
-- 
2.20.1



[PATCH 04/10] staging: rtl8188eu: move defines into the .c file

2021-04-07 Thread Martin Kaiser
Some of the defines from usb_ops_linux.h are used only inside
usb_ops_linux.c. Move them to the .c file.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/usb_ops_linux.h | 8 
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c  | 8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index 36a53239d5df..2f4976d251a1 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -7,14 +7,6 @@
 #ifndef __USB_OPS_LINUX_H__
 #define __USB_OPS_LINUX_H__
 
-#define RTW_USB_CONTROL_MSG_TIMEOUT500/* ms */
-
-#define MAX_USBCTRL_VENDORREQ_TIMES10
-
-#define ALIGNMENT_UNIT 16
-#define MAX_VENDOR_REQ_CMD_SIZE254 /* 8188cu SIE Support */
-#define MAX_USB_IO_CTL_SIZE(MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
-
 #define USB_HIGH_SPEED_BULK_SIZE   512
 #define USB_FULL_SPEED_BULK_SIZE   64
 
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 74f34440fc8c..13d2733b2b1b 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -10,6 +10,14 @@
 #include 
 #include 
 
+#define RTW_USB_CONTROL_MSG_TIMEOUT500 /* ms */
+
+#define MAX_USBCTRL_VENDORREQ_TIMES10
+
+#define ALIGNMENT_UNIT 16
+#define MAX_VENDOR_REQ_CMD_SIZE254
+#define MAX_USB_IO_CTL_SIZE(MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
+
 #define REALTEK_USB_VENQT_READ (USB_DIR_IN | USB_TYPE_VENDOR | 
USB_RECIP_DEVICE)
 #define REALTEK_USB_VENQT_WRITE(USB_DIR_OUT | USB_TYPE_VENDOR | 
USB_RECIP_DEVICE)
 
-- 
2.20.1



[PATCH 03/10] staging: rtl8188eu: remove unused defines

2021-04-07 Thread Martin Kaiser
Some defines in usb_ops_linux.h are not used by the rtl8188eu driver.
Remove them.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/usb_ops_linux.h | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index 1a0b38de5027..36a53239d5df 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -7,15 +7,10 @@
 #ifndef __USB_OPS_LINUX_H__
 #define __USB_OPS_LINUX_H__
 
-#define VENDOR_CMD_MAX_DATA_LEN254
-
-#define RTW_USB_CONTROL_MSG_TIMEOUT_TEST   10/* ms */
 #define RTW_USB_CONTROL_MSG_TIMEOUT500/* ms */
 
 #define MAX_USBCTRL_VENDORREQ_TIMES10
 
-#define RTW_USB_BULKOUT_TIME   5000/* ms */
-
 #define ALIGNMENT_UNIT 16
 #define MAX_VENDOR_REQ_CMD_SIZE254 /* 8188cu SIE Support */
 #define MAX_USB_IO_CTL_SIZE(MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
-- 
2.20.1



[PATCH 02/10] staging: rtl8188eu: remove unnecessary brackets

2021-04-07 Thread Martin Kaiser
ESHUTDOWN is just a number, it needs no brackets.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 8e9fd9d4afda..74f34440fc8c 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -267,7 +267,7 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, void 
*pdata, u16 len, u8 req
len, status, *(u32 *)pdata, vendorreq_times);
 
if (status < 0) {
-   if (status == (-ESHUTDOWN) || status == -ENODEV)
+   if (status == -ESHUTDOWN || status == -ENODEV)
adapt->bSurpriseRemoved = true;
else

adapt->HalData->srestpriv.wifi_error_status = USB_VEN_REQ_CMD_FAIL;
-- 
2.20.1



[PATCH 01/10] staging: rtl8188eu: remove unused macros

2021-04-07 Thread Martin Kaiser
usb_ops_linux.h contains a couple of macros to make functions usable as
urb completion callbacks. Most of them are unused and can be removed.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/include/usb_ops_linux.h | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index 4e0e48cb5c8e..1a0b38de5027 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -23,18 +23,10 @@
 #define USB_HIGH_SPEED_BULK_SIZE   512
 #define USB_FULL_SPEED_BULK_SIZE   64
 
-#define _usbctrl_vendorreq_async_callback(urb, regs)   \
-   _usbctrl_vendorreq_async_callback(urb)
-#define usb_bulkout_zero_complete(purb, regs)  \
-   usb_bulkout_zero_complete(purb)
-#define usb_write_mem_complete(purb, regs) \
-   usb_write_mem_complete(purb)
 #define usb_write_port_complete(purb, regs)\
usb_write_port_complete(purb)
 #define usb_read_port_complete(purb, regs) \
usb_read_port_complete(purb)
-#define usb_read_interrupt_complete(purb, regs)\
-   usb_read_interrupt_complete(purb)
 
 unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr);
 
-- 
2.20.1



[PATCH 11/11] staging: rtl8188eu: remove an obsolete comment

2021-04-06 Thread Martin Kaiser
This driver does not set URB_ZERO_PACKET.

The rtl8188eu driver that's available from Realtek/Edimax has some
commented-out code that sets zero packet. It was removed from this
driver before it was imported.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index bb5889a130ca..8e9fd9d4afda 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -677,8 +677,6 @@ u32 usb_write_port(struct adapter *padapter, u32 addr, u32 
cnt, struct xmit_buf
 
ret = _SUCCESS;
 
-/*We add the URB_ZERO_PACKET flag to urb so that the host will send the 
zero packet automatically. */
-
RT_TRACE(_module_hci_ops_os_c_, _drv_err_, ("-%s\n", __func__));
 
 exit:
-- 
2.20.1



[PATCH 09/11] staging: rtl8188eu: clean up usb_write16

2021-04-06 Thread Martin Kaiser
Remove unnecessary variable, summarize declaration and assignment.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index e2ff4f70610e..9d0c34f6a86c 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -495,16 +495,10 @@ int usb_write8(struct adapter *adapter, u32 addr, u8 val)
 
 int usb_write16(struct adapter *adapter, u32 addr, u16 val)
 {
-   u16 wvalue;
-   u16 len;
-   __le32 data;
-
-   wvalue = (u16)(addr & 0x);
-   len = 2;
-
-   data = cpu_to_le32(val & 0x);
+   u16 wvalue = (u16)(addr & 0x);
+   __le32 data = cpu_to_le32(val & 0x);
 
-   return usbctrl_vendorreq(adapter, wvalue, , len, 
REALTEK_USB_VENQT_WRITE);
+   return usbctrl_vendorreq(adapter, wvalue, , 2, 
REALTEK_USB_VENQT_WRITE);
 }
 
 int usb_write32(struct adapter *adapter, u32 addr, u32 val)
-- 
2.20.1



[PATCH 10/11] staging: rtl8188eu: clean up usb_write32

2021-04-06 Thread Martin Kaiser
Remove unnecessary variable, summarize declaration and assignment.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 9d0c34f6a86c..bb5889a130ca 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -503,15 +503,10 @@ int usb_write16(struct adapter *adapter, u32 addr, u16 
val)
 
 int usb_write32(struct adapter *adapter, u32 addr, u32 val)
 {
-   u16 wvalue;
-   u16 len;
-   __le32 data;
-
-   wvalue = (u16)(addr & 0x);
-   len = 4;
-   data = cpu_to_le32(val);
+   u16 wvalue = (u16)(addr & 0x);
+   __le32 data = cpu_to_le32(val);
 
-   return usbctrl_vendorreq(adapter, wvalue, , len, 
REALTEK_USB_VENQT_WRITE);
+   return usbctrl_vendorreq(adapter, wvalue, , 4, 
REALTEK_USB_VENQT_WRITE);
 }
 
 static void usb_write_port_complete(struct urb *purb, struct pt_regs *regs)
-- 
2.20.1



[PATCH 08/11] staging: rtl8188eu: clean up usb_write8

2021-04-06 Thread Martin Kaiser
Remove unnecessary variable, summarize declaration and assignment.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index beab5343fda8..e2ff4f70610e 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -487,14 +487,10 @@ void rtw_hal_inirp_deinit(struct adapter *padapter)
 
 int usb_write8(struct adapter *adapter, u32 addr, u8 val)
 {
-   u16 wvalue;
-   u16 len;
-   u8 data;
+   u16 wvalue = (u16)(addr & 0x);
+   u8 data = val;
 
-   wvalue = (u16)(addr & 0x);
-   len = 1;
-   data = val;
-   return usbctrl_vendorreq(adapter, wvalue, , len, 
REALTEK_USB_VENQT_WRITE);
+   return usbctrl_vendorreq(adapter, wvalue, , 1, 
REALTEK_USB_VENQT_WRITE);
 }
 
 int usb_write16(struct adapter *adapter, u32 addr, u16 val)
-- 
2.20.1



[PATCH 07/11] staging: rtl8188eu: clean up usb_read32

2021-04-06 Thread Martin Kaiser
Remove unnecessary variable, summarize declaration and assignment.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 915bf86237b0..beab5343fda8 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -316,14 +316,10 @@ u16 usb_read16(struct adapter *adapter, u32 addr)
 
 u32 usb_read32(struct adapter *adapter, u32 addr)
 {
-   u16 wvalue;
-   u16 len;
+   u16 wvalue = (u16)(addr & 0x);
__le32 data;
 
-   wvalue = (u16)(addr & 0x);
-   len = 4;
-
-   usbctrl_vendorreq(adapter, wvalue, , len, REALTEK_USB_VENQT_READ);
+   usbctrl_vendorreq(adapter, wvalue, , 4, REALTEK_USB_VENQT_READ);
 
return le32_to_cpu(data);
 }
-- 
2.20.1



[PATCH 06/11] staging: rtl8188eu: clean up usb_read16

2021-04-06 Thread Martin Kaiser
Remove unnecessary variable, summarize declaration and assignment.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 0172405c815e..915bf86237b0 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -306,13 +306,10 @@ u8 usb_read8(struct adapter *adapter, u32 addr)
 
 u16 usb_read16(struct adapter *adapter, u32 addr)
 {
-   u16 wvalue;
-   u16 len;
+   u16 wvalue = (u16)(addr & 0x);
__le32 data;
 
-   wvalue = (u16)(addr & 0x);
-   len = 2;
-   usbctrl_vendorreq(adapter, wvalue, , len, REALTEK_USB_VENQT_READ);
+   usbctrl_vendorreq(adapter, wvalue, , 2, REALTEK_USB_VENQT_READ);
 
return (u16)(le32_to_cpu(data) & 0x);
 }
-- 
2.20.1



[PATCH 05/11] staging: rtl8188eu: clean up usb_read8

2021-04-06 Thread Martin Kaiser
Remove unnecessary variable, summarize declaration and assignment.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 205a15dd67a5..0172405c815e 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -296,14 +296,10 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, void 
*pdata, u16 len, u8 req
 
 u8 usb_read8(struct adapter *adapter, u32 addr)
 {
-   u16 wvalue;
-   u16 len;
-   u8 data = 0;
-
-   wvalue = (u16)(addr & 0x);
-   len = 1;
+   u16 wvalue = (u16)(addr & 0x);
+   u8 data;
 
-   usbctrl_vendorreq(adapter, wvalue, , len, REALTEK_USB_VENQT_READ);
+   usbctrl_vendorreq(adapter, wvalue, , 1, REALTEK_USB_VENQT_READ);
 
return data;
 }
-- 
2.20.1



[PATCH 02/11] staging: rtl8188eu: ctrl vendor req value is always 0x05

2021-04-06 Thread Martin Kaiser
The bRequest value for the vendor specific control requests sent by this
driver is always 0x05. Replace the function parameter with a define. Use
the same define as the rtlwifi driver.

Signed-off-by: Martin Kaiser 
---
 .../staging/rtl8188eu/os_dep/usb_ops_linux.c  | 32 +++
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index 6926443bba4e..bf57a91cc40d 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -10,6 +10,8 @@
 #include 
 #include 
 
+#define REALTEK_USB_VENQT_CMD_REQ  0x05
+
 static void interrupt_handler_8188eu(struct adapter *adapt, u16 pkt_len, u8 
*pbuf)
 {
struct hal_data_8188e *haldata = adapt->HalData;
@@ -198,7 +200,8 @@ unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 
addr)
return pipe;
 }
 
-static int usbctrl_vendorreq(struct adapter *adapt, u8 request, u16 value, u16 
index, void *pdata, u16 len, u8 requesttype)
+static int
+usbctrl_vendorreq(struct adapter *adapt, u16 value, u16 index, void *pdata, 
u16 len, u8 requesttype)
 {
struct dvobj_priv *dvobjpriv = adapter_to_dvobj(adapt);
struct usb_device *udev = dvobjpriv->pusbdev;
@@ -247,7 +250,8 @@ static int usbctrl_vendorreq(struct adapter *adapt, u8 
request, u16 value, u16 i
memcpy(pIo_buf, pdata, len);
}
 
-   status = usb_control_msg(udev, pipe, request, reqtype, value, 
index, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
+   status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+reqtype, value, index, pIo_buf, len, 
RTW_USB_CONTROL_MSG_TIMEOUT);
 
if (status == len) {   /*  Success this control transfer. */
if (requesttype == 0x01)
@@ -286,61 +290,55 @@ static int usbctrl_vendorreq(struct adapter *adapt, u8 
request, u16 value, u16 i
 
 u8 usb_read8(struct adapter *adapter, u32 addr)
 {
-   u8 request;
u8 requesttype;
u16 wvalue;
u16 index;
u16 len;
u8 data = 0;
 
-   request = 0x05;
requesttype = 0x01;/* read_in */
index = 0;/* n/a */
 
wvalue = (u16)(addr & 0x);
len = 1;
 
-   usbctrl_vendorreq(adapter, request, wvalue, index, , len, 
requesttype);
+   usbctrl_vendorreq(adapter, wvalue, index, , len, requesttype);
 
return data;
 }
 
 u16 usb_read16(struct adapter *adapter, u32 addr)
 {
-   u8 request;
u8 requesttype;
u16 wvalue;
u16 index;
u16 len;
__le32 data;
 
-   request = 0x05;
requesttype = 0x01;/* read_in */
index = 0;/* n/a */
wvalue = (u16)(addr & 0x);
len = 2;
-   usbctrl_vendorreq(adapter, request, wvalue, index, , len, 
requesttype);
+   usbctrl_vendorreq(adapter, wvalue, index, , len, requesttype);
 
return (u16)(le32_to_cpu(data) & 0x);
 }
 
 u32 usb_read32(struct adapter *adapter, u32 addr)
 {
-   u8 request;
u8 requesttype;
u16 wvalue;
u16 index;
u16 len;
__le32 data;
 
-   request = 0x05;
requesttype = 0x01;/* read_in */
index = 0;/* n/a */
 
wvalue = (u16)(addr & 0x);
len = 4;
 
-   usbctrl_vendorreq(adapter, request, wvalue, index, , len, 
requesttype);
+   usbctrl_vendorreq(adapter, wvalue, index, , len, requesttype);
 
return le32_to_cpu(data);
 }
@@ -508,33 +506,29 @@ void rtw_hal_inirp_deinit(struct adapter *padapter)
 
 int usb_write8(struct adapter *adapter, u32 addr, u8 val)
 {
-   u8 request;
u8 requesttype;
u16 wvalue;
u16 index;
u16 len;
u8 data;
 
-   request = 0x05;
requesttype = 0x00;/* write_out */
index = 0;/* n/a */
wvalue = (u16)(addr & 0x);
len = 1;
data = val;
-   return usbctrl_vendorreq(adapter, request, wvalue,
+   return usbctrl_vendorreq(adapter, wvalue,
 index, , len, requesttype);
 }
 
 int usb_write16(struct adapter *adapter, u32 addr, u16 val)
 {
-   u8 request;
u8 requesttype;
u16 wvalue;
u16 index;
u16 len;
__le32 data;
 
-   request = 0x05;
requesttype = 0x00;/* write_out */
index = 0;/* n/a */
 
@@ -543,20 +537,18 @@ int usb_write16(struct adapter *adapter, u32 addr, u16 
val)
 
data = cpu_to_le32(val & 0x);
 
-   return usbctrl_vendorreq(adapter, request, wvalue,
+   return usbctrl_vendorreq(adapter, wvalue,
 index, , len, requesttype);
 }
 
 int usb_write32(struct adapter *adapter, u32 addr, u32 val)
 {
-   u8 request;
u8 requesttype;
u16 wvalue;
u16 index;
 

[PATCH 04/11] staging: rtl8188eu: use actual request type as parameter

2021-04-06 Thread Martin Kaiser
At the moment, usbctrl_vendorreq's requesttype parameter must be set to 1
for reading and 0 for writing. It's then converted to the actual
bmRequestType for the USB control request. We can simplify the code and
avoid this conversion if the caller passes the actual bmRequestType.

We already have defines for the read and write request types. Move them to
usb_ops_linux.c, they're used only inside this file. Replace the numeric
values with USB constants to make their meaning clearer.

Signed-off-by: Martin Kaiser 
---
 .../staging/rtl8188eu/include/usb_ops_linux.h |  3 --
 .../staging/rtl8188eu/os_dep/usb_ops_linux.c  | 52 +++
 2 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/usb_ops_linux.h 
b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
index 70d729742839..4e0e48cb5c8e 100644
--- a/drivers/staging/rtl8188eu/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8188eu/include/usb_ops_linux.h
@@ -16,9 +16,6 @@
 
 #define RTW_USB_BULKOUT_TIME   5000/* ms */
 
-#define REALTEK_USB_VENQT_READ 0xC0
-#define REALTEK_USB_VENQT_WRITE0x40
-
 #define ALIGNMENT_UNIT 16
 #define MAX_VENDOR_REQ_CMD_SIZE254 /* 8188cu SIE Support */
 #define MAX_USB_IO_CTL_SIZE(MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index b760636f03d3..205a15dd67a5 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -10,6 +10,9 @@
 #include 
 #include 
 
+#define REALTEK_USB_VENQT_READ (USB_DIR_IN | USB_TYPE_VENDOR | 
USB_RECIP_DEVICE)
+#define REALTEK_USB_VENQT_WRITE(USB_DIR_OUT | USB_TYPE_VENDOR | 
USB_RECIP_DEVICE)
+
 #define REALTEK_USB_VENQT_CMD_REQ  0x05
 #define REALTEK_USB_VENQT_CMD_IDX  0x00
 
@@ -202,13 +205,12 @@ unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, 
u32 addr)
 }
 
 static int
-usbctrl_vendorreq(struct adapter *adapt, u16 value, void *pdata, u16 len, u8 
requesttype)
+usbctrl_vendorreq(struct adapter *adapt, u16 value, void *pdata, u16 len, u8 
reqtype)
 {
struct dvobj_priv *dvobjpriv = adapter_to_dvobj(adapt);
struct usb_device *udev = dvobjpriv->pusbdev;
unsigned int pipe;
int status = 0;
-   u8 reqtype;
u8 *pIo_buf;
int vendorreq_times = 0;
 
@@ -242,13 +244,14 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, void 
*pdata, u16 len, u8 req
while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) {
memset(pIo_buf, 0, len);
 
-   if (requesttype == 0x01) {
+   if (reqtype == REALTEK_USB_VENQT_READ) {
pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
-   reqtype =  REALTEK_USB_VENQT_READ;
-   } else {
+   } else if (reqtype == REALTEK_USB_VENQT_WRITE) {
pipe = usb_sndctrlpipe(udev, 0);/* write_out */
-   reqtype =  REALTEK_USB_VENQT_WRITE;
memcpy(pIo_buf, pdata, len);
+   } else {
+   status = -EINVAL;
+   goto free_buf;
}
 
status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
@@ -256,11 +259,11 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, void 
*pdata, u16 len, u8 req
 pIo_buf, len, 
RTW_USB_CONTROL_MSG_TIMEOUT);
 
if (status == len) {   /*  Success this control transfer. */
-   if (requesttype == 0x01)
+   if (reqtype == REALTEK_USB_VENQT_READ)
memcpy(pdata, pIo_buf,  len);
} else { /*  error cases */
DBG_88E("reg 0x%x, usb %s %u fail, status:%d 
value=0x%x, vendorreq_times:%d\n",
-   value, (requesttype == 0x01) ? "read" : "write",
+   value, (reqtype == REALTEK_USB_VENQT_READ) ? 
"read" : "write",
len, status, *(u32 *)pdata, vendorreq_times);
 
if (status < 0) {
@@ -270,7 +273,7 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, void 
*pdata, u16 len, u8 req

adapt->HalData->srestpriv.wifi_error_status = USB_VEN_REQ_CMD_FAIL;
} else { /*  status != len && status >= 0 */
if (status > 0) {
-   if (requesttype == 0x01) {
+   if (reqtype == REALTEK_USB_VENQT_READ) {
/*  For Control read transfer, 
we have to copy the read data from pIo_buf to pdata. */
me

[PATCH 03/11] staging: rtl8188eu: ctrl vendor req index is not used

2021-04-06 Thread Martin Kaiser
The index for rtl8188eu's vendor-specific control requests is not used.
Remove the index parameter from usbctrl_vendorreq and pass index 0 to
usb_control_msg.

Signed-off-by: Martin Kaiser 
---
 .../staging/rtl8188eu/os_dep/usb_ops_linux.c  | 33 ++-
 1 file changed, 10 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c 
b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index bf57a91cc40d..b760636f03d3 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -11,6 +11,7 @@
 #include 
 
 #define REALTEK_USB_VENQT_CMD_REQ  0x05
+#define REALTEK_USB_VENQT_CMD_IDX  0x00
 
 static void interrupt_handler_8188eu(struct adapter *adapt, u16 pkt_len, u8 
*pbuf)
 {
@@ -201,7 +202,7 @@ unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 
addr)
 }
 
 static int
-usbctrl_vendorreq(struct adapter *adapt, u16 value, u16 index, void *pdata, 
u16 len, u8 requesttype)
+usbctrl_vendorreq(struct adapter *adapt, u16 value, void *pdata, u16 len, u8 
requesttype)
 {
struct dvobj_priv *dvobjpriv = adapter_to_dvobj(adapt);
struct usb_device *udev = dvobjpriv->pusbdev;
@@ -251,7 +252,8 @@ usbctrl_vendorreq(struct adapter *adapt, u16 value, u16 
index, void *pdata, u16
}
 
status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
-reqtype, value, index, pIo_buf, len, 
RTW_USB_CONTROL_MSG_TIMEOUT);
+reqtype, value, 
REALTEK_USB_VENQT_CMD_IDX,
+pIo_buf, len, 
RTW_USB_CONTROL_MSG_TIMEOUT);
 
if (status == len) {   /*  Success this control transfer. */
if (requesttype == 0x01)
@@ -292,17 +294,15 @@ u8 usb_read8(struct adapter *adapter, u32 addr)
 {
u8 requesttype;
u16 wvalue;
-   u16 index;
u16 len;
u8 data = 0;
 
requesttype = 0x01;/* read_in */
-   index = 0;/* n/a */
 
wvalue = (u16)(addr & 0x);
len = 1;
 
-   usbctrl_vendorreq(adapter, wvalue, index, , len, requesttype);
+   usbctrl_vendorreq(adapter, wvalue, , len, requesttype);
 
return data;
 }
@@ -311,15 +311,13 @@ u16 usb_read16(struct adapter *adapter, u32 addr)
 {
u8 requesttype;
u16 wvalue;
-   u16 index;
u16 len;
__le32 data;
 
requesttype = 0x01;/* read_in */
-   index = 0;/* n/a */
wvalue = (u16)(addr & 0x);
len = 2;
-   usbctrl_vendorreq(adapter, wvalue, index, , len, requesttype);
+   usbctrl_vendorreq(adapter, wvalue, , len, requesttype);
 
return (u16)(le32_to_cpu(data) & 0x);
 }
@@ -328,17 +326,15 @@ u32 usb_read32(struct adapter *adapter, u32 addr)
 {
u8 requesttype;
u16 wvalue;
-   u16 index;
u16 len;
__le32 data;
 
requesttype = 0x01;/* read_in */
-   index = 0;/* n/a */
 
wvalue = (u16)(addr & 0x);
len = 4;
 
-   usbctrl_vendorreq(adapter, wvalue, index, , len, requesttype);
+   usbctrl_vendorreq(adapter, wvalue, , len, requesttype);
 
return le32_to_cpu(data);
 }
@@ -508,56 +504,47 @@ int usb_write8(struct adapter *adapter, u32 addr, u8 val)
 {
u8 requesttype;
u16 wvalue;
-   u16 index;
u16 len;
u8 data;
 
requesttype = 0x00;/* write_out */
-   index = 0;/* n/a */
wvalue = (u16)(addr & 0x);
len = 1;
data = val;
-   return usbctrl_vendorreq(adapter, wvalue,
-index, , len, requesttype);
+   return usbctrl_vendorreq(adapter, wvalue, , len, requesttype);
 }
 
 int usb_write16(struct adapter *adapter, u32 addr, u16 val)
 {
u8 requesttype;
u16 wvalue;
-   u16 index;
u16 len;
__le32 data;
 
requesttype = 0x00;/* write_out */
-   index = 0;/* n/a */
 
wvalue = (u16)(addr & 0x);
len = 2;
 
data = cpu_to_le32(val & 0x);
 
-   return usbctrl_vendorreq(adapter, wvalue,
-index, , len, requesttype);
+   return usbctrl_vendorreq(adapter, wvalue, , len, requesttype);
 }
 
 int usb_write32(struct adapter *adapter, u32 addr, u32 val)
 {
u8 requesttype;
u16 wvalue;
-   u16 index;
u16 len;
__le32 data;
 
requesttype = 0x00;/* write_out */
-   index = 0;/* n/a */
 
wvalue = (u16)(addr & 0x);
len = 4;
data = cpu_to_le32(val);
 
-   return usbctrl_vendorreq(adapter, wvalue,
-index, , len, requesttype);
+   return usbctrl_vendorreq(adapter, wvalue, , len, requesttype);
 }
 
 static void usb_write_port_complete(struct urb *purb, struct pt_regs *regs)
-- 
2.20.1



[PATCH 01/11] staging: rtl8188eu: remove unused efuse hal components

2021-04-06 Thread Martin Kaiser
struct hal_data_8188e contains some components related to efuses which
are not used for rtl8188eu.

Signed-off-by: Martin Kaiser 
---
 .../staging/rtl8188eu/include/rtl8188e_hal.h  |  4 
 drivers/staging/rtl8188eu/include/rtw_efuse.h | 20 ---
 2 files changed, 24 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/rtl8188e_hal.h 
b/drivers/staging/rtl8188eu/include/rtl8188e_hal.h
index 6035c12ec578..0c4c23be1dd5 100644
--- a/drivers/staging/rtl8188eu/include/rtl8188e_hal.h
+++ b/drivers/staging/rtl8188eu/include/rtl8188e_hal.h
@@ -211,10 +211,6 @@ struct hal_data_8188e {
u8  bAPKThermalMeterIgnore;
 
boolEepromOrEfuse;
-   /* 92C:256bytes, 88E:512bytes, we use union set (512bytes) */
-   u8  EfuseMap[2][HWSET_MAX_SIZE_512];
-   u8  EfuseUsedPercentage;
-   struct efuse_halEfuseHal;
 
u8  Index24G_CCK_Base[MAX_RF_PATH][CHANNEL_MAX_NUMBER];
u8  Index24G_BW40_Base[MAX_RF_PATH][CHANNEL_MAX_NUMBER];
diff --git a/drivers/staging/rtl8188eu/include/rtw_efuse.h 
b/drivers/staging/rtl8188eu/include/rtw_efuse.h
index 5926fc9b5e6b..74182c32c4ec 100644
--- a/drivers/staging/rtl8188eu/include/rtw_efuse.h
+++ b/drivers/staging/rtl8188eu/include/rtw_efuse.h
@@ -56,26 +56,6 @@ struct pgpkt {
u8 word_cnts;
 };
 
-/*--Define structure*/
-struct efuse_hal {
-   u8 fakeEfuseBank;
-   u32 fakeEfuseUsedBytes;
-   u8 fakeEfuseContent[EFUSE_MAX_HW_SIZE];
-   u8 fakeEfuseInitMap[EFUSE_MAX_MAP_LEN];
-   u8 fakeEfuseModifiedMap[EFUSE_MAX_MAP_LEN];
-
-   u16 BTEfuseUsedBytes;
-   u8 BTEfuseUsedPercentage;
-   u8 BTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
-   u8 BTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN];
-   u8 BTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN];
-
-   u16 fakeBTEfuseUsedBytes;
-   u8 fakeBTEfuseContent[EFUSE_MAX_BT_BANK][EFUSE_MAX_HW_SIZE];
-   u8 fakeBTEfuseInitMap[EFUSE_BT_MAX_MAP_LEN];
-   u8 fakeBTEfuseModifiedMap[EFUSE_BT_MAX_MAP_LEN];
-};
-
 u8 Efuse_CalculateWordCnts(u8 word_en);
 u8 efuse_OneByteRead(struct adapter *adapter, u16 addr, u8 *data);
 u8 efuse_OneByteWrite(struct adapter *adapter, u16 addr, u8 data);
-- 
2.20.1



[PATCH] staging: rtl8723bs: remove unused dvobj_priv members

2021-04-05 Thread Martin Kaiser
InterfaceNumber und NumInterfaces in struct dvobj_priv are not used.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8723bs/include/drv_types.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/staging/rtl8723bs/include/drv_types.h 
b/drivers/staging/rtl8723bs/include/drv_types.h
index a454a6390537..cec8d5ac0e2e 100644
--- a/drivers/staging/rtl8723bs/include/drv_types.h
+++ b/drivers/staging/rtl8723bs/include/drv_types.h
@@ -295,10 +295,6 @@ struct dvobj_priv {
struct cam_ctl_t cam_ctl;
struct cam_entry_cache cam_cache[TOTAL_CAM_ENTRY];
 
-   /* For 92D, DMDP have 2 interface. */
-   u8 InterfaceNumber;
-   u8 NumInterfaces;
-
/* In /Out Pipe information */
int RtInPipe[2];
int RtOutPipe[4];
-- 
2.20.1



[PATCH v2] staging: rtl8188eu: (trivial) remove a duplicate debug print

2021-03-29 Thread Martin Kaiser
Keep the one that shows the wakeup capability.

Signed-off-by: Martin Kaiser 
---
v2:
 - fix the subject line

 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 91a3d34a1050..e18f1fff59ca 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -377,7 +377,6 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv 
*dvobj,
dvobj->pusbdev->do_remote_wakeup = 1;
pusb_intf->needs_remote_wakeup = 1;
device_init_wakeup(_intf->dev, 1);
-   pr_debug("\n  
padapter->pwrctrlpriv.bSupportRemoteWakeup~~\n");
pr_debug("\n  
padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",
 device_may_wakeup(_intf->dev));
}
-- 
2.20.1



[PATCH] staging: rtl8188eu: remove unused function parameter

2021-03-28 Thread Martin Kaiser
rtw_usb_if1_init does not use its struct usb_device_id parameter.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index e18f1fff59ca..fba0af36d302 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -323,8 +323,7 @@ static int rtw_resume(struct usb_interface *pusb_intf)
  */
 
 static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
-   struct usb_interface *pusb_intf,
-   const struct usb_device_id *pdid)
+   struct usb_interface *pusb_intf)
 {
struct adapter *padapter;
struct net_device *pnetdev;
@@ -462,7 +461,7 @@ static int rtw_drv_init(struct usb_interface *pusb_intf, 
const struct usb_device
goto exit;
}
 
-   if1 = rtw_usb_if1_init(dvobj, pusb_intf, pdid);
+   if1 = rtw_usb_if1_init(dvobj, pusb_intf);
if (!if1) {
pr_debug("rtw_init_primarystruct adapter Failed!\n");
goto free_dvobj;
-- 
2.20.1



[PATCH] staging: rtl8188eu: (trivial) remove a duplicate comment

2021-03-28 Thread Martin Kaiser
Keep the one that shows the wakeup capability.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 91a3d34a1050..e18f1fff59ca 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -377,7 +377,6 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv 
*dvobj,
dvobj->pusbdev->do_remote_wakeup = 1;
pusb_intf->needs_remote_wakeup = 1;
device_init_wakeup(_intf->dev, 1);
-   pr_debug("\n  
padapter->pwrctrlpriv.bSupportRemoteWakeup~~\n");
pr_debug("\n  
padapter->pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",
 device_may_wakeup(_intf->dev));
}
-- 
2.20.1



Re: [PATCH][next] staging: rtl8188eu: Fix null pointer dereference on free_netdev call

2021-03-24 Thread Martin Kaiser
Hello Colin,

Thus wrote Colin King (colin.k...@canonical.com):

> From: Colin Ian King 

> An unregister_netdev call checks if pnetdev is null, hence a later
> call to free_netdev can potentially be passing a null pointer, causing
> a null pointer dereference. Avoid this by adding a null pointer check
> on pnetdev before calling free_netdev.

> Fixes: 1665c8fdffbb ("staging: rtl8188eu: use netdev routines for private 
> data")
> Signed-off-by: Colin Ian King 
> ---
>  drivers/staging/rtl8188eu/os_dep/usb_intf.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

> diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
> b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> index 518e9feb3f46..91a3d34a1050 100644
> --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> @@ -446,7 +446,8 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
>   pr_debug("+r871xu_dev_remove, hw_init_completed=%d\n",
>if1->hw_init_completed);
>   rtw_free_drv_sw(if1);
> - free_netdev(pnetdev);
> + if (pnetdev)
> + free_netdev(pnetdev);
>  }

>  static int rtw_drv_init(struct usb_interface *pusb_intf, const struct 
> usb_device_id *pdid)
> -- 
> 2.30.2

you're right. I removed the NULL check that was part of rtw_free_netdev.
Sorry for the mistake and thanks for your fix.

Reviewed-by: Martin Kaiser 

Best regards,
Martin


[PATCH] staging: rtl8188eu: use netdev routines for private data

2021-03-21 Thread Martin Kaiser
This driver implements its own routines to allocate, access and free the
private data of its net_device. Use the functionality from the networking
core instead.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/core/rtw_debug.c|  8 +-
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  |  2 +-
 drivers/staging/rtl8188eu/core/rtw_xmit.c |  5 +-
 .../staging/rtl8188eu/include/osdep_intf.h|  2 +-
 .../staging/rtl8188eu/include/osdep_service.h | 13 ---
 .../staging/rtl8188eu/os_dep/ioctl_linux.c| 88 +--
 drivers/staging/rtl8188eu/os_dep/os_intfs.c   | 22 +++--
 .../staging/rtl8188eu/os_dep/osdep_service.c  | 31 ---
 .../staging/rtl8188eu/os_dep/rtw_android.c|  6 +-
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   | 27 +++---
 drivers/staging/rtl8188eu/os_dep/xmit_linux.c |  2 +-
 11 files changed, 78 insertions(+), 128 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_debug.c 
b/drivers/staging/rtl8188eu/core/rtw_debug.c
index 11198d43a371..1060837fe463 100644
--- a/drivers/staging/rtl8188eu/core/rtw_debug.c
+++ b/drivers/staging/rtl8188eu/core/rtw_debug.c
@@ -33,7 +33,7 @@ int proc_set_write_reg(struct file *file, const char __user 
*buffer,
   unsigned long count, void *data)
 {
struct net_device *dev = data;
-   struct adapter *padapter = rtw_netdev_priv(dev);
+   struct adapter *padapter = netdev_priv(dev);
char tmp[32];
u32 addr, val, len;
 
@@ -75,7 +75,7 @@ int proc_get_read_reg(char *page, char **start,
  int *eof, void *data)
 {
struct net_device *dev = data;
-   struct adapter *padapter = rtw_netdev_priv(dev);
+   struct adapter *padapter = netdev_priv(dev);
 
int len = 0;
 
@@ -139,7 +139,7 @@ int proc_get_adapter_state(char *page, char **start,
   int *eof, void *data)
 {
struct net_device *dev = data;
-   struct adapter *padapter = rtw_netdev_priv(dev);
+   struct adapter *padapter = netdev_priv(dev);
int len = 0;
 
len += scnprintf(page + len, count - len, "bSurpriseRemoved=%d, 
bDriverStopped=%d\n",
@@ -155,7 +155,7 @@ int proc_get_best_channel(char *page, char **start,
  int *eof, void *data)
 {
struct net_device *dev = data;
-   struct adapter *padapter = rtw_netdev_priv(dev);
+   struct adapter *padapter = netdev_priv(dev);
struct mlme_ext_priv *pmlmeext = >mlmeextpriv;
int len = 0;
u32 i, best_channel_24G = 1, index_24G = 0;
diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 3848e695ac84..c3c1cf67cf7e 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -84,7 +84,7 @@ static int rtw_hw_resume(struct adapter *padapter)
pwrpriv->bips_processing = true;
rtw_reset_drv_sw(padapter);
 
-   if (ips_netdrv_open(rtw_netdev_priv(pnetdev)) != _SUCCESS) {
+   if (ips_netdrv_open(netdev_priv(pnetdev)) != _SUCCESS) {
mutex_unlock(>mutex_lock);
goto error_exit;
}
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c 
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 317355f830cb..ed81cbc5e191 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -44,7 +44,10 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
 
-   /*  We don't need to memset padapter->XXX to zero, because adapter is 
allocated by vzalloc(). */
+   /*
+* We don't need to memset padapter->XXX to zero because adapter is
+* allocated by alloc_etherdev_mq, which eventually calls kvzalloc.
+*/
 
spin_lock_init(>lock);
 
diff --git a/drivers/staging/rtl8188eu/include/osdep_intf.h 
b/drivers/staging/rtl8188eu/include/osdep_intf.h
index 5ee4ed995025..5012b9176526 100644
--- a/drivers/staging/rtl8188eu/include/osdep_intf.h
+++ b/drivers/staging/rtl8188eu/include/osdep_intf.h
@@ -23,7 +23,7 @@ void rtw_cancel_all_timer(struct adapter *padapter);
 
 int rtw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 
-struct net_device *rtw_init_netdev(struct adapter *padapter);
+struct net_device *rtw_init_netdev(void);
 u16 rtw_recv_select_queue(struct sk_buff *skb);
 
 int netdev_open(struct net_device *pnetdev);
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index 56e937b26407..efd0833e28c8 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -66,19 +66,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void _rtw_init_queue(struct __queue *pqueue);
 
-struct rtw_netdev_priv_indicator {
-   void *pr

[PATCH] staging: rtl8188eu: Add Edimax EW-7811UN V2 to device table

2021-02-04 Thread Martin Kaiser
The Edimax EW-7811UN V2 uses an RTL8188EU chipset and works with this
driver.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c 
b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 43ebd11b53fe..efad43d8e465 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -41,6 +41,7 @@ static const struct usb_device_id rtw_usb_id_tbl[] = {
{USB_DEVICE(0x2357, 0x0111)}, /* TP-Link TL-WN727N v5.21 */
{USB_DEVICE(0x2C4E, 0x0102)}, /* MERCUSYS MW150US v2 */
{USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */
+   {USB_DEVICE(0x7392, 0xb811)}, /* Edimax EW-7811UN V2 */
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0xffef)}, /* Rosewill RNX-N150NUB */
{}  /* Terminating entry */
 };
-- 
2.20.1



Re: [PATCH v2 0/3] Make fw_devlink=on more forgiving

2021-02-03 Thread Martin Kaiser
Thus wrote Geert Uytterhoeven (ge...@linux-m68k.org):

> > The property you are using is not a standard GPIO binding (-gpios,
> > gpio, gpios) and I'm not surprised it's not working. The gpio1 is
> > probably getting probe deferred and ends up running after "my_driver".

> So my_driver doesn't support deferred probe,

I know that the gpio definition in the device-tree is non-standard (and
should have been done differently).

Apart from this, the driver uses module_platform_driver_probe. My
understanding is that this prevents probe deferral.

Does this mean that from now on, a driver which requests a gpio must not
use module_platform_driver_probe?

Thanks,
Martin


Re: [PATCH v2 0/3] Make fw_devlink=on more forgiving

2021-02-03 Thread Martin Kaiser
Thus wrote Saravana Kannan (sarava...@google.com):

> > With modules disabled, the kernel boots but probe fails for some
> > (non-mainline) drivers in my tree.

> Thanks Martin!

> > All of those drivers have a gpio in
> > their device-tree node, such as

> > my_driver {
> >gpio_test1 = < 0 0>;
> >...
> > };

> > with gpio1 from arch/arm/boot/dts/imx25.dtsi.

> > The probe function calls

> > of_get_named_gpio(np, "gpio_test1", 0);

> > to get the gpio. This fails with -EINVAL.

> And you didn't see this issue with the fsl,avic patch?

No. With the fsl,avic patch in place, all drivers are probed correctly.

> The property you are using is not a standard GPIO binding (-gpios,
> gpio, gpios) and I'm not surprised it's not working.

I know that I should be using the gpiod API as suggested by Geert.

BTW is this definition ok? Could its driver be converted to using the
gpiod api?

rtc: rtc {
   compatible = "moxa,moxart-rtc";
   gpio-rtc-sclk = < 5 0>;
...


> The gpio1 is probably getting probe deferred and ends up running after
> "my_driver".

I added a debug print in the probe function. It turned out that the
driver for gpio1 is probed for the first time after my_driver.

I removed the interrupt-controller property for gpio2 for testing. gpio2
was then probed much earlier.

Best regards,
Martin


Re: [PATCH v2 0/3] Make fw_devlink=on more forgiving

2021-02-02 Thread Martin Kaiser
Hi Saravana,

Thus wrote Saravana Kannan (sarava...@google.com):

> Martin,

> If you tested this series, can you please give a Tested-by?

I tested this v2 series on top of next-20210202 (without the fsl,avic
patch).

If modules are enabled, the kernel doesn't boot on my imx25 board. This
is expected, I guess.

With modules disabled, the kernel boots but probe fails for some
(non-mainline) drivers in my tree. All of those drivers have a gpio in
their device-tree node, such as

my_driver {
   gpio_test1 = < 0 0>;
   ...
};

with gpio1 from arch/arm/boot/dts/imx25.dtsi.

The probe function calls

of_get_named_gpio(np, "gpio_test1", 0);

to get the gpio. This fails with -EINVAL.

Best regards,
Martin


Re: [PATCH v1] ARM: imx: avic: Convert to using IRQCHIP_DECLARE

2021-02-01 Thread Martin Kaiser
Thus wrote Saravana Kannan (sarava...@google.com):

> On Sun, Jan 31, 2021 at 5:26 PM Fabio Estevam  wrote:

> > Hi Saravana,

> > On Sun, Jan 31, 2021 at 5:56 PM Saravana Kannan  
> > wrote:

> > > +static int __init imx_avic_init(struct device_node *node,
> > > +  struct device_node *parent)
> > > +{
> > > +   void __iomem *avic_base;
> > > +
> > > +   avic_base = of_iomap(node, 0);
> > > +   BUG_ON(!avic_base);
> > > +   mxc_init_irq(avic_base);
> > > +   return 0;
> > > +}
> > > +
> > > +IRQCHIP_DECLARE(imx_avic, "fsl,imx31-avic", imx_avic_init);

> > Shouldn't the compatible be "fsl,avic" instead?

> Fabio,

> Ah yes. I had that too. I deleted the wrong one in the last minute
> before sending it out. Thanks for catching it.

> I'll wait to see if there are any other review comments before I send out v2.

> Martin,

> Please make this fix before you test it.

> -Saravana

with fsl,avic

Tested-by: Martin Kaiser 


Re: [PATCH v2 0/2] of: property: Add fw_devlink support for more props

2021-02-01 Thread Martin Kaiser
Hi Saravana,

Thus wrote Saravana Kannan (sarava...@google.com):

> This series [1] has a high chance of fixing it for you if
> CONFIG_MODULES is disabled in your set up. Can you give it a shot?

sure. This fixes things for me if CONFIG_MODULES is disabled. Booting is
still stuck if modules are enabled.

> The real problem is that arch/arm/mach-imx/avic.c doesn't set the
> OF_POPULATED flag for the "fsl,avic" node. fw_devlink uses this
> information to know that this device node will never have a struct
> device created for it. The proper way to do this for root IRQCHIP
> nodes is to use IRQCHIP_DECLARE(). I Cc'ed you on a clean up patch for
> IMX [2], can you please give [2] a shot *without* [1] and with
> CONFIG_MODULES enabled? Things should boot properly with this
> combination too.

This works as well.

Thanks,
Martin


[PATCH] staging: rtl8723bs: fix rtw_cfg80211_monitor_if_xmit_entry's return value

2021-01-31 Thread Martin Kaiser
A netdev xmit function should return NETDEV_TX_OK or NETDEV_TX_BUSY.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c 
b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 11032316c53d..ff164a8c8679 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -2516,7 +2516,7 @@ static netdev_tx_t 
rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, struc
 
dev_kfree_skb_any(skb);
 
-   return 0;
+   return NETDEV_TX_OK;
 
 }
 
-- 
2.20.1



[PATCH] staging: rtl8188eu: fix rtw_xmit_entry's return value

2021-01-22 Thread Martin Kaiser
A netdev xmit function should return NETDEV_TX_OK or NETDEV_TX_BUSY.

Signed-off-by: Martin Kaiser 
---
 drivers/staging/rtl8188eu/os_dep/xmit_linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/os_dep/xmit_linux.c 
b/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
index c22ddeb9a56b..b0efa2eb705e 100644
--- a/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
@@ -205,5 +205,5 @@ int rtw_xmit_entry(struct sk_buff *pkt, struct net_device 
*pnetdev)
 ("%s: drop, tx_drop=%d\n", __func__, (u32)pxmitpriv->tx_drop));
 
 exit:
-   return 0;
+   return NETDEV_TX_OK;
 }
-- 
2.20.1



[PATCH v4] PCI: brcmstb: Remove chained IRQ handler and data in one go

2021-01-15 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
Acked-by: Florian Fainelli 
Acked-by: Nicolas Saenz Julienne 
---
Hi Lorenzo,
I sent this simple patch back in November, it seems that it got lost
somehow. Is there any chance that you can apply it?
Thanks, Martin

v4:
 - resend after two months
 - clean up the commit message while at it
v3:
 - rewrite the commit message again. this is no race condition if we
   remove the interrupt handler. sorry for the noise.
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/pcie-brcmstb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c 
b/drivers/pci/controller/pcie-brcmstb.c
index d41257f43a8f..95f6dd93ceae 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -603,8 +603,7 @@ static void brcm_msi_remove(struct brcm_pcie *pcie)
 
if (!msi)
return;
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
brcm_free_domains(msi);
 }
 
-- 
2.20.1



[PATCH v4 3/3] PCI: xgene-msi: Fix race in installing chained irq handler

2021-01-15 Thread Martin Kaiser
Fix a race where a pending interrupt could be received and the handler
called before the handler's data has been setup, by converting to
irq_set_chained_handler_and_data().

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained IRQ
handler").

Based on the mail discussion, it seems ok to drop the error handling.

Signed-off-by: Martin Kaiser 
---
v4
 - resend after two months

 drivers/pci/controller/pci-xgene-msi.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/controller/pci-xgene-msi.c 
b/drivers/pci/controller/pci-xgene-msi.c
index 2470782cb01a..1c34c897a7e2 100644
--- a/drivers/pci/controller/pci-xgene-msi.c
+++ b/drivers/pci/controller/pci-xgene-msi.c
@@ -384,13 +384,9 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu)
if (!msi_group->gic_irq)
continue;
 
-   irq_set_chained_handler(msi_group->gic_irq,
-   xgene_msi_isr);
-   err = irq_set_handler_data(msi_group->gic_irq, msi_group);
-   if (err) {
-   pr_err("failed to register GIC IRQ handler\n");
-   return -EINVAL;
-   }
+   irq_set_chained_handler_and_data(msi_group->gic_irq,
+   xgene_msi_isr, msi_group);
+
/*
 * Statically allocate MSI GIC IRQs to each CPU core.
 * With 8-core X-Gene v1, 2 MSI GIC IRQs are allocated
-- 
2.20.1



[PATCH v4 1/3] PCI: altera-msi: Remove IRQ handler and data in one go

2021-01-15 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
---
Hi Lorenzo,
here's another bunch of simple patches that were discussed in November.
Could you have a look?
Thanks,
Martin

v4:
 - resend after two months
 - capitalize the commit message properly
v3:
 - rewrite the commit message again. this is no race condition if we
   remove the interrupt handler. sorry for the noise.
v2:
 - rewrite the commit message to clarify that this is a bugfix


 drivers/pci/controller/pcie-altera-msi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-altera-msi.c 
b/drivers/pci/controller/pcie-altera-msi.c
index e1636f7714ca..42691dd8ebef 100644
--- a/drivers/pci/controller/pcie-altera-msi.c
+++ b/drivers/pci/controller/pcie-altera-msi.c
@@ -204,8 +204,7 @@ static int altera_msi_remove(struct platform_device *pdev)
struct altera_msi *msi = platform_get_drvdata(pdev);
 
msi_writel(msi, 0, MSI_INTMASK);
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
 
altera_free_domains(msi);
 
-- 
2.20.1



[PATCH v4 2/3] PCI: dwc: Remove IRQ handler and data in one go

2021-01-15 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
---
v4:
 - resend after two months
 - capitalize the commit message properly
v3:
 - rewrite the commit message again. this is no race condition if we
   remove the interrupt handler. sorry for the noise.
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c 
b/drivers/pci/controller/dwc/pcie-designware-host.c
index 8a84c005f32b..3837fff48944 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -258,10 +258,8 @@ int dw_pcie_allocate_domains(struct pcie_port *pp)
 
 static void dw_pcie_free_msi(struct pcie_port *pp)
 {
-   if (pp->msi_irq) {
-   irq_set_chained_handler(pp->msi_irq, NULL);
-   irq_set_handler_data(pp->msi_irq, NULL);
-   }
+   if (pp->msi_irq)
+   irq_set_chained_handler_and_data(pp->msi_irq, NULL, NULL);
 
irq_domain_remove(pp->msi_domain);
irq_domain_remove(pp->irq_domain);
-- 
2.20.1



[PATCH RESEND v2 2/3] mailbox: stm32-ipcc: remove duplicate error message

2020-11-29 Thread Martin Kaiser
platform_get_irq_byname already prints an error message if the requested
irq was not found. Don't print another message in the driver.

Signed-off-by: Martin Kaiser 
Reviewed-by: Fabien Dessenne 
---
changes in v2
- added Fabien's review tag
- reformatted the commit message such that lines are < 75 chars

 drivers/mailbox/stm32-ipcc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/mailbox/stm32-ipcc.c b/drivers/mailbox/stm32-ipcc.c
index ef966887aa15..ab8fe56af948 100644
--- a/drivers/mailbox/stm32-ipcc.c
+++ b/drivers/mailbox/stm32-ipcc.c
@@ -257,9 +257,6 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
for (i = 0; i < IPCC_IRQ_NUM; i++) {
ipcc->irqs[i] = platform_get_irq_byname(pdev, irq_name[i]);
if (ipcc->irqs[i] < 0) {
-   if (ipcc->irqs[i] != -EPROBE_DEFER)
-   dev_err(dev, "no IRQ specified %s\n",
-   irq_name[i]);
ret = ipcc->irqs[i];
goto err_clk;
}
-- 
2.20.1



[PATCH RESEND v2 3/3] mailbox: stm32-ipcc: cast void pointers to unsigned long

2020-11-29 Thread Martin Kaiser
Now that the driver can be enabled by COMPILE_TEST, we see warnings on
64bit platforms when void pointers are cast to unsigned int (and
vice versa).

warning: cast to smaller integer type 'unsigned int' from 'void *'
   unsigned int chan = (unsigned int)link->con_priv;
...
warning: cast to 'void *' from smaller integer type 'unsigned int'
   ipcc->controller.chans[i].con_priv = (void *)i;

Update these casts to use unsigned long variables, which are the same
size as pointers on all platforms.

Reported-by: kernel test robot 
Signed-off-by: Martin Kaiser 
Reviewed-by: Fabien Dessenne 
---
changes in v2
- added this patch to fix COMPILE_TEST warnings

 drivers/mailbox/stm32-ipcc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mailbox/stm32-ipcc.c b/drivers/mailbox/stm32-ipcc.c
index ab8fe56af948..b84e0587937c 100644
--- a/drivers/mailbox/stm32-ipcc.c
+++ b/drivers/mailbox/stm32-ipcc.c
@@ -144,11 +144,11 @@ static irqreturn_t stm32_ipcc_tx_irq(int irq, void *data)
 
 static int stm32_ipcc_send_data(struct mbox_chan *link, void *data)
 {
-   unsigned int chan = (unsigned int)link->con_priv;
+   unsigned long chan = (unsigned long)link->con_priv;
struct stm32_ipcc *ipcc = container_of(link->mbox, struct stm32_ipcc,
   controller);
 
-   dev_dbg(ipcc->controller.dev, "%s: chan:%d\n", __func__, chan);
+   dev_dbg(ipcc->controller.dev, "%s: chan:%lu\n", __func__, chan);
 
/* set channel n occupied */
stm32_ipcc_set_bits(>lock, ipcc->reg_proc + IPCC_XSCR,
@@ -163,7 +163,7 @@ static int stm32_ipcc_send_data(struct mbox_chan *link, 
void *data)
 
 static int stm32_ipcc_startup(struct mbox_chan *link)
 {
-   unsigned int chan = (unsigned int)link->con_priv;
+   unsigned long chan = (unsigned long)link->con_priv;
struct stm32_ipcc *ipcc = container_of(link->mbox, struct stm32_ipcc,
   controller);
int ret;
@@ -183,7 +183,7 @@ static int stm32_ipcc_startup(struct mbox_chan *link)
 
 static void stm32_ipcc_shutdown(struct mbox_chan *link)
 {
-   unsigned int chan = (unsigned int)link->con_priv;
+   unsigned long chan = (unsigned long)link->con_priv;
struct stm32_ipcc *ipcc = container_of(link->mbox, struct stm32_ipcc,
   controller);
 
@@ -206,7 +206,7 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
struct device_node *np = dev->of_node;
struct stm32_ipcc *ipcc;
struct resource *res;
-   unsigned int i;
+   unsigned long i;
int ret;
u32 ip_ver;
static const char * const irq_name[] = {"rx", "tx"};
@@ -265,7 +265,7 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
irq_thread[i], IRQF_ONESHOT,
dev_name(dev), ipcc);
if (ret) {
-   dev_err(dev, "failed to request irq %d (%d)\n", i, ret);
+   dev_err(dev, "failed to request irq %lu (%d)\n", i, 
ret);
goto err_clk;
}
}
-- 
2.20.1



[PATCH RESEND v2 1/3] mailbox: stm32-ipcc: add COMPILE_TEST dependency

2020-11-29 Thread Martin Kaiser
This allows compiling the driver on architectures where the hardware is not
available. Most other mailbox drivers support this as well.

Signed-off-by: Martin Kaiser 
Reviewed-by: Fabien Dessenne 
---
changes in v2
- added Fabien's review tag

Dear all,

this has been around for some weeks now. Is there anything else you need
before these simple patches can be merged?

Thanks,
Martin

 drivers/mailbox/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index 05b1009e2820..abbf5d67ffa2 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -201,7 +201,7 @@ config BCM_FLEXRM_MBOX
 
 config STM32_IPCC
tristate "STM32 IPCC Mailbox"
-   depends on MACH_STM32MP157
+   depends on MACH_STM32MP157 || COMPILE_TEST
help
  Mailbox implementation for STMicroelectonics STM32 family chips
  with hardware for Inter-Processor Communication Controller (IPCC)
-- 
2.20.1



[PATCH v3 1/3] PCI: altera-msi: remove chained IRQ handler and data in one go

2020-11-12 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
---
v3:
 - rewrite the commit message again. this is no race condition if we
   remove the interrupt handler. sorry for the noise.
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/pcie-altera-msi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-altera-msi.c 
b/drivers/pci/controller/pcie-altera-msi.c
index e1636f7714ca..42691dd8ebef 100644
--- a/drivers/pci/controller/pcie-altera-msi.c
+++ b/drivers/pci/controller/pcie-altera-msi.c
@@ -204,8 +204,7 @@ static int altera_msi_remove(struct platform_device *pdev)
struct altera_msi *msi = platform_get_drvdata(pdev);
 
msi_writel(msi, 0, MSI_INTMASK);
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
 
altera_free_domains(msi);
 
-- 
2.20.1



[PATCH v3 3/3] PCI: xgene-msi: Fix race in installing chained irq handler

2020-11-12 Thread Martin Kaiser
Fix a race where a pending interrupt could be received and the handler
called before the handler's data has been setup, by converting to
irq_set_chained_handler_and_data().

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained IRQ
handler").

Based on the mail discussion, it seems ok to drop the error handling.

Link: 
https://lore.kernel.org/linux-pci/87h7pumo9l@nanos.tec.linutronix.de/T/#m6d3288531114ada1378b41538ef73fef451f1441
Signed-off-by: Martin Kaiser 
---
 drivers/pci/controller/pci-xgene-msi.c | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/controller/pci-xgene-msi.c 
b/drivers/pci/controller/pci-xgene-msi.c
index 2470782cb01a..1c34c897a7e2 100644
--- a/drivers/pci/controller/pci-xgene-msi.c
+++ b/drivers/pci/controller/pci-xgene-msi.c
@@ -384,13 +384,9 @@ static int xgene_msi_hwirq_alloc(unsigned int cpu)
if (!msi_group->gic_irq)
continue;
 
-   irq_set_chained_handler(msi_group->gic_irq,
-   xgene_msi_isr);
-   err = irq_set_handler_data(msi_group->gic_irq, msi_group);
-   if (err) {
-   pr_err("failed to register GIC IRQ handler\n");
-   return -EINVAL;
-   }
+   irq_set_chained_handler_and_data(msi_group->gic_irq,
+   xgene_msi_isr, msi_group);
+
/*
 * Statically allocate MSI GIC IRQs to each CPU core.
 * With 8-core X-Gene v1, 2 MSI GIC IRQs are allocated
-- 
2.20.1



[PATCH v3 2/3] PCI: dwc: remove chained IRQ handler and data in one go

2020-11-12 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
---
v3:
 - rewrite the commit message again. this is no race condition if we
   remove the interrupt handler. sorry for the noise.
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c 
b/drivers/pci/controller/dwc/pcie-designware-host.c
index 44c2a6572199..fc2428165f13 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -258,10 +258,8 @@ int dw_pcie_allocate_domains(struct pcie_port *pp)
 
 void dw_pcie_free_msi(struct pcie_port *pp)
 {
-   if (pp->msi_irq) {
-   irq_set_chained_handler(pp->msi_irq, NULL);
-   irq_set_handler_data(pp->msi_irq, NULL);
-   }
+   if (pp->msi_irq)
+   irq_set_chained_handler_and_data(pp->msi_irq, NULL, NULL);
 
irq_domain_remove(pp->msi_domain);
irq_domain_remove(pp->irq_domain);
-- 
2.20.1



[PATCH v3] PCI: brcmstb: remove chained IRQ handler and data in one go

2020-11-12 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
Acked-by: Florian Fainelli 
Acked-by: Nicolas Saenz Julienne 
---
v3:
 - rewrite the commit message again. this is no race condition if we
   remove the interrupt handler. sorry for the noise.
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/pcie-brcmstb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c 
b/drivers/pci/controller/pcie-brcmstb.c
index bea86899bd5d..7c666f4deb47 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -606,8 +606,7 @@ static void brcm_msi_remove(struct brcm_pcie *pcie)
 
if (!msi)
return;
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
brcm_free_domains(msi);
 }
 
-- 
2.20.1



[PATCH v2 2/2] PCI: dwc: Fix race in removing chained IRQ handler

2020-11-11 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
---
 drivers/pci/controller/dwc/pcie-designware-host.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c 
b/drivers/pci/controller/dwc/pcie-designware-host.c
index 44c2a6572199..fc2428165f13 100644
--- a/drivers/pci/controller/dwc/pcie-designware-host.c
+++ b/drivers/pci/controller/dwc/pcie-designware-host.c
@@ -258,10 +258,8 @@ int dw_pcie_allocate_domains(struct pcie_port *pp)
 
 void dw_pcie_free_msi(struct pcie_port *pp)
 {
-   if (pp->msi_irq) {
-   irq_set_chained_handler(pp->msi_irq, NULL);
-   irq_set_handler_data(pp->msi_irq, NULL);
-   }
+   if (pp->msi_irq)
+   irq_set_chained_handler_and_data(pp->msi_irq, NULL, NULL);
 
irq_domain_remove(pp->msi_domain);
irq_domain_remove(pp->irq_domain);
-- 
2.20.1



[PATCH v2 1/2] PCI: altera-msi: Fix race in removing chained IRQ handler

2020-11-11 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
---
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/pcie-altera-msi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-altera-msi.c 
b/drivers/pci/controller/pcie-altera-msi.c
index e1636f7714ca..42691dd8ebef 100644
--- a/drivers/pci/controller/pcie-altera-msi.c
+++ b/drivers/pci/controller/pcie-altera-msi.c
@@ -204,8 +204,7 @@ static int altera_msi_remove(struct platform_device *pdev)
struct altera_msi *msi = platform_get_drvdata(pdev);
 
msi_writel(msi, 0, MSI_INTMASK);
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
 
altera_free_domains(msi);
 
-- 
2.20.1



[PATCH v2] PCI: brcmstb: Fix race in removing chained IRQ handler

2020-11-11 Thread Martin Kaiser
Call irq_set_chained_handler_and_data() to clear the chained handler
and the handler's data under irq_desc->lock.

See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
IRQ handler").

Signed-off-by: Martin Kaiser 
Acked-by: Florian Fainelli 
---
v2:
 - rewrite the commit message to clarify that this is a bugfix

 drivers/pci/controller/pcie-brcmstb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c 
b/drivers/pci/controller/pcie-brcmstb.c
index bea86899bd5d..7c666f4deb47 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -606,8 +606,7 @@ static void brcm_msi_remove(struct brcm_pcie *pcie)
 
if (!msi)
return;
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
brcm_free_domains(msi);
 }
 
-- 
2.20.1



Re: [PATCH] PCI: altera-msi: Remove irq handler and data in one go

2020-11-11 Thread Martin Kaiser
Thus wrote Bjorn Helgaas (helg...@kernel.org):

> [+cc Florian, sorry, I hadn't seen your ack when I sent the below]

> On Tue, Nov 10, 2020 at 03:21:36PM -0600, Bjorn Helgaas wrote:
> > [+cc Nicolas, Jingoo, Gustavo, Toan]

> > On Sun, Nov 08, 2020 at 08:11:40PM +0100, Martin Kaiser wrote:
> > > Replace the two separate calls for removing the irq handler and data with 
> > > a
> > > single irq_set_chained_handler_and_data() call.

> > This is similar to these:

> >   36f024ed8fc9 ("PCI/MSI: pci-xgene-msi: Consolidate chained IRQ handler 
> > install/remove")
> >   5168a73ce32d ("PCI/keystone: Consolidate chained IRQ handler 
> > install/remove")
> >   2cf5a03cb29d ("PCI/keystone: Fix race in installing chained IRQ handler")

> > and it seems potentially important that this removes the IRQ handler
> > and data *atomically*, i.e., both are done while holding
> > irq_get_desc_buslock().  

Ok, understood.

> > So I would use this:

> >   PCI: altera-msi: Fix race in installing chained IRQ handler

> >   Fix a race where a pending interrupt could be received and the handler
> >   called before the handler's data has been setup by converting to
> >   irq_set_chained_handler_and_data().

> >   See also 2cf5a03cb29d ("PCI/keystone: Fix race in installing chained
> >   IRQ handler").

> > to make it clear that this is actually a bug fix, not just a cleanup.

Thomas' commit 2cf5a03cb29d fixed a case where the handler was installed.
We're removing the handler here so his commit message doesn't really fit.
Anyway, I'll rewrite the commit message to clarify that this fixes a
race condition.

> > Looks like this should also be done in dw_pcie_free_msi() and

I'll send a patch for this.

> > xgene_msi_hwirq_alloc() at the same time?

This function uses the error status from irq_set_handler_data().
irq_set_chained_handler_and_data() returns no such error status. Is it
ok to drop the error handling?

Thanks,
Martin


[PATCH] PCI: altera-msi: Remove irq handler and data in one go

2020-11-08 Thread Martin Kaiser
Replace the two separate calls for removing the irq handler and data with a
single irq_set_chained_handler_and_data() call.

Signed-off-by: Martin Kaiser 
---
 drivers/pci/controller/pcie-altera-msi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-altera-msi.c 
b/drivers/pci/controller/pcie-altera-msi.c
index e1636f7714ca..42691dd8ebef 100644
--- a/drivers/pci/controller/pcie-altera-msi.c
+++ b/drivers/pci/controller/pcie-altera-msi.c
@@ -204,8 +204,7 @@ static int altera_msi_remove(struct platform_device *pdev)
struct altera_msi *msi = platform_get_drvdata(pdev);
 
msi_writel(msi, 0, MSI_INTMASK);
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
 
altera_free_domains(msi);
 
-- 
2.20.1



[PATCH] PCI: brcmstb: Remove irq handler and data in one go

2020-11-08 Thread Martin Kaiser
Replace the two separate calls for removing the irq handler and data with a
single irq_set_chained_handler_and_data() call.

Signed-off-by: Martin Kaiser 
---
 drivers/pci/controller/pcie-brcmstb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pcie-brcmstb.c 
b/drivers/pci/controller/pcie-brcmstb.c
index bea86899bd5d..7c666f4deb47 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -606,8 +606,7 @@ static void brcm_msi_remove(struct brcm_pcie *pcie)
 
if (!msi)
return;
-   irq_set_chained_handler(msi->irq, NULL);
-   irq_set_handler_data(msi->irq, NULL);
+   irq_set_chained_handler_and_data(msi->irq, NULL, NULL);
brcm_free_domains(msi);
 }
 
-- 
2.20.1



[PATCH] pinctrl: pinctrl-at91-pio4: Set irq handler and data in one go

2020-11-08 Thread Martin Kaiser
Replace the two separate calls for setting the irq handler and data with a
single irq_set_chained_handler_and_data() call.

Signed-off-by: Martin Kaiser 
---
 drivers/pinctrl/pinctrl-at91-pio4.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c 
b/drivers/pinctrl/pinctrl-at91-pio4.c
index 578b387100d9..157fea808629 100644
--- a/drivers/pinctrl/pinctrl-at91-pio4.c
+++ b/drivers/pinctrl/pinctrl-at91-pio4.c
@@ -1127,8 +1127,8 @@ static int atmel_pinctrl_probe(struct platform_device 
*pdev)
return -EINVAL;
}
atmel_pioctrl->irqs[i] = res->start;
-   irq_set_chained_handler(res->start, atmel_gpio_irq_handler);
-   irq_set_handler_data(res->start, atmel_pioctrl);
+   irq_set_chained_handler_and_data(res->start,
+   atmel_gpio_irq_handler, atmel_pioctrl);
dev_dbg(dev, "bank %i: irq=%pr\n", i, res);
}
 
-- 
2.20.1



[PATCH v2 3/3] i2c: exynos5: don't check for irq 0

2020-11-01 Thread Martin Kaiser
platform_get_irq never returns 0. Don't check for this. Make it clear that
the error path always returns a negative error code.

Signed-off-by: Martin Kaiser 
---
changes in v2
- split the patch in three parts

 drivers/i2c/busses/i2c-exynos5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index fad1c52857aa..20a9881a0d6c 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -778,7 +778,7 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
init_completion(>msg_complete);
 
i2c->irq = ret = platform_get_irq(pdev, 0);
-   if (ret <= 0)
+   if (ret < 0)
goto err_clk;
 
ret = devm_request_irq(>dev, i2c->irq, exynos5_i2c_irq,
-- 
2.20.1



[PATCH v2 1/3] i2c: exynos5: remove duplicate error message

2020-11-01 Thread Martin Kaiser
platform_get_irq already prints an error message if the requested irq
was not found. Don't print another message in the driver.

Signed-off-by: Martin Kaiser 
---
changes in v2
- split the patch in three parts

 drivers/i2c/busses/i2c-exynos5.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 6ce3ec03b595..c5f5fb28762d 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -779,7 +779,6 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
 
i2c->irq = ret = platform_get_irq(pdev, 0);
if (ret <= 0) {
-   dev_err(>dev, "cannot find HS-I2C IRQ\n");
ret = -EINVAL;
goto err_clk;
}
-- 
2.20.1



[PATCH v2 2/3] i2c: exynos5: fix platform_get_irq error handling

2020-11-01 Thread Martin Kaiser
If platform_get_irq returns an error, relay this error to the caller of
the probe function. Don't change all errors to -EINVAL. This breaks the
case where platform_get_irq returns -EPROBE_DEFER.

Signed-off-by: Martin Kaiser 
---
changes in v2
- split the patch in three parts

 drivers/i2c/busses/i2c-exynos5.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index c5f5fb28762d..fad1c52857aa 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -778,10 +778,8 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
init_completion(>msg_complete);
 
i2c->irq = ret = platform_get_irq(pdev, 0);
-   if (ret <= 0) {
-   ret = -EINVAL;
+   if (ret <= 0)
goto err_clk;
-   }
 
ret = devm_request_irq(>dev, i2c->irq, exynos5_i2c_irq,
   IRQF_NO_SUSPEND, dev_name(>dev), i2c);
-- 
2.20.1



[PATCH v2 3/3] mailbox: stm32-ipcc: cast void pointers to unsigned long

2020-11-01 Thread Martin Kaiser
Now that the driver can be enabled by COMPILE_TEST, we see warnings on
64bit platforms when void pointers are cast to unsigned int (and
vice versa).

warning: cast to smaller integer type 'unsigned int' from 'void *'
   unsigned int chan = (unsigned int)link->con_priv;
...
warning: cast to 'void *' from smaller integer type 'unsigned int'
   ipcc->controller.chans[i].con_priv = (void *)i;

Update these casts to use unsigned long variables, which are the same
size as pointers on all platforms.

Reported-by: kernel test robot 
Signed-off-by: Martin Kaiser 
---
changes in v2
- added this patch to fix COMPILE_TEST warnings

 drivers/mailbox/stm32-ipcc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/mailbox/stm32-ipcc.c b/drivers/mailbox/stm32-ipcc.c
index ab8fe56af948..b84e0587937c 100644
--- a/drivers/mailbox/stm32-ipcc.c
+++ b/drivers/mailbox/stm32-ipcc.c
@@ -144,11 +144,11 @@ static irqreturn_t stm32_ipcc_tx_irq(int irq, void *data)
 
 static int stm32_ipcc_send_data(struct mbox_chan *link, void *data)
 {
-   unsigned int chan = (unsigned int)link->con_priv;
+   unsigned long chan = (unsigned long)link->con_priv;
struct stm32_ipcc *ipcc = container_of(link->mbox, struct stm32_ipcc,
   controller);
 
-   dev_dbg(ipcc->controller.dev, "%s: chan:%d\n", __func__, chan);
+   dev_dbg(ipcc->controller.dev, "%s: chan:%lu\n", __func__, chan);
 
/* set channel n occupied */
stm32_ipcc_set_bits(>lock, ipcc->reg_proc + IPCC_XSCR,
@@ -163,7 +163,7 @@ static int stm32_ipcc_send_data(struct mbox_chan *link, 
void *data)
 
 static int stm32_ipcc_startup(struct mbox_chan *link)
 {
-   unsigned int chan = (unsigned int)link->con_priv;
+   unsigned long chan = (unsigned long)link->con_priv;
struct stm32_ipcc *ipcc = container_of(link->mbox, struct stm32_ipcc,
   controller);
int ret;
@@ -183,7 +183,7 @@ static int stm32_ipcc_startup(struct mbox_chan *link)
 
 static void stm32_ipcc_shutdown(struct mbox_chan *link)
 {
-   unsigned int chan = (unsigned int)link->con_priv;
+   unsigned long chan = (unsigned long)link->con_priv;
struct stm32_ipcc *ipcc = container_of(link->mbox, struct stm32_ipcc,
   controller);
 
@@ -206,7 +206,7 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
struct device_node *np = dev->of_node;
struct stm32_ipcc *ipcc;
struct resource *res;
-   unsigned int i;
+   unsigned long i;
int ret;
u32 ip_ver;
static const char * const irq_name[] = {"rx", "tx"};
@@ -265,7 +265,7 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
irq_thread[i], IRQF_ONESHOT,
dev_name(dev), ipcc);
if (ret) {
-   dev_err(dev, "failed to request irq %d (%d)\n", i, ret);
+   dev_err(dev, "failed to request irq %lu (%d)\n", i, 
ret);
goto err_clk;
}
}
-- 
2.20.1



[PATCH v2 2/3] mailbox: stm32-ipcc: remove duplicate error message

2020-11-01 Thread Martin Kaiser
platform_get_irq_byname already prints an error message if the requested
irq was not found. Don't print another message in the driver.

Signed-off-by: Martin Kaiser 
Reviewed-by: Fabien Dessenne 
---
changes in v2
- added Fabien's review tag
- reformatted the commit message such that lines are < 75 chars

 drivers/mailbox/stm32-ipcc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/mailbox/stm32-ipcc.c b/drivers/mailbox/stm32-ipcc.c
index ef966887aa15..ab8fe56af948 100644
--- a/drivers/mailbox/stm32-ipcc.c
+++ b/drivers/mailbox/stm32-ipcc.c
@@ -257,9 +257,6 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
for (i = 0; i < IPCC_IRQ_NUM; i++) {
ipcc->irqs[i] = platform_get_irq_byname(pdev, irq_name[i]);
if (ipcc->irqs[i] < 0) {
-   if (ipcc->irqs[i] != -EPROBE_DEFER)
-   dev_err(dev, "no IRQ specified %s\n",
-   irq_name[i]);
ret = ipcc->irqs[i];
goto err_clk;
}
-- 
2.20.1



[PATCH v2 1/3] mailbox: stm32-ipcc: add COMPILE_TEST dependency

2020-11-01 Thread Martin Kaiser
This allows compiling the driver on architectures where the hardware is not
available. Most other mailbox drivers support this as well.

Signed-off-by: Martin Kaiser 
Reviewed-by: Fabien Dessenne 
---
changes in v2
- added Fabien's review tag

 drivers/mailbox/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index 05b1009e2820..abbf5d67ffa2 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -201,7 +201,7 @@ config BCM_FLEXRM_MBOX
 
 config STM32_IPCC
tristate "STM32 IPCC Mailbox"
-   depends on MACH_STM32MP157
+   depends on MACH_STM32MP157 || COMPILE_TEST
help
  Mailbox implementation for STMicroelectonics STM32 family chips
  with hardware for Inter-Processor Communication Controller (IPCC)
-- 
2.20.1



[PATCH] i2c: exynos5: fix platform_get_irq error handling

2020-10-27 Thread Martin Kaiser
platform_get_irq already prints an error message if the requested irq
was not found. Don't print another message in the driver.

If platform_get_irq returns an error, relay this error to the caller of the
probe function. Don't change all errors to -EINVAL. This breaks the case
where platform_get_irq returns -EPROBE_DEFER.

platform_get_irq never returns 0. Don't check for this. Make it clear that
the error path always returns a negative error code.

Signed-off-by: Martin Kaiser 
---
 drivers/i2c/busses/i2c-exynos5.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 6ce3ec03b595..20a9881a0d6c 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -778,11 +778,8 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
init_completion(>msg_complete);
 
i2c->irq = ret = platform_get_irq(pdev, 0);
-   if (ret <= 0) {
-   dev_err(>dev, "cannot find HS-I2C IRQ\n");
-   ret = -EINVAL;
+   if (ret < 0)
goto err_clk;
-   }
 
ret = devm_request_irq(>dev, i2c->irq, exynos5_i2c_irq,
   IRQF_NO_SUSPEND, dev_name(>dev), i2c);
-- 
2.20.1



[PATCH 1/2] mailbox: stm32-ipcc: add COMPILE_TEST dependency

2020-10-24 Thread Martin Kaiser
This allows compiling the driver on architectures where the hardware is not
available. Most other mailbox drivers support this as well.

Signed-off-by: Martin Kaiser 
---

I used this for testing the trivial patch that removes the duplicate error
message. Also, compiling the driver on x86_64 worked without errors.

 drivers/mailbox/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig
index 05b1009e2820..abbf5d67ffa2 100644
--- a/drivers/mailbox/Kconfig
+++ b/drivers/mailbox/Kconfig
@@ -201,7 +201,7 @@ config BCM_FLEXRM_MBOX
 
 config STM32_IPCC
tristate "STM32 IPCC Mailbox"
-   depends on MACH_STM32MP157
+   depends on MACH_STM32MP157 || COMPILE_TEST
help
  Mailbox implementation for STMicroelectonics STM32 family chips
  with hardware for Inter-Processor Communication Controller (IPCC)
-- 
2.20.1



[PATCH 2/2] mailbox: stm32-ipcc: remove duplicate error message

2020-10-24 Thread Martin Kaiser
platform_get_irq_byname already prints an error message if the requested irq
was not found. Don't print another message in the driver.

Signed-off-by: Martin Kaiser 
---
 drivers/mailbox/stm32-ipcc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/mailbox/stm32-ipcc.c b/drivers/mailbox/stm32-ipcc.c
index ef966887aa15..ab8fe56af948 100644
--- a/drivers/mailbox/stm32-ipcc.c
+++ b/drivers/mailbox/stm32-ipcc.c
@@ -257,9 +257,6 @@ static int stm32_ipcc_probe(struct platform_device *pdev)
for (i = 0; i < IPCC_IRQ_NUM; i++) {
ipcc->irqs[i] = platform_get_irq_byname(pdev, irq_name[i]);
if (ipcc->irqs[i] < 0) {
-   if (ipcc->irqs[i] != -EPROBE_DEFER)
-   dev_err(dev, "no IRQ specified %s\n",
-   irq_name[i]);
ret = ipcc->irqs[i];
goto err_clk;
}
-- 
2.20.1



Re: [PATCH v2 5/5] hwrng: imx-rngc: enable driver for i.MX6

2020-06-21 Thread Martin Kaiser
Thus wrote Horia Geantă (horia.gea...@nxp.com):

> i.MX6 SL, SLL, ULL, ULZ SoCs have an RNGB block.

> Since imx-rngc driver supports also rngb,
> let's enable it for these SoCs too.

> Signed-off-by: Horia Geantă 
> ---
>  drivers/char/hw_random/Kconfig| 2 +-
>  drivers/char/hw_random/imx-rngc.c | 3 +++
>  2 files changed, 4 insertions(+), 1 deletion(-)

> diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
> index 0ad17efc96df..53f6a7e4392f 100644
> --- a/drivers/char/hw_random/Kconfig
> +++ b/drivers/char/hw_random/Kconfig
> @@ -245,7 +245,7 @@ config HW_RANDOM_MXC_RNGA
>  config HW_RANDOM_IMX_RNGC
>   tristate "Freescale i.MX RNGC Random Number Generator"
>   depends on HAS_IOMEM && HAVE_CLK
> - depends on SOC_IMX25 || COMPILE_TEST
> + depends on SOC_IMX25 || SOC_IMX6SL || SOC_IMX6SLL || SOC_IMX6UL || 
> COMPILE_TEST
>   default HW_RANDOM
>   help
> This driver provides kernel-side support for the Random Number
> diff --git a/drivers/char/hw_random/imx-rngc.c 
> b/drivers/char/hw_random/imx-rngc.c
> index 9c47e431ce90..84576d2fbf8c 100644
> --- a/drivers/char/hw_random/imx-rngc.c
> +++ b/drivers/char/hw_random/imx-rngc.c
> @@ -350,6 +350,9 @@ static SIMPLE_DEV_PM_OPS(imx_rngc_pm_ops, 
> imx_rngc_suspend, imx_rngc_resume);

>  static const struct of_device_id imx_rngc_dt_ids[] = {
>   { .compatible = "fsl,imx25-rngb", .data = NULL, },
> + { .compatible = "fsl,imx6sl-rngb", .data = NULL, },
> + { .compatible = "fsl,imx6sll-rngb", .data = NULL, },
> + { .compatible = "fsl,imx6ull-rngb", .data = NULL, },
>   { /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, imx_rngc_dt_ids);
> -- 
> 2.17.1

Reviewed-by: Martin Kaiser 


[PATCH v2 0/2] dt-bindings: display: fix native-mode setting

2019-10-05 Thread Martin Kaiser
According to
Documentation/devicetree/bindings/display/panel/display-timing.txt,
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used.

We've already fixed the board definitions which got this wrong. Fix the
examples in the device tree bindings as well.

Martin Kaiser (2):
  dt-bindings: display: imx: fix native-mode setting
  dt-bindings: display: clps711x-fb: fix native-mode setting

 Documentation/devicetree/bindings/display/cirrus,clps711x-fb.txt | 2 +-
 Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.11.0



[PATCH v2 1/2] dt-bindings: display: imx: fix native-mode setting

2019-10-05 Thread Martin Kaiser
Move the native-mode setting inside the display-timing node. Outside of
display-timing, it is ignored.

Signed-off-by: Martin Kaiser 
---
changes in v2
 move parts of the commit message into the cover letter

 Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt 
b/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt
index e5a8b363d829..f4df9e83bcd2 100644
--- a/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt
+++ b/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt
@@ -38,10 +38,10 @@ Example:
 
display0: display0 {
model = "Primeview-PD050VL1";
-   native-mode = <_disp0>;
bits-per-pixel = <16>;
fsl,pcr = <0xf0c88080>; /* non-standard but required */
display-timings {
+   native-mode = <_disp0>;
timing_disp0: 640x480 {
hactive = <640>;
vactive = <480>;
-- 
2.11.0



[PATCH v2 2/2] dt-bindings: display: clps711x-fb: fix native-mode setting

2019-10-05 Thread Martin Kaiser
Move the native-mode setting inside the display-timing node. Outside of
display-timing, it is ignored.

Signed-off-by: Martin Kaiser 
---
changes in v2
 fix the example in this binding as well

 Documentation/devicetree/bindings/display/cirrus,clps711x-fb.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/display/cirrus,clps711x-fb.txt 
b/Documentation/devicetree/bindings/display/cirrus,clps711x-fb.txt
index b0e506610400..0ab5f0663611 100644
--- a/Documentation/devicetree/bindings/display/cirrus,clps711x-fb.txt
+++ b/Documentation/devicetree/bindings/display/cirrus,clps711x-fb.txt
@@ -27,11 +27,11 @@ Example:
 
display: display {
model = "320x240x4";
-   native-mode = <>;
bits-per-pixel = <4>;
ac-prescale = <17>;
 
display-timings {
+   native-mode = <>;
timing0: 320x240 {
hactive = <320>;
hback-porch = <0>;
-- 
2.11.0



[PATCH] dt-bindings: display: imx: fix native-mode setting

2019-09-18 Thread Martin Kaiser
According to
Documentation/devicetree/bindings/display/panel/display-timing.txt,
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used.

We've already fixed the board definitions which got this wrong. Fix the
example in the imx framebuffer bindings as well.

Signed-off-by: Martin Kaiser 
---
 Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt 
b/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt
index e5a8b363d829..f4df9e83bcd2 100644
--- a/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt
+++ b/Documentation/devicetree/bindings/display/imx/fsl,imx-fb.txt
@@ -38,10 +38,10 @@ Example:
 
display0: display0 {
model = "Primeview-PD050VL1";
-   native-mode = <_disp0>;
bits-per-pixel = <16>;
fsl,pcr = <0xf0c88080>; /* non-standard but required */
display-timings {
+   native-mode = <_disp0>;
timing_disp0: 640x480 {
hactive = <640>;
vactive = <480>;
-- 
2.11.0



[PATCH] iio: max5481: use devres for iio device registration

2019-08-14 Thread Martin Kaiser
Replace iio_device_register with the devres variant and drop the
explicit function call to unregister the iio device.

Signed-off-by: Martin Kaiser 
---
 drivers/iio/potentiometer/max5481.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/iio/potentiometer/max5481.c 
b/drivers/iio/potentiometer/max5481.c
index 732375b6d131..40b7212e68dc 100644
--- a/drivers/iio/potentiometer/max5481.c
+++ b/drivers/iio/potentiometer/max5481.c
@@ -162,7 +162,7 @@ static int max5481_probe(struct spi_device *spi)
if (ret < 0)
return ret;
 
-   return iio_device_register(indio_dev);
+   return devm_iio_device_register(>dev, indio_dev);
 }
 
 static int max5481_remove(struct spi_device *spi)
@@ -170,8 +170,6 @@ static int max5481_remove(struct spi_device *spi)
struct iio_dev *indio_dev = dev_get_drvdata(>dev);
struct max5481_data *data = iio_priv(indio_dev);
 
-   iio_device_unregister(indio_dev);
-
/* save wiper reg to NV reg */
return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
 }
-- 
2.11.0



[PATCH] iio: max5487: use devres for iio device registration

2019-08-14 Thread Martin Kaiser
Replace iio_device_register with the devres variant and drop the
explicit function call to unregister the iio device.

Signed-off-by: Martin Kaiser 
---
 drivers/iio/potentiometer/max5487.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/iio/potentiometer/max5487.c 
b/drivers/iio/potentiometer/max5487.c
index 68ff806d4668..a6c92050d397 100644
--- a/drivers/iio/potentiometer/max5487.c
+++ b/drivers/iio/potentiometer/max5487.c
@@ -110,15 +110,11 @@ static int max5487_spi_probe(struct spi_device *spi)
if (ret < 0)
return ret;
 
-   return iio_device_register(indio_dev);
+   return devm_iio_device_register(>dev, indio_dev);
 }
 
 static int max5487_spi_remove(struct spi_device *spi)
 {
-   struct iio_dev *indio_dev = dev_get_drvdata(>dev);
-
-   iio_device_unregister(indio_dev);
-
/* save both wiper regs to NV regs */
return max5487_write_cmd(spi, MAX5487_COPY_AB_TO_NV);
 }
-- 
2.11.0



Re: iio: Is storing output values to non volatile registers something we should do automatically or leave to userspace action. [was Re: [PATCH] iio: potentiometer: max5432: update the non-volatile po

2019-08-12 Thread Martin Kaiser
Hi Jonathan,

Thus wrote Jonathan Cameron (ji...@kernel.org):

> The patch is fine, but I'm wondering about whether we need some element
> of policy control on this restore to current value.

> A few things to take into account.

> * Some devices don't have a non volatile store.  So userspace will be
>   responsible for doing the restore on reboot.
> * This may be one of several related devices, and it may make no sense
>   to restore this one if the others aren't going to be in the same
>   state as before the reboot.
> * Some devices only have non volatile registers for this sort of value
>   (or save to non volatile on removal of power). Hence any policy to
>   not store the value can't apply to this class of device.

I see your point. You'd like a consistent bahaviour across all
potentiometer drivers. Or at least a way for user space to figure out
whether a chip uses non-volatile storage or not.
This property doesn't quite fit into the channel info that are defined
in the arrays in drivers/iio/industrialio-core.c. Is there any other way
to set such a property?

> My initial thought is that these probably don't matter that much and
> we should apply this, but I would like to seek input from others!

> I thought there were some other drivers doing similar store to no
> volatile but I can't find one.

drivers/iio/potentiometer/max5481.c and max5487.c do something similar.

They use a command to transfer the setting from volatile to non-volatile
register in the spi remove function. I guess that the intention is to
save the current setting when the system is rebooted. However, my
understanding is that the remove function is called only when a module
is unloaded or when user space does explicitly unbind the device from
the bus via sysfs. That's why I tried using the shutdown function
instead.

Still, this approach has some disadvantages. For many systems, there's a
soft reboot (shutdown -r) where the driver's shutdown function is called
and a "hard reboot" where the power from the CPU and the potentiometer
chip is removed and reapplied. In this case, the current value would not
be transfered to the non-volatile register. 

At least for the max5432 family, there's no way to read the current
setting. The only option for user space to have a well-defined setting
is to set the wiper position explicitly at startup.

I guess the only sensible way to use a non-volatile register would be a
write operation where user space gets a response about successful
completion.

We could have two channels to write to the volatile or to non-volatile
register. Or we stick to one channel and update both volatile and
non-volatile registers when user space changes the value. This assumes
that the setting does not change frequently, which is prabably not true
for all applications...

Whatever we come up with, we should at least make the max* chips behave
the same way.

Best regards,
Martin


[PATCH] iio: potentiometer: max5432: update the non-volatile position

2019-08-09 Thread Martin Kaiser
Keep track of the wiper position that was set by user space. Store the
current wiper position in the chip's non-volatile register when the
system is rebooted. This will be the initial position next time the
max5432 chip is powered.

Update the register in the i2c client's shutdown function. Unlike the
remove function, shutdown is called when the system is rebooted. It's
safe to send an i2c message in the shutdown function.

Skip the update if user space never changed the wiper position.

Signed-off-by: Martin Kaiser 
---
The patch is against the testing branch in
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
It seems that this branch is not merged into linux-next.

 drivers/iio/potentiometer/max5432.c | 43 +
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/potentiometer/max5432.c 
b/drivers/iio/potentiometer/max5432.c
index 641b1821fdf6..73449078c89b 100644
--- a/drivers/iio/potentiometer/max5432.c
+++ b/drivers/iio/potentiometer/max5432.c
@@ -16,16 +16,33 @@
 
 /* All chip variants have 32 wiper positions. */
 #define MAX5432_MAX_POS 31
+/*
+ * Initial value when the wiper position is unknown.
+ * (The chip does not support reading the current position.)
+ */
+#define MAX5432_INVALID_POS (MAX5432_MAX_POS + 1)
 
 #define MAX5432_OHM_50K   (50  * 1000)
 #define MAX5432_OHM_100K  (100 * 1000)
 
 /* Update the volatile (currently active) setting. */
 #define MAX5432_CMD_VREG  0x11
+/*
+ * Update the non-volatile setting that's used to initialize the wiper
+ * at startup.
+ */
+#define MAX5432_CMD_NVREG 0x21
+
+/*
+ * Wiper position is in bits D7-D3 of the data byte.
+ * (D2-D0 are don't care bits.)
+ */
+#define WIPER_POS_DATA(pos) ((pos) << 3)
 
 struct max5432_data {
struct i2c_client *client;
unsigned long ohm;
+   u8 wiper_pos;
 };
 
 static const struct iio_chan_spec max5432_channels[] = {
@@ -63,7 +80,6 @@ static int max5432_write_raw(struct iio_dev *indio_dev,
int val, int val2, long mask)
 {
struct max5432_data *data = iio_priv(indio_dev);
-   u8 data_byte;
 
if (mask != IIO_CHAN_INFO_RAW)
return -EINVAL;
@@ -74,10 +90,10 @@ static int max5432_write_raw(struct iio_dev *indio_dev,
if (val2 != 0)
return -EINVAL;
 
-   /* Wiper position is in bits D7-D3. (D2-D0 are don't care bits.) */
-   data_byte = val << 3;
+   data->wiper_pos = val;
+
return i2c_smbus_write_byte_data(data->client, chan->address,
-   data_byte);
+   WIPER_POS_DATA(data->wiper_pos));
 }
 
 static const struct iio_info max5432_info = {
@@ -101,6 +117,7 @@ static int max5432_probe(struct i2c_client *client,
data = iio_priv(indio_dev);
data->client = client;
data->ohm = (unsigned long)of_device_get_match_data(dev);
+   data->wiper_pos = MAX5432_INVALID_POS;
 
indio_dev->dev.parent = dev;
indio_dev->info = _info;
@@ -111,6 +128,23 @@ static int max5432_probe(struct i2c_client *client,
return devm_iio_device_register(dev, indio_dev);
 }
 
+static void max5432_shutdown(struct i2c_client *client)
+{
+   struct iio_dev *indio_dev;
+   struct max5432_data *data;
+
+   indio_dev = i2c_get_clientdata(client);
+   if (!indio_dev)
+   return;
+
+   data = iio_priv(indio_dev);
+   if (data->wiper_pos == MAX5432_INVALID_POS)
+   return;
+
+   i2c_smbus_write_byte_data(client, MAX5432_CMD_NVREG,
+   WIPER_POS_DATA(data->wiper_pos));
+}
+
 static const struct of_device_id max5432_dt_ids[] = {
{ .compatible = "maxim,max5432", .data = (void *)MAX5432_OHM_50K  },
{ .compatible = "maxim,max5433", .data = (void *)MAX5432_OHM_100K },
@@ -126,6 +160,7 @@ static struct i2c_driver max5432_driver = {
.of_match_table = of_match_ptr(max5432_dt_ids),
},
.probe = max5432_probe,
+   .shutdown = max5432_shutdown,
 };
 
 module_i2c_driver(max5432_driver);
-- 
2.11.0



[PATCH 3/8] ARM: dts: eukrea-mbimxsd27: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx27-eukrea-mbimxsd27-baseboard.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx27-eukrea-mbimxsd27-baseboard.dts 
b/arch/arm/boot/dts/imx27-eukrea-mbimxsd27-baseboard.dts
index 84fc8df4be7c..9c3ec82ec7e5 100644
--- a/arch/arm/boot/dts/imx27-eukrea-mbimxsd27-baseboard.dts
+++ b/arch/arm/boot/dts/imx27-eukrea-mbimxsd27-baseboard.dts
@@ -11,11 +11,11 @@
 
display0: CMO-QVGA {
model = "CMO-QVGA";
-   native-mode = <>;
bits-per-pixel = <16>;
fsl,pcr = <0xfad08b80>;
 
display-timings {
+   native-mode = <>;
timing0: 320x240 {
clock-frequency = <650>;
hactive = <320>;
-- 
2.11.0



[PATCH 5/8] ARM: dts: imx27-phytec-phycore-rdk: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx27-phytec-phycore-rdk.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx27-phytec-phycore-rdk.dts 
b/arch/arm/boot/dts/imx27-phytec-phycore-rdk.dts
index 5606f417e9e8..bf883e45576a 100644
--- a/arch/arm/boot/dts/imx27-phytec-phycore-rdk.dts
+++ b/arch/arm/boot/dts/imx27-phytec-phycore-rdk.dts
@@ -14,11 +14,11 @@
 
display0: LQ035Q7 {
model = "Sharp-LQ035Q7";
-   native-mode = <>;
bits-per-pixel = <16>;
fsl,pcr = <0xf00080c0>;
 
display-timings {
+   native-mode = <>;
timing0: 240x320 {
clock-frequency = <550>;
hactive = <240>;
-- 
2.11.0



[PATCH 6/8] ARM: dts: edb7211: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/ep7211-edb7211.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/ep7211-edb7211.dts 
b/arch/arm/boot/dts/ep7211-edb7211.dts
index a0c270f63fee..da076479c8e2 100644
--- a/arch/arm/boot/dts/ep7211-edb7211.dts
+++ b/arch/arm/boot/dts/ep7211-edb7211.dts
@@ -25,11 +25,11 @@
 
display: display {
model = "320x240x4";
-   native-mode = <>;
bits-per-pixel = <4>;
ac-prescale = <17>;
 
display-timings {
+   native-mode = <>;
timing0: 320x240 {
hactive = <320>;
hback-porch = <0>;
-- 
2.11.0



[PATCH 4/8] ARM: dts: mbimxsd25: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-cmo-qvga.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-cmo-qvga.dts 
b/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-cmo-qvga.dts
index dbecd6d2cfc4..7d4301b22b90 100644
--- a/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-cmo-qvga.dts
+++ b/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-cmo-qvga.dts
@@ -14,8 +14,8 @@
bits-per-pixel = <16>;
fsl,pcr = <0xcad08b80>;
bus-width = <18>;
-   native-mode = <_timings>;
display-timings {
+   native-mode = <_timings>;
qvga_timings: 320x240 {
clock-frequency = <650>;
hactive = <320>;
-- 
2.11.0



[PATCH 8/8] ARM: dts: imx25: mbimxsd25: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dts 
b/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dts
index d60d8f464ca9..24027a1fb46d 100644
--- a/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dts
+++ b/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-vga.dts
@@ -14,8 +14,8 @@
bits-per-pixel = <16>;
fsl,pcr = <0xfa208b80>;
bus-width = <18>;
-   native-mode = <_vga_timings>;
display-timings {
+   native-mode = <_vga_timings>;
dvi_vga_timings: 640x480 {
clock-frequency = <3125>;
hactive = <640>;
-- 
2.11.0



[PATCH 7/8] ARM: dts: apf27dev: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx27-apf27dev.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx27-apf27dev.dts 
b/arch/arm/boot/dts/imx27-apf27dev.dts
index 087c6e237af0..6f1e8ce9e76e 100644
--- a/arch/arm/boot/dts/imx27-apf27dev.dts
+++ b/arch/arm/boot/dts/imx27-apf27dev.dts
@@ -12,10 +12,10 @@
 
display: display {
model = "Chimei-LW700AT9003";
-   native-mode = <>;
bits-per-pixel = <16>;  /* non-standard but required */
fsl,pcr = <0xfae80083>; /* non-standard but required */
display-timings {
+   native-mode = <>;
timing0: 800x480 {
clock-frequency = <3333>;
hactive = <800>;
-- 
2.11.0



[PATCH 1/8] ARM: dts: imx27 phyCARD-S: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx27-phytec-phycard-s-rdk.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx27-phytec-phycard-s-rdk.dts 
b/arch/arm/boot/dts/imx27-phytec-phycard-s-rdk.dts
index 5e5e282ed30e..0cd75dadf292 100644
--- a/arch/arm/boot/dts/imx27-phytec-phycard-s-rdk.dts
+++ b/arch/arm/boot/dts/imx27-phytec-phycard-s-rdk.dts
@@ -15,10 +15,10 @@
 
display: display {
model = "Primeview-PD050VL1";
-   native-mode = <>;
bits-per-pixel = <16>;  /* non-standard but required */
fsl,pcr = <0xf0c88080>; /* non-standard but required */
display-timings {
+   native-mode = <>;
timing0: 640x480 {
hactive = <640>;
vactive = <480>;
-- 
2.11.0



[PATCH 2/8] ARM: dts: imx25: mbimxsd25: native-mode is part of display-timings

2019-08-01 Thread Martin Kaiser
Move the native-mode property inside the display-timings node.

According to
Documentation/devicetree/bindings/display/panel/display-timing.txt.
native-mode is a property of the display-timings node.

If it's located outside of display-timings, the native-mode setting is
ignored and the first display timing is used (which is a problem only if
someone adds another display timing).

Signed-off-by: Martin Kaiser 
---
 arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-svga.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-svga.dts 
b/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-svga.dts
index ad2f7e879831..80a7f96de4c6 100644
--- a/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-svga.dts
+++ b/arch/arm/boot/dts/imx25-eukrea-mbimxsd25-baseboard-dvi-svga.dts
@@ -14,8 +14,8 @@
bits-per-pixel = <16>;
fsl,pcr = <0xfa208b80>;
bus-width = <18>;
-   native-mode = <_svga_timings>;
display-timings {
+   native-mode = <_svga_timings>;
dvi_svga_timings: 800x600 {
clock-frequency = <4000>;
hactive = <800>;
-- 
2.11.0



  1   2   3   4   >