All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: merge _rtw_enqueue_cmd into its caller
@ 2023-02-11 16:50 Martin Kaiser
  2023-02-13 19:23 ` Philipp Hortmann
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Kaiser @ 2023-02-11 16:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel, Martin Kaiser

The _rtw_enqueue_cmd function is called only by rtw_enqueue_cmd.

When _rtw_enqueue_cmd is called, the caller has already checked that the
obj parameter is not NULL. _rtw_enqueue_cmd returns _SUCCESS in any case.

We can merge the two functions and simplify the error handling.

Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 drivers/staging/r8188eu/core/rtw_cmd.c | 47 +++++---------------------
 1 file changed, 9 insertions(+), 38 deletions(-)

diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
index d57360a68fb3..ca9e3d4ee7f4 100644
--- a/drivers/staging/r8188eu/core/rtw_cmd.c
+++ b/drivers/staging/r8188eu/core/rtw_cmd.c
@@ -28,32 +28,6 @@ void rtw_free_evt_priv(struct	evt_priv *pevtpriv)
 	}
 }
 
-/* Calling Context:
- *
- * rtw_enqueue_cmd can only be called between kernel thread,
- * since only spin_lock is used.
- *
- * ISR/Call-Back functions can't call this sub-function.
- */
-
-static int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj)
-{
-	unsigned long flags;
-
-	if (!obj)
-		goto exit;
-
-	spin_lock_irqsave(&queue->lock, flags);
-
-	list_add_tail(&obj->list, &queue->queue);
-
-	spin_unlock_irqrestore(&queue->lock, flags);
-
-exit:
-
-	return _SUCCESS;
-}
-
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
 	init_completion(&pcmdpriv->enqueue_cmd);
@@ -125,28 +99,25 @@ static int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
 
 u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
 {
-	int res = _FAIL;
+	unsigned long flags;
 	struct adapter *padapter = pcmdpriv->padapter;
 
 	if (!cmd_obj)
-		goto exit;
+		return _FAIL;
 
 	cmd_obj->padapter = padapter;
 
-	res = rtw_cmd_filter(pcmdpriv, cmd_obj);
-	if (res == _FAIL) {
+	if (rtw_cmd_filter(pcmdpriv, cmd_obj) == _FAIL) {
 		rtw_free_cmd_obj(cmd_obj);
-		goto exit;
+		return _FAIL;
 	}
 
-	res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
-
-	if (res == _SUCCESS)
-		complete(&pcmdpriv->enqueue_cmd);
+	spin_lock_irqsave(&pcmdpriv->cmd_queue.lock, flags);
+	list_add_tail(&cmd_obj->list, &pcmdpriv->cmd_queue.queue);
+	spin_unlock_irqrestore(&pcmdpriv->cmd_queue.lock, flags);
 
-exit:
-
-	return res;
+	complete(&pcmdpriv->enqueue_cmd);
+	return _SUCCESS;
 }
 
 struct	cmd_obj	*rtw_dequeue_cmd(struct cmd_priv *pcmdpriv)
-- 
2.30.2


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

* Re: [PATCH] staging: r8188eu: merge _rtw_enqueue_cmd into its caller
  2023-02-11 16:50 [PATCH] staging: r8188eu: merge _rtw_enqueue_cmd into its caller Martin Kaiser
@ 2023-02-13 19:23 ` Philipp Hortmann
  0 siblings, 0 replies; 2+ messages in thread
From: Philipp Hortmann @ 2023-02-13 19:23 UTC (permalink / raw)
  To: Martin Kaiser, Greg Kroah-Hartman
  Cc: Larry Finger, Phillip Potter, Michael Straube, Pavel Skripkin,
	linux-staging, linux-kernel

On 2/11/23 17:50, Martin Kaiser wrote:
> The _rtw_enqueue_cmd function is called only by rtw_enqueue_cmd.
> 
> When _rtw_enqueue_cmd is called, the caller has already checked that the
> obj parameter is not NULL. _rtw_enqueue_cmd returns _SUCCESS in any case.
> 
> We can merge the two functions and simplify the error handling.
> 
> Signed-off-by: Martin Kaiser <martin@kaiser.cx>
> ---
>   drivers/staging/r8188eu/core/rtw_cmd.c | 47 +++++---------------------
>   1 file changed, 9 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/staging/r8188eu/core/rtw_cmd.c b/drivers/staging/r8188eu/core/rtw_cmd.c
> index d57360a68fb3..ca9e3d4ee7f4 100644
> --- a/drivers/staging/r8188eu/core/rtw_cmd.c
> +++ b/drivers/staging/r8188eu/core/rtw_cmd.c
> @@ -28,32 +28,6 @@ void rtw_free_evt_priv(struct	evt_priv *pevtpriv)
>   	}
>   }
>   
> -/* Calling Context:
> - *
> - * rtw_enqueue_cmd can only be called between kernel thread,
> - * since only spin_lock is used.
> - *
> - * ISR/Call-Back functions can't call this sub-function.
> - */
> -
> -static int _rtw_enqueue_cmd(struct __queue *queue, struct cmd_obj *obj)
> -{
> -	unsigned long flags;
> -
> -	if (!obj)
> -		goto exit;
> -
> -	spin_lock_irqsave(&queue->lock, flags);
> -
> -	list_add_tail(&obj->list, &queue->queue);
> -
> -	spin_unlock_irqrestore(&queue->lock, flags);
> -
> -exit:
> -
> -	return _SUCCESS;
> -}
> -
>   int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
>   {
>   	init_completion(&pcmdpriv->enqueue_cmd);
> @@ -125,28 +99,25 @@ static int rtw_cmd_filter(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
>   
>   u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
>   {
> -	int res = _FAIL;
> +	unsigned long flags;
>   	struct adapter *padapter = pcmdpriv->padapter;
>   
>   	if (!cmd_obj)
> -		goto exit;
> +		return _FAIL;
>   
>   	cmd_obj->padapter = padapter;
>   
> -	res = rtw_cmd_filter(pcmdpriv, cmd_obj);
> -	if (res == _FAIL) {
> +	if (rtw_cmd_filter(pcmdpriv, cmd_obj) == _FAIL) {
>   		rtw_free_cmd_obj(cmd_obj);
> -		goto exit;
> +		return _FAIL;
>   	}
>   
> -	res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
> -
> -	if (res == _SUCCESS)
> -		complete(&pcmdpriv->enqueue_cmd);
> +	spin_lock_irqsave(&pcmdpriv->cmd_queue.lock, flags);
> +	list_add_tail(&cmd_obj->list, &pcmdpriv->cmd_queue.queue);
> +	spin_unlock_irqrestore(&pcmdpriv->cmd_queue.lock, flags);
>   
> -exit:
> -
> -	return res;
> +	complete(&pcmdpriv->enqueue_cmd);
> +	return _SUCCESS;
>   }
>   
>   struct	cmd_obj	*rtw_dequeue_cmd(struct cmd_priv *pcmdpriv)

Tested-by: Philipp Hortmann <philipp.g.hortmann@gmail.com> # Edimax N150


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

end of thread, other threads:[~2023-02-13 19:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-11 16:50 [PATCH] staging: r8188eu: merge _rtw_enqueue_cmd into its caller Martin Kaiser
2023-02-13 19:23 ` Philipp Hortmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.