Re: [PATCH v2] x86: UV uv_tlb.c cleanup

From: Ingo Molnar
Date: Fri May 20 2011 - 09:19:42 EST



Ok, the whole file looks a lot better now. A few small details:

* Cliff Wickman <cpw@xxxxxxx> wrote:

> + vp = kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
> + uvhub_descs = (struct uvhub_desc *)vp;
> + memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
> + uvhub_mask = kzalloc((nuvhubs+7)/8, GFP_KERNEL);
> +
> + if (get_cpu_topology(base_part_pnode, uvhub_descs, uvhub_mask)) {
> + kfree(uvhub_descs);
> + kfree(uvhub_mask);
> + return 1;
> + }
> + if (summarize_uvhub_sockets(nuvhubs, uvhub_descs, uvhub_mask)) {
> + kfree(uvhub_descs);
> + kfree(uvhub_mask);
> + return 1;
> + }
> +
> kfree(uvhub_descs);
> kfree(uvhub_mask);
> + init_per_cpu_tunables();
> return 0;

Look how the teardown of uvhub_descs and uvhub_mask is repeated 3 times (!).

What we do in the kernel instead are:

if (func())
goto fail;

if (func2())
goto fail;

ret = 0;
out:
kfree(ptr1);
kfree(ptr2);

return ret;

fail:
ret = 1;
goto out;
}

this makes it more obvious and more readable.

Thanks,

Ingo
--
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/