[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20110503215828.GJ5352@nuttenaction>
Date: Tue, 3 May 2011 23:58:29 +0200
From: Hagen Paul Pfeifer <hagen@...u.net>
To: Thiago Farina <tfransosi@...il.com>
Cc: Mark Brown <broonie@...nsource.wolfsonmicro.com>,
Liam Girdwood <lrg@...mlogic.co.uk>,
linux list <linux-kernel@...r.kernel.org>
Subject: Re: regulators: kzalloc doubt
* Thiago Farina | 2011-05-03 18:54:13 [-0300]:
>What is the preferred way to use kzalloc? I have seen two ways under
>drivers/regulator/.
>
>1-
>
>struct my_regulator_info *info = NULL;
>
>info = kzalloc(sizeof(struct my_regulator_info), GFP_KERNEL);
>
>2-
>
>struct my_regulator_info *info;
>
>info = kzalloc(sizeof(*info), GFP_KERNEL);
Documentation/CodingStyle - Chapter 14: Allocating memory:
[...]
The preferred form for passing a size of a struct is the following:
p = kmalloc(sizeof(*p), ...);
The alternative form where struct name is spelled out hurts readability and
introduces an opportunity for a bug when the pointer variable type is changed
but the corresponding sizeof that is passed to a memory allocator is not.
Casting the return value which is a void pointer is redundant. The conversion
from void pointer to any other pointer type is guaranteed by the C programming
language.
Cheers, Hagen
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists