From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A0659337BB3 for ; Mon, 23 Feb 2026 17:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771868888; cv=none; b=h2EOwkTnFXiSCOA/dJ6PnE44itOlj0eatQx4nDklIbo77KFr0fYm8rIpCSr62q4wKh9zMCxsHbotg5V12und3bewhW6E+URiHrvGAcV6m4XfYFbQGp73fq68MnZPzf9Rjs8wcqsdK6TRk5cnEIxCDJbgLnKe4ooOb0/c5KGUnBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771868888; c=relaxed/simple; bh=yUaE5zI5O84yhqEQLnUoq6Jjsx/np6/JhfDyOiFTKQo=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=d4x5jasKFGgGvhvVJCBawuBRBPv5xcCuP4Tbw7STRL0+5rp/+Hl1YLqg1WFMhwyLs3fxYI4hH+5RM0p+38hPNTDoRFojMC2sm934JDCQj5b4dpkbJ0S9jHfOeTPwfbmLJ1IroxTaYun1X3rJYHMZzSVn6zC2xntRyGic/rGHuq4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jB9zvnF4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jB9zvnF4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71E0BC116C6; Mon, 23 Feb 2026 17:48:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771868888; bh=yUaE5zI5O84yhqEQLnUoq6Jjsx/np6/JhfDyOiFTKQo=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=jB9zvnF4rSLVt8V4ygQYJ2aOzEvAdRaeZrsl8QF98b9eOVVgSKyTr2rcq4IDbl4Ef e1rgmsinS60aHNDtZs2hVU7pBZr54gqnGMAncr869W0PZY2G2/NyhH1RUOazVy7OCB Uj/z9MhoFIj3sgaUVHkeKrUuIvPkd0FMlgewCD7jkngLzNXZgHOXs3Hr/owrH4i8qR JrHmsWVLSTPf2PObBYJ3KLBWI9K3XVxr9ixbRW2aIAqTz1RFtoYKUsc95Jw1oUGzj1 2s83CocNq34Bgvf7fXGMt1spv+resNTxS1ujiH9v81i5cj6uQ5BYITuYrDrEfglt0M C62buyXYrlb2w== Date: Mon, 23 Feb 2026 09:48:03 -0800 From: Kees Cook To: Guenter Roeck CC: linux-kernel@vger.kernel.org, Nathan Chancellor Subject: =?US-ASCII?Q?Re=3A_=5BPATCH=5D_treewide=3A_Replace_kmalloc?= =?US-ASCII?Q?_with_kmalloc=5Fobj_for_non-scalar_types?= User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <8DBEF986-6446-4EF8-9570-C898BD301B1E@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On February 23, 2026 8:05:10 AM PST, Guenter Roeck = wrote: >On Fri, Feb 20, 2026 at 11:49:23PM -0800, Kees Cook wrote: >> This is the result of running the Coccinelle script from >> scripts/coccinelle/api/kmalloc_objs=2Ecocci=2E The script is designed t= o >> avoid scalar types (which need careful case-by-case checking), and >> instead replace kmalloc-family calls that allocate struct or union >> object instances: >>=20 >> Single allocations: kmalloc(sizeof(TYPE), =2E=2E=2E) >> are replaced with: kmalloc_obj(TYPE, =2E=2E=2E) >>=20 >> Array allocations: kmalloc_array(COUNT, sizeof(TYPE), =2E=2E=2E) >> are replaced with: kmalloc_objs(TYPE, COUNT, =2E=2E=2E) >>=20 >> Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), =2E=2E=2E= ) >> are replaced with: kmalloc_flex(*PTR, FAM, COUNT, =2E=2E=2E) >>=20 >> (where TYPE may also be *VAR) >>=20 >> The resulting allocations no longer return "void *", instead returning >> "TYPE *"=2E >>=20 >> Signed-off-by: Kees Cook >> --- >> diff --git a/arch/um/drivers/ubd_kern=2Ec b/arch/um/drivers/ubd_kern=2E= c >> index 37455e74d314=2E=2E42f392e6add3 100644 >> --- a/arch/um/drivers/ubd_kern=2Ec >> +++ b/arch/um/drivers/ubd_kern=2Ec >> @@ -1069,20 +1069,16 @@ static int __init ubd_init(void) >> if (register_blkdev(UBD_MAJOR, "ubd")) >> return -1; >> =20 >> - irq_req_buffer =3D kmalloc_array(UBD_REQ_BUFFER_SIZE, >> - sizeof(struct io_thread_req *), >> - GFP_KERNEL >> - ); >> + irq_req_buffer =3D kmalloc_objs(struct io_thread_req *, >> + UBD_REQ_BUFFER_SIZE, GFP_KERNEL); >> irq_remainder =3D 0; >> =20 >> if (irq_req_buffer =3D=3D NULL) { >> printk(KERN_ERR "Failed to initialize ubd buffering\n"); >> return -ENOMEM; >> } >> - io_req_buffer =3D kmalloc_array(UBD_REQ_BUFFER_SIZE, >> - sizeof(struct io_thread_req *), >> - GFP_KERNEL >> - ); >> + io_req_buffer =3D kmalloc_objs(struct io_thread_req *, >> + UBD_REQ_BUFFER_SIZE, GFP_KERNEL); > >Building um:defconfig =2E=2E=2E failed >-------------- >Error log: >arch/um/drivers/ubd_kern=2Ec: In function 'ubd_init': >arch/um/drivers/ubd_kern=2Ec:1072:24: error: assignment to 'struct io_thr= ead_req * (*)[]' from incompatible pointer type 'struct io_thread_req **' [= -Wincompatible-pointer-types] > 1072 | irq_req_buffer =3D kmalloc_objs(struct io_thread_req *, > | ^ >arch/um/drivers/ubd_kern=2Ec:1080:23: error: assignment to 'struct io_thr= ead_req * (*)[]' from incompatible pointer type 'struct io_thread_req **' [= -Wincompatible-pointer-types] > 1080 | io_req_buffer =3D kmalloc_objs(struct io_thread_req *, Thanks for finding this! I'll get these fixed up today; I missed um in my = build testing=2E Doing these tree-wide changes is tricky without having a = sane way to get them into -next first=2E -Kees --=20 Kees Cook