On Wed, Dec 18, 2013 at 09:17:48AM +0100, Marin Ramesa wrote: > Don't initialize to zero, rather move the initialization of size before > the break statement. Break on the first iteration should never happen, so the > position of initialization doesn't matter. > > * ipc/mach_debug.c (host_ipc_hash_info) (size): Don't initialize to zero. > (host_ipc_hash_info) (size): Move initialization before the break statement. > > --- > ipc/mach_debug.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/ipc/mach_debug.c b/ipc/mach_debug.c > index dd9057a..d7c454b 100644 > --- a/ipc/mach_debug.c > +++ b/ipc/mach_debug.c > @@ -112,7 +112,7 @@ host_ipc_hash_info( > mach_msg_type_number_t *countp) > { > vm_offset_t addr; > - vm_size_t size = 0; /* Suppress gcc warning */ > + vm_size_t size; > hash_info_bucket_t *info; > unsigned int potential, actual; > kern_return_t kr; > @@ -127,6 +127,9 @@ host_ipc_hash_info( > > for (;;) { > actual = ipc_hash_info(info, potential); > + > + size = round_page(actual * sizeof *info); > + > if (actual <= potential) > break; > > @@ -135,7 +138,6 @@ host_ipc_hash_info( > if (info != *infop) > kmem_free(ipc_kernel_map, addr, size);
See that kmem_free() right here, it uses the size computed during the previous iteration. It works as it is because ipc_hash_info returns ipc_hash_global_size, a value that doesn't change after initialization. But it will break if the hash table is made resizable. > - size = round_page(actual * sizeof *info); > kr = kmem_alloc_pageable(ipc_kernel_map, &addr, size); > if (kr != KERN_SUCCESS) > return KERN_RESOURCE_SHORTAGE; -- Richard Braun