All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory
@ 2023-01-19  9:22 Yang Yingliang
  2023-01-20  2:04 ` Jesse Brandeburg
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yang Yingliang @ 2023-01-19  9:22 UTC (permalink / raw)
  To: netdev
  Cc: lars.povlsen, Steen.Hegelund, daniel.machon, UNGLinuxDriver,
	davem, edumazet, kuba, pabeni

Use kmemdup() helper instead of open-coding to simplify
the code when allocating newckf and newcaf.

Generated by: scripts/coccinelle/api/memdup.cocci

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/net/ethernet/microchip/vcap/vcap_api.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
index 71f787a78295..d9cf2cd1925a 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -1000,18 +1000,16 @@ static struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri,
 		return duprule;
 
 	list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) {
-		newckf = kzalloc(sizeof(*newckf), GFP_KERNEL);
+		newckf = kmemdup(ckf, sizeof(*newckf), GFP_KERNEL);
 		if (!newckf)
 			return ERR_PTR(-ENOMEM);
-		memcpy(newckf, ckf, sizeof(*newckf));
 		list_add_tail(&newckf->ctrl.list, &duprule->data.keyfields);
 	}
 
 	list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) {
-		newcaf = kzalloc(sizeof(*newcaf), GFP_KERNEL);
+		newcaf = kmemdup(caf, sizeof(*newcaf), GFP_KERNEL);
 		if (!newcaf)
 			return ERR_PTR(-ENOMEM);
-		memcpy(newcaf, caf, sizeof(*newcaf));
 		list_add_tail(&newcaf->ctrl.list, &duprule->data.actionfields);
 	}
 
-- 
2.25.1


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

* Re: [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory
  2023-01-19  9:22 [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory Yang Yingliang
@ 2023-01-20  2:04 ` Jesse Brandeburg
  2023-01-20  8:05 ` Steen Hegelund
  2023-01-21  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jesse Brandeburg @ 2023-01-20  2:04 UTC (permalink / raw)
  To: Yang Yingliang, netdev
  Cc: lars.povlsen, Steen.Hegelund, daniel.machon, UNGLinuxDriver,
	davem, edumazet, kuba, pabeni

On 1/19/2023 1:22 AM, Yang Yingliang wrote:
> Use kmemdup() helper instead of open-coding to simplify
> the code when allocating newckf and newcaf.
> 
> Generated by: scripts/coccinelle/api/memdup.cocci
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>   drivers/net/ethernet/microchip/vcap/vcap_api.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)

I don't like kmemdup much as you have to be very careful to make sure 
the original memory is freed in the error case. However this code seems 
like it works correctly since it was already having to free the source 
memory earlier.

Reviewed-by: Jesse Brandeburg <jesse.brandeburg@intel.com>


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

* Re: [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory
  2023-01-19  9:22 [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory Yang Yingliang
  2023-01-20  2:04 ` Jesse Brandeburg
@ 2023-01-20  8:05 ` Steen Hegelund
  2023-01-21  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Steen Hegelund @ 2023-01-20  8:05 UTC (permalink / raw)
  To: Yang Yingliang, netdev
  Cc: lars.povlsen, daniel.machon, UNGLinuxDriver, davem, edumazet,
	kuba, pabeni

Hi Yang,

Thanks for the correction.

Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>

BR
Steen

On Thu, 2023-01-19 at 17:22 +0800, Yang Yingliang wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> Use kmemdup() helper instead of open-coding to simplify
> the code when allocating newckf and newcaf.
> 
> Generated by: scripts/coccinelle/api/memdup.cocci
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  drivers/net/ethernet/microchip/vcap/vcap_api.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c
> b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> index 71f787a78295..d9cf2cd1925a 100644
> --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
> +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> @@ -1000,18 +1000,16 @@ static struct vcap_rule_internal *vcap_dup_rule(struct
> vcap_rule_internal *ri,
>                 return duprule;
> 
>         list_for_each_entry(ckf, &ri->data.keyfields, ctrl.list) {
> -               newckf = kzalloc(sizeof(*newckf), GFP_KERNEL);
> +               newckf = kmemdup(ckf, sizeof(*newckf), GFP_KERNEL);
>                 if (!newckf)
>                         return ERR_PTR(-ENOMEM);
> -               memcpy(newckf, ckf, sizeof(*newckf));
>                 list_add_tail(&newckf->ctrl.list, &duprule->data.keyfields);
>         }
> 
>         list_for_each_entry(caf, &ri->data.actionfields, ctrl.list) {
> -               newcaf = kzalloc(sizeof(*newcaf), GFP_KERNEL);
> +               newcaf = kmemdup(caf, sizeof(*newcaf), GFP_KERNEL);
>                 if (!newcaf)
>                         return ERR_PTR(-ENOMEM);
> -               memcpy(newcaf, caf, sizeof(*newcaf));
>                 list_add_tail(&newcaf->ctrl.list, &duprule-
> >data.actionfields);
>         }
> 
> --
> 2.25.1
> 


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

* Re: [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory
  2023-01-19  9:22 [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory Yang Yingliang
  2023-01-20  2:04 ` Jesse Brandeburg
  2023-01-20  8:05 ` Steen Hegelund
@ 2023-01-21  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-01-21  2:20 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: netdev, lars.povlsen, Steen.Hegelund, daniel.machon,
	UNGLinuxDriver, davem, edumazet, kuba, pabeni

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Thu, 19 Jan 2023 17:22:10 +0800 you wrote:
> Use kmemdup() helper instead of open-coding to simplify
> the code when allocating newckf and newcaf.
> 
> Generated by: scripts/coccinelle/api/memdup.cocci
> 
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> 
> [...]

Here is the summary with links:
  - [net-next] net: microchip: vcap: use kmemdup() to allocate memory
    https://git.kernel.org/netdev/net-next/c/5e64f59a3cc2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-01-21  2:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-19  9:22 [PATCH net-next] net: microchip: vcap: use kmemdup() to allocate memory Yang Yingliang
2023-01-20  2:04 ` Jesse Brandeburg
2023-01-20  8:05 ` Steen Hegelund
2023-01-21  2:20 ` patchwork-bot+netdevbpf

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.