]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
memblock: add assertion for zero allocation alignment
authorVineet Gupta <Vineet.Gupta1@synopsys.com>
Wed, 20 Mar 2013 04:07:08 +0000 (15:07 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 21 Mar 2013 05:28:25 +0000 (16:28 +1100)
commit560beac808b45dd83a91e3a0dd2c62c34c510bb3
treec539304b7162924cc41925869fe5ad3cde61f0e1
parentcc3481a95ccec5592978897ee141b295052649e2
memblock: add assertion for zero allocation alignment

This came to light when calling memblock allocator from arc port (for
copying flattended DT).  If a "0" alignment is passed, the allocator
round_up() call incorrectly rounds up the size to 0.

round_up(num, alignto) => ((num - 1) | (alignto -1)) + 1

While the obvious allocation failure causes kernel to panic, it is better
to warn the caller to fix the code.

Tejun suggested that instead of BUG_ON(!align) - which might be
ineffective due to pending console init and such, it is better to WARN_ON,
and continue the boot with a reasonable default align.

Caller passing @size need not be handled similarly as the subsequent
panic will indicate that anyhow.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memblock.c