From patchwork Thu Jun 6 14:46:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 13688615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96236C25B75 for ; Thu, 6 Jun 2024 14:47:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 284B66B00A0; Thu, 6 Jun 2024 10:47:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 234B76B00A1; Thu, 6 Jun 2024 10:47:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FC616B00A2; Thu, 6 Jun 2024 10:47:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E549F6B00A0 for ; Thu, 6 Jun 2024 10:47:21 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 99A211216D9 for ; Thu, 6 Jun 2024 14:47:21 +0000 (UTC) X-FDA: 82200741882.13.A64CC00 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by imf15.hostedemail.com (Postfix) with ESMTP id AEF7EA0024 for ; Thu, 6 Jun 2024 14:47:19 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=XYLv3rmY; spf=pass (imf15.hostedemail.com: domain of jean-philippe@linaro.org designates 209.85.128.45 as permitted sender) smtp.mailfrom=jean-philippe@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717685239; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=gAMNxXiwwiKZelOMcLP7GiR7QCh00iHenVieTh1hHYA=; b=LYhvI/PY0+yHgIvbjxua2MrWyxPFC+PbJqGWRc4uA357wXe+YSUgbD30r56DItokI0DliA N53lhxEoLYMrucKNiWha+eGaY6hmWXRxOKH3OCogNyvLfs6Gsn5vTgqr//ZxUDpxAlL8A5 +S891dssersy1MkGN25LLrl8Goj0s6w= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=XYLv3rmY; spf=pass (imf15.hostedemail.com: domain of jean-philippe@linaro.org designates 209.85.128.45 as permitted sender) smtp.mailfrom=jean-philippe@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717685239; a=rsa-sha256; cv=none; b=QS8bxIXraRObEF5jO53X3SaxochQQ2W92pi3J384JOreolExvGt1bQptC+vih7VNLGkgbK fmMRKaNeTJ4YgXUMNQYquHp9LKGYcQjTpBg7upoLAdJ1jdmD7U5zrVqdK6DxfCvPZ/McFE jCkY8twPxusLNGFkdpYNcTy+rVyyxYQ= Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4214fe0067fso11445815e9.1 for ; Thu, 06 Jun 2024 07:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717685238; x=1718290038; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gAMNxXiwwiKZelOMcLP7GiR7QCh00iHenVieTh1hHYA=; b=XYLv3rmY56NM0xhcPIazaSAL9xaEL+Y/c3+DKcnNtSJPPrDg2sHpTYMTU/4ne/mZBq bU5U/AAQC9tLvU5kY6d94lTrL/dtqI6ydqbypbo7YRWjAvbrZh1tpCjhjQEKAKV5fiPq 6oFc4wsEP175pPq8RCuXjEuAFVqXl/FoSFDSpXoNchXfJZ6x9rZ1LnZ5D90et9qNnMWb ampaCx9si50+i5g0AG+WZuosBGfqICN8D3gpqfyPobHFvtGR0cWStRSv1EfTlKol/3Ib eIe/HgBQFWZBIWI7pWd9LD3D5V+eEVf21ohpmWEQeIeBfeehnthtlve5cCCBrfu9Bwbn xicQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717685238; x=1718290038; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gAMNxXiwwiKZelOMcLP7GiR7QCh00iHenVieTh1hHYA=; b=AVA7IKs9B9UrPDnyfn0rqAPMDDceY+ni0ZapFiMqCZGEimOJGnhF23f8uqZcLp+vZT U5KejRqMXN6MqnaASNXV4n3DhzyzTXCxSs+8vN9hpI/JXlwqQw/02N1JWNLnB20XOqK2 7T61NvR84vuCo94pF8kFFZsFz6aJZnOxIggSyK7YaUXXiOVyDyHxZwtG0E9pTi4mU2cs JAGeA2r5jJ49jR3j1D5J7xz25sAY8zTz1l5xi3sYQh0hPkJwoqfXxo6xG7sEpcxLlgWp 40tObOY3pz7FtejIT00dqZwauoy/0NyJ+76MNuFdMdXmPImE/xYSMsJBW0c1U2aFt9hh 7PGw== X-Forwarded-Encrypted: i=1; AJvYcCUcAArPbDZOb4mE/qDnm51uDnmJa5IGnkcAVgdByviERmxCifPcChEGpqp9uTLK7fplmlSfEWyjZSLpOaNCsZz+Sms= X-Gm-Message-State: AOJu0Yz2623i/+UWSwRk3VkdQb3qaTZfzHTduKuwEp4qY+jsuhi1OvJG IqQB8+4g+w7zvncejs+F4/dqi4pYLuw6G0oGmTsBDKaefg98f7d1KgqM7TdBEo4= X-Google-Smtp-Source: AGHT+IGnRw7gclR2L13bttoMoqC/Ze9nXxsoh8QiaTGf4ppoKg3RVMfE+/mGMpwFjtl27lSycgHujw== X-Received: by 2002:a05:6000:1250:b0:35d:c98e:9823 with SMTP id ffacd0b85a97d-35e8ef9702dmr4218356f8f.62.1717685237987; Thu, 06 Jun 2024 07:47:17 -0700 (PDT) Received: from localhost.localdomain ([2.221.137.100]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35ef5d4729asm1746386f8f.25.2024.06.06.07.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 07:47:17 -0700 (PDT) From: Jean-Philippe Brucker To: thierry.reding@gmail.com, jonathanh@nvidia.com, kees@kernel.org, andy@kernel.org, akpm@linux-foundation.org Cc: linux-tegra@vger.kernel.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, Jean-Philippe Brucker Subject: [PATCH] mm/util: Swap kmemdup_array() arguments Date: Thu, 6 Jun 2024 15:46:09 +0100 Message-ID: <20240606144608.97817-2-jean-philippe@linaro.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: AEF7EA0024 X-Stat-Signature: kt665jcnt6368g6hdfa8mdzdksniy87p X-HE-Tag: 1717685239-342858 X-HE-Meta: U2FsdGVkX1+L+xopPjC+CuFA11FvgTUNQAQKrpagvMhUVMOpon4KG1cX18vzyh3rdEhawg14QBcgGbkJkmyX/XCjH2/I085dLwunYRZJ2dHkWqDUBy2fcffMO7IVmqmFv7IQDXf8vHMOOwLet3sedZNfmD6pQEmr/u/NAQlVGPhxl1iQC8uZf4Hi/W3ODCaXj3d77ZeXDG/CPm6wH59myn6FNo/WIYezX0FYpbZ2BojIWKBZzRtmxy+QVOgPMfgq5Y5CUqy04F7NUlj3KZYUBr7sUItGsIseIz5OvG2L/1rpe8/V17pTdCAvP0rMSsIGuKoHIUCGUzOwo7AHKEY9281mOhUs4JGvCgJ4yDG1R3l/fJiPn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fs6dzg4AESgYJx4baEkp79CEmGww3pVRY1nGvsNTdgrSlwwQPNKSQTucgh+Mb9rrXZuo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 7d78a7773355 ("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: 7d78a7773355 ("string: Add additional __realloc_size() annotations for "dup" helpers") Signed-off-by: Jean-Philippe Brucker Reviewed-by: Andy Shevchenko --- include/linux/string.h | 2 +- drivers/soc/tegra/fuse/fuse-tegra.c | 4 ++-- lib/fortify_kunit.c | 2 +- mm/util.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) base-commit: 2df0193e62cf887f373995fb8a91068562784adc diff --git a/include/linux/string.h b/include/linux/string.h index 60168aa2af075..9edace076ddbf 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -289,7 +289,7 @@ extern void *kmemdup_noprof(const void *src, size_t len, gfp_t gfp) __realloc_si extern void *kvmemdup(const void *src, size_t len, gfp_t gfp) __realloc_size(2); extern char *kmemdup_nul(const char *s, size_t len, gfp_t gfp); -extern void *kmemdup_array(const void *src, size_t element_size, size_t count, gfp_t gfp) +extern void *kmemdup_array(const void *src, size_t count, size_t element_size, gfp_t gfp) __realloc_size(2, 3); /* lib/argv_split.c */ diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c index b6bfd6729df39..d276672838465 100644 --- a/drivers/soc/tegra/fuse/fuse-tegra.c +++ b/drivers/soc/tegra/fuse/fuse-tegra.c @@ -127,8 +127,8 @@ static void tegra_fuse_print_sku_info(struct tegra_sku_info *tegra_sku_info) static int tegra_fuse_add_lookups(struct tegra_fuse *fuse) { - fuse->lookups = kmemdup_array(fuse->soc->lookups, sizeof(*fuse->lookups), - fuse->soc->num_lookups, GFP_KERNEL); + fuse->lookups = kmemdup_array(fuse->soc->lookups, fuse->soc->num_lookups, + sizeof(*fuse->lookups), GFP_KERNEL); if (!fuse->lookups) return -ENOMEM; diff --git a/lib/fortify_kunit.c b/lib/fortify_kunit.c index f9cc467334ce3..e17d520f532cf 100644 --- a/lib/fortify_kunit.c +++ b/lib/fortify_kunit.c @@ -374,7 +374,7 @@ static const char * const test_strs[] = { for (i = 0; i < ARRAY_SIZE(test_strs); i++) { \ len = strlen(test_strs[i]); \ KUNIT_EXPECT_EQ(test, __builtin_constant_p(len), 0); \ - checker(len, kmemdup_array(test_strs[i], len, 1, gfp), \ + checker(len, kmemdup_array(test_strs[i], 1, len, gfp), \ kfree(p)); \ checker(len, kmemdup(test_strs[i], len, gfp), \ kfree(p)); \ diff --git a/mm/util.c b/mm/util.c index c9e519e6811f5..6682097372efc 100644 --- a/mm/util.c +++ b/mm/util.c @@ -139,14 +139,14 @@ EXPORT_SYMBOL(kmemdup_noprof); * kmemdup_array - duplicate a given array. * * @src: array to duplicate. - * @element_size: size of each element of array. * @count: number of elements to duplicate from array. + * @element_size: size of each element of array. * @gfp: GFP mask to use. * * Return: duplicated array of @src or %NULL in case of error, * result is physically contiguous. Use kfree() to free. */ -void *kmemdup_array(const void *src, size_t element_size, size_t count, gfp_t gfp) +void *kmemdup_array(const void *src, size_t count, size_t element_size, gfp_t gfp) { return kmemdup(src, size_mul(element_size, count), gfp); }