From nobody Thu Apr 9 09:22:15 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EAD2C433FE for ; Fri, 4 Nov 2022 07:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbiKDHIo (ORCPT ); Fri, 4 Nov 2022 03:08:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229532AbiKDHIl (ORCPT ); Fri, 4 Nov 2022 03:08:41 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29943275EA for ; Fri, 4 Nov 2022 00:08:40 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N3Wpk5JCJzpWBv; Fri, 4 Nov 2022 15:05:02 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 4 Nov 2022 15:08:37 +0800 From: Liao Chang To: , , , CC: , , , Subject: [PATCH -next v2] checkpatch: Add check for array allocator family argument order Date: Fri, 4 Nov 2022 15:05:23 +0800 Message-ID: <20221104070523.60296-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These array allocator family are sometimes misused with the first and second arguments switchted. Same issue with calloc, kvcalloc, kvmalloc_array etc. Bleat if sizeof is the first argument. Link: https://lore.kernel.org/lkml/5374345c-7973-6a3c-d559-73bf4ac15079@red= hat.com/ Signed-off-by: Liao Chang Acked-by: Joe Perches Acked-by: Lukas Bulwahn --- v2: 1. Acked-by Joe Perches. 2. Use lore links in Link tag. --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 1e5e66ae5a52..a9a9dc277cff 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7128,7 +7128,7 @@ sub process { } =20 # check for alloc argument mismatch - if ($line =3D~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/= ) { + if ($line =3D~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))= \s*\(\s*sizeof\b/) { WARN("ALLOC_ARRAY_ARGS", "$1 uses number as first arg, sizeof is generally wrong\n" . $here= curr); } --=20 2.17.1