Skip to content

Commit

Permalink
s390/appldata: use struct_size() helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Gustavo A. R. Silva authored and Heiko Carstens committed Jun 29, 2020
1 parent 6ffb3f6 commit 28ccce5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions arch/s390/appldata/appldata_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ static void appldata_get_os_data(void *data)

os_data->nr_cpus = j;

new_size = sizeof(struct appldata_os_data) +
(os_data->nr_cpus * sizeof(struct appldata_os_per_cpu));
new_size = struct_size(os_data, os_cpu, os_data->nr_cpus);
if (ops.size != new_size) {
if (ops.active) {
rc = appldata_diag(APPLDATA_RECORD_OS_ID,
Expand Down Expand Up @@ -165,8 +164,7 @@ static int __init appldata_os_init(void)
{
int rc, max_size;

max_size = sizeof(struct appldata_os_data) +
(num_possible_cpus() * sizeof(struct appldata_os_per_cpu));
max_size = struct_size(appldata_os_data, os_cpu, num_possible_cpus());
if (max_size > APPLDATA_MAX_REC_SIZE) {
pr_err("Maximum OS record size %i exceeds the maximum "
"record size %i\n", max_size, APPLDATA_MAX_REC_SIZE);
Expand Down

0 comments on commit 28ccce5

Please sign in to comment.