From nobody Sun Jun 14 06:07:10 2026 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD90F36A022 for ; Sat, 2 May 2026 14:44:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.161 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777733061; cv=none; b=Cxq8xKmIWr/hChO1266jPIU15Dz/SBoKCMrhwSo2iMnyLnzKvdkw6yAUtz2zQ5MRC4T7Q6vY8BdKbfCc78KtK+SIols09QHuPtsZOr01bWHrXrVvfSFQ/uy0I3fDfGvU6/lLSrh59yUHfVHBnzcDzXi6h5eEIVsOPL5omrwvjTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777733061; c=relaxed/simple; bh=JFGA6MRz5daPWpVbFxOIvDg6z3MqTc6f22tvDh0qAyg=; h=Message-ID:Subject:From:To:Cc:Date:Content-Type:MIME-Version; b=mMSHIca1/+OtPBrst1rUDShCFyhzbbYX3YkbDnaq7ES9djZZDnXqTkW+SZfEJUam+UcUeZKH50afTiVwP2PgMzSsawoWjiHcBoMhXHXocVfY0g0TKok02vqSGGfc2IYjmYQ281ffgrjAbpMs0jjHk7Dd3BFhmgOmZm2N9FStG3k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b=UprxRT9x; arc=none smtp.client-ip=80.241.56.161 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mailbox.org header.i=@mailbox.org header.b="UprxRT9x" Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4g79f12r8xz9t6D; Sat, 2 May 2026 16:44:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1777733049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=avnltl9Sd5jWmGtaMIbIoQf8jH28Xkaq2oY2G2/1+Xg=; b=UprxRT9xBpFv1vd4EGZ9VlRkE0dTJGdPbLmdm1mrFasM9lHXl2ag5c4Z+7vw9QJ5socoWC 7VOZNIY6xpaEWK9UPI6Vrv8lTRaMwr8WROkCEhlnJWg75EWWA3+uxOO5uPufD0LVG4DaIC fjFzD+oGIQf+4+1OcWY+IDstn8ZNZsD7rpLv6BDFEBMiYccANhy1BjlsufJjex4lfOOZ2q 0sBe4+orftj0S6uidl4YOEmM/yftAHp7gs8U7/UWtntEBLUZ4iY5cqAsAKxD9UtmaYXxXc gPl6zeVaIzI4lozESufaXdnfHoq+315gOBIgt8vGTX7Oym6RpopeqVu2T9Wffw== Message-ID: Subject: [RFC] scripts: checkpatch.pl: type aware alloc: add suggestions to script output From: Manuel Ebner To: Andy Whitcroft , Joe Perches , open list , Kees Cook Cc: Dwaipayan Ray , Lukas Bulwahn Date: Sat, 02 May 2026 16:43:42 +0200 Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MBO-RS-META: 3f961aunm85npuptphxbj3ox4dsg1scz X-MBO-RS-ID: bf61c62da4c8f42d076 Content-Type: text/plain; charset="utf-8" hello, i think i'm far from a patch here, maybe i'll get there. my change messes up $herectx, but i don't know why. @ Kees Cook after comparing the functions of you patch (2932ba8d9c99) with the functions in deprecated.rst i found the issue. there's a missing ')' on line 391. I'll fix this in my patchseries "[PATCH v5 3/3] Documentation: deprecated.rst: kmalloc-family: mark argument as optional" Just to make sure. I'll look for following vars with Regex: ptr, *prt, gfp, count and flex_member ptr =3D kmalloc(sizeof(*ptr), gfp); =C2=A0-> ptr =3D kmalloc_obj(*ptr [, gfp] ); ptr =3D kzalloc(sizeof(*ptr), gfp); =C2=A0-> ptr =3D kzalloc_obj(*ptr [, gfp] ); ptr =3D kmalloc_array(count, sizeof(*ptr), gfp); =C2=A0-> ptr =3D kmalloc_objs(*ptr, count [, gfp] ); ptr =3D kcalloc(count, sizeof(*ptr), gfp); =C2=A0-> ptr =3D kzalloc_objs(*ptr, count [, gfp] ); keywords are: *alloc_obj(s) __auto_type, struct, kmalloc_flex. thoose will be as is in the suggestion ptr =3D kmalloc(struct_size(ptr, flex_member, count), gfp); =C2=A0-> ptr =3D kmalloc_flex(*ptr, flex_member, count [, gfp] ); ptr =3D kmalloc(sizeof(struct foo), gfp); =C2=A0-> __auto_type ptr =3D kmalloc_obj(struct foo [, gfp] ); Thanks Manuel changelog: --------- [PATCH] scripts: checkpatch.pl: type aware alloc: add suggestions to script output goal is to lower the hurdle of implementing type aware alloc by suggesting the required function. old output: WARNING: Prefer kzalloc_obj over kzalloc with sizeof #42: FILE: deprecated.c:42: + ptr =3D kzalloc(sizeof(*ptr), gfp); new output: WARNING: Prefer kmalloc_obj over kmalloc with sizeof #42: FILE: deprecated.c:42: + ptr =3D kzalloc(sizeof(*ptr), gfp); Suggestion + ptr =3D kmalloc_obj(*ptr, gfp); --- =C2=A0scripts/checkpatch.pl | 5 +++-- =C2=A01 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0492d6afc9a1..b8e5fbf2c19a 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7300,10 +7300,11 @@ sub process { =C2=A0# check for (kv|k)[mz]alloc that could be kmalloc_obj/kvmalloc_obj/kzalloc_obj/kvzalloc_obj =C2=A0 if ($perl_version_ok && =C2=A0 =C2=A0=C2=A0=C2=A0 defined $stat && - =C2=A0=C2=A0=C2=A0 $stat =3D~ /^\+\s*($Lval)\s*\=3D\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*= ($FuncArg)\s*,/) { + =C2=A0=C2=A0=C2=A0 $stat =3D~ /(\+?[ \t]*)(\w*)\s=3D\s((?:kv|k)[mz]alloc)\((sizeof\()?\*(\w*)\),\s*(\w*)\);/) { =C2=A0 my $oldfunc =3D $3; =C2=A0 my $a1 =3D $4; =C2=A0 my $newfunc =3D "kmalloc_obj"; + my $suggestfunc =3D "Suggestion -> $1$2 =3D $3\_obj(\*$5, $6\);"; =C2=A0 $newfunc =3D "kvmalloc_obj" if ($oldfunc eq "kvmalloc"); =C2=A0 $newfunc =3D "kvzalloc_obj" if ($oldfunc eq "kvzalloc"); =C2=A0 $newfunc =3D "kzalloc_obj" if ($oldfunc eq "kzalloc"); @@ -7313,7 +7314,7 @@ sub process { =C2=A0 my $herectx =3D get_stat_here($linenr, $cnt, $here); =C2=A0 =C2=A0 if (WARN("ALLOC_WITH_SIZEOF", - "Prefer $newfunc over $oldfunc with sizeof\n" . $herectx) && + "Prefer $newfunc over $oldfunc with sizeof\n" . $suggestfunc . "\n") && =C2=A0 =C2=A0=C2=A0=C2=A0 $cnt =3D=3D 1 && =C2=A0 =C2=A0=C2=A0=C2=A0 $fix) { =C2=A0 $fixed[$fixlinenr] =3D~ s/\b($Lval)\s*\=3D\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($F= uncArg)\s*,/$1 =3D $newfunc($a1,/;