]> git.baikalelectronics.ru Git - kernel.git/commit
clk: npcm7xx: fix memory allocation
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Thu, 23 Aug 2018 23:06:54 +0000 (18:06 -0500)
committerStephen Boyd <sboyd@kernel.org>
Tue, 28 Aug 2018 22:12:59 +0000 (15:12 -0700)
commit3a2fa0194215b824786860889b7929a4ba2b7584
treebd9fc3f1b4ffae47e80d37dbf8f4c054850ceca0
parentf030a7bb7b1f7de16c1c716a587185e209e25800
clk: npcm7xx: fix memory allocation

One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
int stuff;
        void *entry[];
};

instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count,
GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

Notice that, currently, there is a bug during the allocation:

sizeof(npcm7xx_clk_data) should be sizeof(*npcm7xx_clk_data)

Fix this bug by using struct_size() in kzalloc()

This issue was detected with the help of Coccinelle.

Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Avi Fishman <avifishman70@gmail.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clk-npcm7xx.c