mirror of
https://git.proxmox.com/git/mirror_ubuntu-kernels.git
synced 2026-01-03 18:48:45 +00:00
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;
struct boo entry[];
};
size = sizeof(struct foo) + count * sizeof(struct boo);
instance = devm_kzalloc(dev, size, GFP_KERNEL);
Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper.
instance = devm_kzalloc(dev, struct_size(instance, entry, count), GFP_KERNEL);
This code was detected with the help of Coccinelle.
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190410170914.GA16161@embeddedor
|
||
|---|---|---|
| .. | ||
| affinity.c | ||
| autoprobe.c | ||
| chip.c | ||
| cpuhotplug.c | ||
| debug.h | ||
| debugfs.c | ||
| devres.c | ||
| dummychip.c | ||
| generic-chip.c | ||
| handle.c | ||
| internals.h | ||
| ipi.c | ||
| irq_sim.c | ||
| irqdesc.c | ||
| irqdomain.c | ||
| Kconfig | ||
| Makefile | ||
| manage.c | ||
| matrix.c | ||
| migration.c | ||
| msi.c | ||
| pm.c | ||
| proc.c | ||
| resend.c | ||
| settings.h | ||
| spurious.c | ||
| timings.c | ||