Skip to content

Commit 0ee1472

Browse files
jpbruckerkees
authored andcommitted
mm/util: Swap kmemdup_array() arguments
GCC 14.1 complains about the argument usage of kmemdup_array(): drivers/soc/tegra/fuse/fuse-tegra.c:130:65: error: 'kmemdup_array' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args] 130 | fuse->lookups = kmemdup_array(fuse->soc->lookups, sizeof(*fuse->lookups), | ^ drivers/soc/tegra/fuse/fuse-tegra.c:130:65: note: earlier argument should specify number of elements, later size of each element The annotation introduced by commit 7d78a77 ("string: Add additional __realloc_size() annotations for "dup" helpers") lets the compiler think that kmemdup_array() follows the same format as calloc(), with the number of elements preceding the size of one element. So we could simply swap the arguments to __realloc_size() to get rid of that warning, but it seems cleaner to instead have kmemdup_array() follow the same format as krealloc_array(), memdup_array_user(), calloc() etc. Fixes: 7d78a77 ("string: Add additional __realloc_size() annotations for "dup" helpers") Signed-off-by: Jean-Philippe Brucker <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent c3f38fa commit 0ee1472

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

drivers/soc/tegra/fuse/fuse-tegra.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ static void tegra_fuse_print_sku_info(struct tegra_sku_info *tegra_sku_info)
127127

128128
static int tegra_fuse_add_lookups(struct tegra_fuse *fuse)
129129
{
130-
fuse->lookups = kmemdup_array(fuse->soc->lookups, sizeof(*fuse->lookups),
131-
fuse->soc->num_lookups, GFP_KERNEL);
130+
fuse->lookups = kmemdup_array(fuse->soc->lookups, fuse->soc->num_lookups,
131+
sizeof(*fuse->lookups), GFP_KERNEL);
132132
if (!fuse->lookups)
133133
return -ENOMEM;
134134

include/linux/string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ extern void *kmemdup_noprof(const void *src, size_t len, gfp_t gfp) __realloc_si
289289

290290
extern void *kvmemdup(const void *src, size_t len, gfp_t gfp) __realloc_size(2);
291291
extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp);
292-
extern void *kmemdup_array(const void *src, size_t element_size, size_t count, gfp_t gfp)
292+
extern void *kmemdup_array(const void *src, size_t count, size_t element_size, gfp_t gfp)
293293
__realloc_size(2, 3);
294294

295295
/* lib/argv_split.c */

lib/fortify_kunit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static const char * const test_strs[] = {
374374
for (i = 0; i < ARRAY_SIZE(test_strs); i++) { \
375375
len = strlen(test_strs[i]); \
376376
KUNIT_EXPECT_EQ(test, __builtin_constant_p(len), 0); \
377-
checker(len, kmemdup_array(test_strs[i], len, 1, gfp), \
377+
checker(len, kmemdup_array(test_strs[i], 1, len, gfp), \
378378
kfree(p)); \
379379
checker(len, kmemdup(test_strs[i], len, gfp), \
380380
kfree(p)); \

mm/util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ EXPORT_SYMBOL(kmemdup_noprof);
139139
* kmemdup_array - duplicate a given array.
140140
*
141141
* @src: array to duplicate.
142-
* @element_size: size of each element of array.
143142
* @count: number of elements to duplicate from array.
143+
* @element_size: size of each element of array.
144144
* @gfp: GFP mask to use.
145145
*
146146
* Return: duplicated array of @src or %NULL in case of error,
147147
* result is physically contiguous. Use kfree() to free.
148148
*/
149-
void *kmemdup_array(const void *src, size_t element_size, size_t count, gfp_t gfp)
149+
void *kmemdup_array(const void *src, size_t count, size_t element_size, gfp_t gfp)
150150
{
151151
return kmemdup(src, size_mul(element_size, count), gfp);
152152
}

0 commit comments

Comments
 (0)