diff mbox series

[02/12] net: smc911x: Replace malloc()+memset() with calloc()

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

Commit Message

Marek Vasut March 15, 2020, 4:58 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>
---
 drivers/net/smc911x.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Joe Hershberger March 16, 2020, 11:58 p.m. UTC | #1
On Sun, Mar 15, 2020 at 12:00 PM Marek Vasut <marek.vasut at gmail.com> wrote:
>
> 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>

Acked-by: Joe Hershberger <joe.hershberger at ni.com>
Masahiro Yamada March 17, 2020, 6:20 a.m. UTC | #2
On Mon, Mar 16, 2020 at 2:00 AM Marek Vasut <marek.vasut at gmail.com> wrote:
>
> 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>
> ---
>  drivers/net/smc911x.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
> index 24b4eaeb3f..a78b7817ac 100644
> --- a/drivers/net/smc911x.c
> +++ b/drivers/net/smc911x.c
> @@ -242,11 +242,10 @@ int smc911x_initialize(u8 dev_num, int base_addr)
>         unsigned long addrl, addrh;
>         struct eth_device *dev;
>
> -       dev = malloc(sizeof(*dev));
> +       dev = calloc(1, sizeof(*dev));
>         if (!dev) {
>                 return -1;
>         }
> -       memset(dev, 0, sizeof(*dev));
>
>         dev->iobase = base_addr;
>



My personal preference is kzalloc(), but
the reason is just I am addicted to Linux.
So, I do not mind this.

(Another reason I tend to avoid calloc() is I always
forget the order of 'nmemb' and 'size' arguments)
diff mbox series

Patch

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