Re: [PATCH] Fix order_base_2(0)

From: David Howells
Date: Wed Dec 14 2011 - 19:33:55 EST


Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> Does anybody actually *want* order_base_2(0)?

There aren't actually that many users:

| arch/mips/include/asm/mach-powertv/ioremap.h:#define _IOR_OFFSET_WIDTH(n) (1 << order_base_2(n))

Doesn't look like it should ever be 0. In fact, this looks like a case for
using roundup_pow_of_two() directly.

| arch/powerpc/platforms/pseries/iommu.c: len = order_base_2(max_addr);

Not sure. Doesn't look likely, but can memory_hotplug_max() be 0 if hotplug
is not supported?

| arch/x86/kvm/x86.c: return hash_32(gfn & 0xffffffff, order_base_2(ASYNC_PF_PER_VCPU));

Constant 64. Can't be 0.

| fs/ext4/indirect.c: blk_bits = order_base_2(lblock);

lblock *could* perhaps be 0. Being negative is checked for, but not for it
being 0.

| fs/ext4/mballoc.c: int blocksize_bits = order_base_2(size);
| fs/jbd2/journal.c: int i = order_base_2(size) - 10;

Can't be 0.

| fs/jbd2/journal.c: int i = order_base_2(size) - 10;

Hmmm... Can jbd2_alloc() be given a 0 size? (Or jbd2_free() for that matter)

| mm/percpu-km.c: pages = alloc_pages(GFP_KERNEL, order_base_2(nr_pages));
| mm/percpu-km.c: __free_pages(chunk->data, order_base_2(nr_pages));

Can pcpu_group_sizes[0] be less than PAGE_SIZE?

I can't tell from a cursory inspection of pcpu_setup_first_chunk().

In fact, pcpu_create_chunk() could do order_base_2() then subtract PAGE_SHIFT
rather than shifting and then taking the log.

David
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/