linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF()
@ 2023-02-02 20:58 Christophe JAILLET
  2023-02-05 13:18 ` Loic Poulain
  2023-02-24 10:22 ` Kalle Valo
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-02-02 20:58 UTC (permalink / raw)
  To: Loic Poulain, Kalle Valo, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, wcn36xx,
	linux-wireless, netdev

In most (likely all) cases, INIT_HAL_MSG() is called before
PREPARE_HAL_BUF().
In such cases calling memset() is useless because:
   msg_body.header.len = sizeof(msg_body)

So, instead of writing twice the memory, we just have a sanity check to
make sure that some potential trailing memory is zeroed.
It even gives the opportunity to see that by itself and optimize it away.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/wcn36xx/smd.c b/drivers/net/wireless/ath/wcn36xx/smd.c
index 566f0b9c1584..17e1919d1cd8 100644
--- a/drivers/net/wireless/ath/wcn36xx/smd.c
+++ b/drivers/net/wireless/ath/wcn36xx/smd.c
@@ -475,8 +475,8 @@ static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
 
 #define PREPARE_HAL_BUF(send_buf, msg_body) \
 	do {							\
-		memset(send_buf, 0, msg_body.header.len);	\
-		memcpy(send_buf, &msg_body, sizeof(msg_body));	\
+		memcpy_and_pad(send_buf, msg_body.header.len,	\
+			       &msg_body, sizeof(msg_body), 0);	\
 	} while (0)						\
 
 #define PREPARE_HAL_PTT_MSG_BUF(send_buf, p_msg_body) \
-- 
2.34.1


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

* Re: [PATCH net-next] wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF()
  2023-02-02 20:58 [PATCH net-next] wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF() Christophe JAILLET
@ 2023-02-05 13:18 ` Loic Poulain
  2023-02-24 10:22 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Loic Poulain @ 2023-02-05 13:18 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Kalle Valo, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, wcn36xx,
	linux-wireless, netdev

On Thu, 2 Feb 2023 at 21:58, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> In most (likely all) cases, INIT_HAL_MSG() is called before
> PREPARE_HAL_BUF().
> In such cases calling memset() is useless because:
>    msg_body.header.len = sizeof(msg_body)
>
> So, instead of writing twice the memory, we just have a sanity check to
> make sure that some potential trailing memory is zeroed.
> It even gives the opportunity to see that by itself and optimize it away.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Loic Poulain <loic.poulain@linaro.org>



> ---
>  drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/wcn36xx/smd.c b/drivers/net/wireless/ath/wcn36xx/smd.c
> index 566f0b9c1584..17e1919d1cd8 100644
> --- a/drivers/net/wireless/ath/wcn36xx/smd.c
> +++ b/drivers/net/wireless/ath/wcn36xx/smd.c
> @@ -475,8 +475,8 @@ static int wcn36xx_smd_send_and_wait(struct wcn36xx *wcn, size_t len)
>
>  #define PREPARE_HAL_BUF(send_buf, msg_body) \
>         do {                                                    \
> -               memset(send_buf, 0, msg_body.header.len);       \
> -               memcpy(send_buf, &msg_body, sizeof(msg_body));  \
> +               memcpy_and_pad(send_buf, msg_body.header.len,   \
> +                              &msg_body, sizeof(msg_body), 0); \
>         } while (0)                                             \
>
>  #define PREPARE_HAL_PTT_MSG_BUF(send_buf, p_msg_body) \
> --
> 2.34.1
>

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

* Re: [PATCH net-next] wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF()
  2023-02-02 20:58 [PATCH net-next] wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF() Christophe JAILLET
  2023-02-05 13:18 ` Loic Poulain
@ 2023-02-24 10:22 ` Kalle Valo
  1 sibling, 0 replies; 3+ messages in thread
From: Kalle Valo @ 2023-02-24 10:22 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Loic Poulain, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, Christophe JAILLET,
	wcn36xx, linux-wireless, netdev

Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> In most (likely all) cases, INIT_HAL_MSG() is called before
> PREPARE_HAL_BUF().
> In such cases calling memset() is useless because:
>    msg_body.header.len = sizeof(msg_body)
> 
> So, instead of writing twice the memory, we just have a sanity check to
> make sure that some potential trailing memory is zeroed.
> It even gives the opportunity to see that by itself and optimize it away.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Acked-by: Loic Poulain <loic.poulain@linaro.org>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

4a51e66fe96d wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF()

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/7d8ab7fee45222cdbaf80c507525f2d3941587c1.1675371372.git.christophe.jaillet@wanadoo.fr/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 20:58 [PATCH net-next] wifi: wcn36xx: Slightly optimize PREPARE_HAL_BUF() Christophe JAILLET
2023-02-05 13:18 ` Loic Poulain
2023-02-24 10:22 ` Kalle Valo

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).