diff mbox series

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

Message ID 20210523075616.14792-1-yuehaibing@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ethernet: ucc_geth: Use kmemdup() rather than kmalloc+memcpy | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Yue Haibing May 23, 2021, 7:56 a.m. UTC
Issue identified with Coccinelle.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/ethernet/freescale/ucc_geth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christophe Leroy May 23, 2021, 1:29 p.m. UTC | #1
YueHaibing <yuehaibing@huawei.com> a écrit :

> Issue identified with Coccinelle.
>
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  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
Andrew Lunn May 23, 2021, 2:26 p.m. UTC | #2
On Sun, May 23, 2021 at 03:29:37PM +0200, Christophe Leroy wrote:
> YueHaibing <yuehaibing@huawei.com> a écrit :
> 
> > Issue identified with Coccinelle.
> > 
> > Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> > ---
> >  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
Yue Haibing May 24, 2021, 1:07 a.m. UTC | #3
On 2021/5/23 22:26, Andrew Lunn wrote:
> On Sun, May 23, 2021 at 03:29:37PM +0200, Christophe Leroy wrote:
>> YueHaibing <yuehaibing@huawei.com> a écrit :
>>
>>> Issue identified with Coccinelle.
>>>
>>> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
>>> ---
>>>  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
> .
>
diff mbox series

Patch

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;