[PATCH net-next] ethernet: ucc_geth: Use kmemdup() rather than kmalloc+memcpy

Subsystems: freescale quicc engine ucc ethernet driver, networking drivers, the rest

STALE1899d

4 messages, 3 authors, 2021-05-24 · open the first message on its own page

[PATCH net-next] ethernet: ucc_geth: Use kmemdup() rather than kmalloc+memcpy

From: YueHaibing <hidden>
Date: 2021-05-23 08:01:00

Issue identified with Coccinelle.

Signed-off-by: YueHaibing <redacted>
---
 drivers/net/ethernet/freescale/ucc_geth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index e0936510fa34..51206272cc25 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3590,10 +3590,10 @@ static int ucc_geth_probe(struct platform_device* ofdev)
 	if ((ucc_num < 0) || (ucc_num > 7))
 		return -ENODEV;
 
-	ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL);
+	ug_info = kmemdup(&ugeth_primary_info, sizeof(*ug_info),
+			  GFP_KERNEL);
 	if (ug_info == NULL)
 		return -ENOMEM;
-	memcpy(ug_info, &ugeth_primary_info, sizeof(*ug_info));
 
 	ug_info->uf_info.ucc_num = ucc_num;
 
-- 
2.17.1

Re: [PATCH net-next] ethernet: ucc_geth: Use kmemdup() rather than kmalloc+memcpy

From: Christophe Leroy <hidden>
Date: 2021-05-23 13:35:00

YueHaibing [off-list ref] a écrit :
quoted hunk
Issue identified with Coccinelle.

Signed-off-by: YueHaibing <redacted>
---
 drivers/net/ethernet/freescale/ucc_geth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c  
b/drivers/net/ethernet/freescale/ucc_geth.c
index e0936510fa34..51206272cc25 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3590,10 +3590,10 @@ static int ucc_geth_probe(struct  
platform_device* ofdev)
 	if ((ucc_num < 0) || (ucc_num > 7))
 		return -ENODEV;

-	ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL);
+	ug_info = kmemdup(&ugeth_primary_info, sizeof(*ug_info),
+			  GFP_KERNEL);
Can you keep that as a single line ? The tolerance is 100 chars per line now.
 	if (ug_info == NULL)
 		return -ENOMEM;
-	memcpy(ug_info, &ugeth_primary_info, sizeof(*ug_info));

 	ug_info->uf_info.ucc_num = ucc_num;

--
2.17.1

Re: [PATCH net-next] ethernet: ucc_geth: Use kmemdup() rather than kmalloc+memcpy

From: Andrew Lunn <andrew@lunn.ch>
Date: 2021-05-23 14:27:10

On Sun, May 23, 2021 at 03:29:37PM +0200, Christophe Leroy wrote:
YueHaibing [off-list ref] a écrit :
quoted
Issue identified with Coccinelle.

Signed-off-by: YueHaibing <redacted>
---
 drivers/net/ethernet/freescale/ucc_geth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c
b/drivers/net/ethernet/freescale/ucc_geth.c
index e0936510fa34..51206272cc25 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3590,10 +3590,10 @@ static int ucc_geth_probe(struct
platform_device* ofdev)
 	if ((ucc_num < 0) || (ucc_num > 7))
 		return -ENODEV;

-	ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL);
+	ug_info = kmemdup(&ugeth_primary_info, sizeof(*ug_info),
+			  GFP_KERNEL);
Can you keep that as a single line ? The tolerance is 100 chars per line now.
Networking prefers 80. If it fits a single 80 char line, please use a single line.
Otherwise please leave it as it is.

	   Andrew

Re: [PATCH net-next] ethernet: ucc_geth: Use kmemdup() rather than kmalloc+memcpy

From: YueHaibing <hidden>
Date: 2021-05-24 01:07:51

On 2021/5/23 22:26, Andrew Lunn wrote:
On Sun, May 23, 2021 at 03:29:37PM +0200, Christophe Leroy wrote:
quoted
YueHaibing [off-list ref] a écrit :
quoted
Issue identified with Coccinelle.

Signed-off-by: YueHaibing <redacted>
---
 drivers/net/ethernet/freescale/ucc_geth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c
b/drivers/net/ethernet/freescale/ucc_geth.c
index e0936510fa34..51206272cc25 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -3590,10 +3590,10 @@ static int ucc_geth_probe(struct
platform_device* ofdev)
 	if ((ucc_num < 0) || (ucc_num > 7))
 		return -ENODEV;

-	ug_info = kmalloc(sizeof(*ug_info), GFP_KERNEL);
+	ug_info = kmemdup(&ugeth_primary_info, sizeof(*ug_info),
+			  GFP_KERNEL);
Can you keep that as a single line ? The tolerance is 100 chars per line now.
Networking prefers 80. If it fits a single 80 char line, please use a single line.
Otherwise please leave it as it is.
Ok, will send v2.
	   Andrew
.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help