linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: simplify if-if to if-else
@ 2022-04-08  7:42 Yihao Han
  2022-04-08  8:51 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Yihao Han @ 2022-04-08  7:42 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Fabio Aiuto, Yihao Han, Hans de Goede,
	Fabio M. De Francesco, Xiangyang Zhang, Lee Jones,
	Bryan Brattlof, linux-staging, linux-kernel
  Cc: kernel

Replace `if (!recvbuf->pskb)` with `else` for simplification and add curly
brackets according to the kernel coding style:

"Do not unnecessarily use braces where a single statement will do."

...

"This does not apply if only one branch of a conditional statement is
a single statement; in the latter case use braces in both branches"

Please refer to:
https://www.kernel.org/doc/html/v5.17-rc8/process/coding-style.html

Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 drivers/staging/rtl8723bs/hal/sdio_ops.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c
index a545832a468e..739fea437f69 100644
--- a/drivers/staging/rtl8723bs/hal/sdio_ops.c
+++ b/drivers/staging/rtl8723bs/hal/sdio_ops.c
@@ -818,10 +818,9 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size)
 			tmpaddr = (SIZE_PTR)recvbuf->pskb->data;
 			alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
 			skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
-		}
-
-		if (!recvbuf->pskb)
+		} else {
 			return NULL;
+		}
 	}
 
 	/* 3 3. read data from rxfifo */
-- 
2.17.1


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

* Re: [PATCH] staging: rtl8723bs: simplify if-if to if-else
  2022-04-08  7:42 [PATCH] staging: rtl8723bs: simplify if-if to if-else Yihao Han
@ 2022-04-08  8:51 ` Dan Carpenter
  2022-04-08 13:59   ` [PATCH v2] staging: rtl8723bs: remove unnecessary `if` Yihao Han
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2022-04-08  8:51 UTC (permalink / raw)
  To: Yihao Han
  Cc: Greg Kroah-Hartman, Fabio Aiuto, Hans de Goede,
	Fabio M. De Francesco, Xiangyang Zhang, Lee Jones,
	Bryan Brattlof, linux-staging, linux-kernel, kernel

On Fri, Apr 08, 2022 at 12:42:40AM -0700, Yihao Han wrote:
> Replace `if (!recvbuf->pskb)` with `else` for simplification and add curly
> brackets according to the kernel coding style:
> 
> "Do not unnecessarily use braces where a single statement will do."
> 
> ...
> 
> "This does not apply if only one branch of a conditional statement is
> a single statement; in the latter case use braces in both branches"
> 
> Please refer to:
> https://www.kernel.org/doc/html/v5.17-rc8/process/coding-style.html
> 
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---
>  drivers/staging/rtl8723bs/hal/sdio_ops.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c
> index a545832a468e..739fea437f69 100644
> --- a/drivers/staging/rtl8723bs/hal/sdio_ops.c
> +++ b/drivers/staging/rtl8723bs/hal/sdio_ops.c
> @@ -818,10 +818,9 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size)
>  			tmpaddr = (SIZE_PTR)recvbuf->pskb->data;
>  			alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
>  			skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
> -		}
> -
> -		if (!recvbuf->pskb)
> +		} else {
>  			return NULL;
> +		}

Please do it a different way:

		recvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
		if (!recvbuf->pskb)
			return NULL;

Then pull the pull the other side in one tab.

regards,
dan carpenter



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

* [PATCH v2] staging: rtl8723bs: remove unnecessary `if`
  2022-04-08  8:51 ` Dan Carpenter
@ 2022-04-08 13:59   ` Yihao Han
  2022-04-08 14:12     ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Yihao Han @ 2022-04-08 13:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Fabio Aiuto, Yihao Han, Lee Jones,
	Xiangyang Zhang, Fabio M. De Francesco, Bryan Brattlof,
	linux-staging, linux-kernel
  Cc: kernel

remove a unnecesarry if in `sd_recv_rxfifo`

Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Yihao Han <hanyihao@vivo.com>
---
 drivers/staging/rtl8723bs/hal/sdio_ops.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8723bs/hal/sdio_ops.c b/drivers/staging/rtl8723bs/hal/sdio_ops.c
index a545832a468e..107f427ee4aa 100755
--- a/drivers/staging/rtl8723bs/hal/sdio_ops.c
+++ b/drivers/staging/rtl8723bs/hal/sdio_ops.c
@@ -811,17 +811,14 @@ static struct recv_buf *sd_recv_rxfifo(struct adapter *adapter, u32 size)
 		SIZE_PTR alignment = 0;
 
 		recvbuf->pskb = rtw_skb_alloc(MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
-
-		if (recvbuf->pskb) {
-			recvbuf->pskb->dev = adapter->pnetdev;
-
-			tmpaddr = (SIZE_PTR)recvbuf->pskb->data;
-			alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
-			skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
-		}
-
 		if (!recvbuf->pskb)
 			return NULL;
+
+		recvbuf->pskb->dev = adapter->pnetdev;
+
+		tmpaddr = (SIZE_PTR)recvbuf->pskb->data;
+		alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
+		skb_reserve(recvbuf->pskb, (RECVBUFF_ALIGN_SZ - alignment));
 	}
 
 	/* 3 3. read data from rxfifo */
-- 
2.17.1


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

* Re: [PATCH v2] staging: rtl8723bs: remove unnecessary `if`
  2022-04-08 13:59   ` [PATCH v2] staging: rtl8723bs: remove unnecessary `if` Yihao Han
@ 2022-04-08 14:12     ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2022-04-08 14:12 UTC (permalink / raw)
  To: Yihao Han
  Cc: Greg Kroah-Hartman, Fabio Aiuto, Lee Jones, Xiangyang Zhang,
	Fabio M. De Francesco, Bryan Brattlof, linux-staging,
	linux-kernel, kernel

On Fri, Apr 08, 2022 at 06:59:11AM -0700, Yihao Han wrote:
> remove a unnecesarry if in `sd_recv_rxfifo`
> 
> Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Yihao Han <hanyihao@vivo.com>
> ---
  ^^^
Under this cut off line then you need to say what changed since version
1.  Something like: "v2: more extensive cleanup.  v3: edit commit message".

I do want you to edit the commit message because I don't think it really
describes the patch very well.  How I would write this commit message is
this:

    [PATCH v3] staging: rtl8723bs: tidy up error handling

    The check for if rtw_skb_alloc() fails is done twice and is written
    in a confusing way.  Move the "if (!recvbuf->pskb)" right after
    the allocation.  The "if (recvbuf->pskb)" check can now be deleted
    and the code pulled in one tab.

To me this explains the problem and the solution.

regards,
dan carpenter


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

end of thread, other threads:[~2022-04-08 14:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08  7:42 [PATCH] staging: rtl8723bs: simplify if-if to if-else Yihao Han
2022-04-08  8:51 ` Dan Carpenter
2022-04-08 13:59   ` [PATCH v2] staging: rtl8723bs: remove unnecessary `if` Yihao Han
2022-04-08 14:12     ` Dan Carpenter

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