Revision 0e71666b8b9e21e4cb5d805219eb5ed7c5617ca3 authored by Gustavo A. R. Silva on 12 July 2019, 03:52:58 UTC, committed by Linus Torvalds on 12 July 2019, 18:05:41 UTC
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 dlm_migratable_lockres { ... struct dlm_migratable_lock ml[0]; // 16 bytes each, begins at byte 112 }; Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. So, replace the following form: sizeof(struct dlm_migratable_lockres) + (mres->num_locks * sizeof(struct dlm_migratable_lock)) with: struct_size(mres, ml, mres->num_locks) Notice that, in this case, variable sz is not necessary, hence it is removed. This code was detected with the help of Coccinelle. Link: http://lkml.kernel.org/r/20190605204926.GA24467@embeddedor Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e926d8a
File | Mode | Size |
---|---|---|
Makefile | -rw-r--r-- | 361 bytes |
compat.c | -rw-r--r-- | 2.2 KB |
ipc_sysctl.c | -rw-r--r-- | 6.1 KB |
mq_sysctl.c | -rw-r--r-- | 2.7 KB |
mqueue.c | -rw-r--r-- | 40.3 KB |
msg.c | -rw-r--r-- | 30.5 KB |
msgutil.c | -rw-r--r-- | 3.6 KB |
namespace.c | -rw-r--r-- | 4.6 KB |
sem.c | -rw-r--r-- | 62.1 KB |
shm.c | -rw-r--r-- | 43.0 KB |
syscall.c | -rw-r--r-- | 5.1 KB |
util.c | -rw-r--r-- | 22.8 KB |
util.h | -rw-r--r-- | 9.7 KB |
Computing file changes ...