From patchwork Tue Sep 12 17:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 138491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp752686vqx; Tue, 12 Sep 2023 17:00:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfF+QHez14f65M29exXtsO3D5O3xVnzobJWX28WhloyM8ezppE/wJM8+G/fQ5l1x3I9mcQ X-Received: by 2002:a17:902:9a0a:b0:1c3:8539:c358 with SMTP id v10-20020a1709029a0a00b001c38539c358mr1129718plp.35.1694563203098; Tue, 12 Sep 2023 17:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694563203; cv=none; d=google.com; s=arc-20160816; b=VKTSR/NlUMGTfY8yGcy1WeS2232612Sq0Udvn8j4HJfOzjSBWop/9utV10lAGKgO/t 8WkFE8ICTLDWP6oqaWNXVYUDOC3pWeL2xFu/6nsdEwdUHYa4TMR89NC2tv7XeZe2um/O NwY9BD+BrMrg4WMhAYCoaAR0ZWsRFaGxHi1mZ724pZOGl8I71KlrVKfLq7gMnoL5KBz0 efVO+7kcw194Xd+34vd5Nrzs4EbToI2FOTg5etkmj9I/tLU6omIt9wwvq1zqFrZ+cp4I gY410prmyf6shBJQJ1837lJTG8RJ5A2mSZlsat9SFHwFKFQTJfF2gGZH02HrL7b7N0PE IS7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=EbbdWy+JjhB0uS97Z/HvaXFL63Pr8rWd/axhAIfHcjM=; fh=YsWw00Jlfa55bKJrmUXcyDdrFa+jsHw4t798gLJ5P3Y=; b=gs183wRxg/eRkUaCsAcbQQT6kcUS6dWsJ2DW6mvEJq8mLZ3C9imIIdTYgxa1HkNEO/ ktSyeGaG00HxHR3c0Gf00HckTHl/jTNvPBx8PtMfivSa10jBUXxloa9i0WyX7xJWw4CG +Dwnu+/bPooQ1PTfqC1MchghnBfwNcfa47uVzvdXH3ZM+/XO7b6sw1DreWQYUfenEpC8 zWicVmMdAYnjyxHvpNooTv22kxA2XfGxaQXpjB+26reGb3psZUk06mnoLSd+qf4X6lI4 XyJF3jYkE8p3an6SqHpcZoBgYGmLqb2Ywp6orqfJyfGSS3l8BWNdqS0Xkc7VR+LC6Nx6 mzJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mhyHO6vY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id q6-20020a17090311c600b001c3b806219bsi4424654plh.143.2023.09.12.16.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 17:00:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mhyHO6vY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 709B284AF1E8; Tue, 12 Sep 2023 10:04:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235629AbjILREJ (ORCPT + 37 others); Tue, 12 Sep 2023 13:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234031AbjILREI (ORCPT ); Tue, 12 Sep 2023 13:04:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84060110; Tue, 12 Sep 2023 10:04:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72235C433C7; Tue, 12 Sep 2023 17:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694538244; bh=TlF+LlVr0+p7G1whWSyXl90KqhYFGDWhgyj2gIcU/UA=; h=Date:From:To:Cc:Subject:From; b=mhyHO6vYRr7rhv+o8basUZBhSTzBB4vdH6hmy+KBgxrmwlYgAjUCSw35UYWqItxqp 6SlXtJLx0HLyia+1rx/xqSRi8StgbgCULhVSCctmqlPsgho4RWgFJLr9bmDgEd2jwi aZn7VbUvKMA6FuO8/8Tpg2xWOT6wSlvFoq1CR2kPROwfzZJ1mtqVoMxlYUPJXrWC8M f6+ThE0PycZMlMFCxqRBspH1cyR4CGAmzfEJPQlH9Fr+DEReN4rIf7Q/XVPImt3QdC me4bRCbcwp3g3/R/99U2OK7Srf/f1+hhSMTJZBo3RsyVNJcm4/G2gmLia5eMXx6bdt +a/1AVA+kiCBQ== Date: Tue, 12 Sep 2023 11:04:59 -0600 From: "Gustavo A. R. Silva" To: Andy Whitcroft , Joe Perches , Dwaipayan Ray , Lukas Bulwahn Cc: linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] checkpatch: add a couple new alloc functions to alloc with multiplies check Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 10:04:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776855608202674626 X-GMAIL-MSGID: 1776878305495852679 vmalloc() and vzalloc() functions have now 2-factor multiplication argument forms vmalloc_array() and vcalloc(), correspondingly. Add alloc-with-multiplies checks for these new functions. Link: https://github.com/KSPP/linux/issues/342 Signed-off-by: Gustavo A. R. Silva --- scripts/checkpatch.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 7d16f863edf1..45265d0eee1b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7207,17 +7207,19 @@ sub process { "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); } -# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc +# check for (kv|k|v)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/vmalloc_array/kvcalloc/kcalloc/vcalloc if ($perl_version_ok && defined $stat && - $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { + $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,?/) { my $oldfunc = $3; my $a1 = $4; my $a2 = $10; my $newfunc = "kmalloc_array"; $newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc"); + $newfunc = "vmalloc_array" if ($oldfunc eq "vmalloc"); $newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc"); $newfunc = "kcalloc" if ($oldfunc eq "kzalloc"); + $newfunc = "vcalloc" if ($oldfunc eq "vzalloc"); my $r1 = $a1; my $r2 = $a2; if ($a1 =~ /^sizeof\s*\S/) { @@ -7233,7 +7235,7 @@ sub process { "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) && $cnt == 1 && $fix) { - $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e; + $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e; } } }