Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/appldata: use struct_size() helper

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

This code was detected with the help of Coccinelle and, audited and
fixed manually.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Message-Id: <20200617212930.GA11728@embeddedor>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>

authored by

Gustavo A. R. Silva and committed by
Heiko Carstens
28ccce5f 6ffb3f6b

+2 -4
+2 -4
arch/s390/appldata/appldata_os.c
··· 129 129 130 130 os_data->nr_cpus = j; 131 131 132 - new_size = sizeof(struct appldata_os_data) + 133 - (os_data->nr_cpus * sizeof(struct appldata_os_per_cpu)); 132 + new_size = struct_size(os_data, os_cpu, os_data->nr_cpus); 134 133 if (ops.size != new_size) { 135 134 if (ops.active) { 136 135 rc = appldata_diag(APPLDATA_RECORD_OS_ID, ··· 164 165 { 165 166 int rc, max_size; 166 167 167 - max_size = sizeof(struct appldata_os_data) + 168 - (num_possible_cpus() * sizeof(struct appldata_os_per_cpu)); 168 + max_size = struct_size(appldata_os_data, os_cpu, num_possible_cpus()); 169 169 if (max_size > APPLDATA_MAX_REC_SIZE) { 170 170 pr_err("Maximum OS record size %i exceeds the maximum " 171 171 "record size %i\n", max_size, APPLDATA_MAX_REC_SIZE);