Skip to content

Commit 3b201c9

Browse files
dmantipovbroonie
authored andcommitted
regmap: fix kcalloc() arguments order
When compiling with gcc version 14.0.0 20231220 (experimental) and W=1, I've noticed a bunch of four similar warnings like: drivers/base/regmap/regmap-ram.c: In function '__regmap_init_ram': drivers/base/regmap/regmap-ram.c:68:37: warning: 'kcalloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Wcalloc-transposed-args] 68 | data->read = kcalloc(sizeof(bool), config->max_register + 1, | ^~~~ Since 'n' and 'size' arguments of 'kcalloc()' are multiplied to calculate the final size, their actual order doesn't affect the result and so this is not a bug. But it's still worth to fix it. Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Link: https://msgid.link/r/20231220175829.533700-1-dmantipov@yandex.ru Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1957b92 commit 3b201c9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/base/regmap/regmap-ram.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ struct regmap *__regmap_init_ram(const struct regmap_config *config,
6565
return ERR_PTR(-EINVAL);
6666
}
6767

68-
data->read = kcalloc(sizeof(bool), config->max_register + 1,
68+
data->read = kcalloc(config->max_register + 1, sizeof(bool),
6969
GFP_KERNEL);
7070
if (!data->read)
7171
return ERR_PTR(-ENOMEM);
7272

73-
data->written = kcalloc(sizeof(bool), config->max_register + 1,
73+
data->written = kcalloc(config->max_register + 1, sizeof(bool),
7474
GFP_KERNEL);
7575
if (!data->written)
7676
return ERR_PTR(-ENOMEM);

drivers/base/regmap/regmap-raw-ram.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ struct regmap *__regmap_init_raw_ram(const struct regmap_config *config,
122122
return ERR_PTR(-EINVAL);
123123
}
124124

125-
data->read = kcalloc(sizeof(bool), config->max_register + 1,
125+
data->read = kcalloc(config->max_register + 1, sizeof(bool),
126126
GFP_KERNEL);
127127
if (!data->read)
128128
return ERR_PTR(-ENOMEM);
129129

130-
data->written = kcalloc(sizeof(bool), config->max_register + 1,
130+
data->written = kcalloc(config->max_register + 1, sizeof(bool),
131131
GFP_KERNEL);
132132
if (!data->written)
133133
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)