diff mbox series

[V2,02/13] net: smc911x: Replace malloc()+memset() with calloc()

Message ID 20200321170508.82753-3-marek.vasut+renesas@gmail.com
State Superseded
Headers show
Series net: smc911x: Convert to DM | expand

Commit Message

Marek Vasut March 21, 2020, 5:04 p.m. UTC
Replace combination of malloc()+memset() with calloc() as the behavior
is exactly the same and the amount of code is reduced.

Signed-off-by: Marek Vasut <marek.vasut+renesas at gmail.com>
Cc: Joe Hershberger <joe.hershberger at ni.com>
Cc: Masahiro Yamada <yamada.masahiro at socionext.com>
---
V2: - Use kzalloc()
    - Return -ENOMEM on alloc fail
---
 drivers/net/smc911x.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Masahiro Yamada March 22, 2020, 5:38 p.m. UTC | #1
On Sun, Mar 22, 2020 at 2:06 AM Marek Vasut <marek.vasut at gmail.com> wrote:
>
> Replace combination of malloc()+memset() with calloc() as the behavior

calloc() -> kzalloc()

to sync with the actual code.

Please fix the subject as well.





> is exactly the same and the amount of code is reduced.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas at gmail.com>
> Cc: Joe Hershberger <joe.hershberger at ni.com>
> Cc: Masahiro Yamada <yamada.masahiro at socionext.com>
> ---
> V2: - Use kzalloc()
>     - Return -ENOMEM on alloc fail
> ---
>  drivers/net/smc911x.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
> index 24b4eaeb3f..9a2a0f4435 100644
> --- a/drivers/net/smc911x.c
> +++ b/drivers/net/smc911x.c
> @@ -242,11 +242,9 @@ int smc911x_initialize(u8 dev_num, int base_addr)
>         unsigned long addrl, addrh;
>         struct eth_device *dev;
>
> -       dev = malloc(sizeof(*dev));
> -       if (!dev) {
> -               return -1;
> -       }
> -       memset(dev, 0, sizeof(*dev));
> +       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
> +       if (!dev)
> +               return -ENOMEM;
>
>         dev->iobase = base_addr;
>
> --
> 2.25.1
>
Marek Vasut March 25, 2020, 3:31 p.m. UTC | #2
On 3/22/20 6:38 PM, Masahiro Yamada wrote:
> On Sun, Mar 22, 2020 at 2:06 AM Marek Vasut <marek.vasut at gmail.com> wrote:
>>
>> Replace combination of malloc()+memset() with calloc() as the behavior
> 
> calloc() -> kzalloc()
> 
> to sync with the actual code.
> 
> Please fix the subject as well.

I'm switching this back to calloc(), it's not worth pulling in all the
linux compat stuff for one single function.
diff mbox series

Patch

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 24b4eaeb3f..9a2a0f4435 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -242,11 +242,9 @@  int smc911x_initialize(u8 dev_num, int base_addr)
 	unsigned long addrl, addrh;
 	struct eth_device *dev;
 
-	dev = malloc(sizeof(*dev));
-	if (!dev) {
-		return -1;
-	}
-	memset(dev, 0, sizeof(*dev));
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
 
 	dev->iobase = base_addr;