From nobody Wed Sep 17 09:57:38 2025 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 1D528C4332F for ; Tue, 20 Dec 2022 05:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232829AbiLTFZj (ORCPT ); Tue, 20 Dec 2022 00:25:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbiLTFZg (ORCPT ); Tue, 20 Dec 2022 00:25:36 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF61C12759 for ; Mon, 19 Dec 2022 21:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1671513916; bh=sFskYXbidjd/kcmqsM6ylTeRnbnKAC12byfrx9G5ZBw=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:MIME-Version: Content-Type; b=e0NyAsLbQs/avEnwiC7ZsVK9GU4zrPuQ2XS2Ty1xYms0TvZepQfGJFyoXdovGjoPg nLFh9Azc+zv2bYdeL81WbyjoQwjCRe+8KHm/0j+9fgCl8r4OFQLTKGwboLCvlQzsrA h66ImFahB2Wf5lr5pJmUA8uWAo9X2/daha3s3yRU= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via ip-206.mailobj.net [213.182.55.206] Tue, 20 Dec 2022 06:25:16 +0100 (CET) X-EA-Auth: UI0gHJBKyazNjZiXWvC0DmV1kOkEQvUhUW4KYOzbDoHDVw8pLiXzVtXTgzUhY3wuuWiIusiFO/ZVMxGyeNWUeIXmzD/eWeUJ Date: Tue, 20 Dec 2022 10:55:11 +0530 From: Deepak R Varma To: Russell King , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , drv@mailo.com Subject: [PATCH] ARM/dma-mapping: use kvzalloc for fallback memory allocation need Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the memory sizes are not known upfront, it is preferred to use the kvzalloc helper function instead of direct conditional evaluation of size and kzalloc/vzalloc fallback design. The kvzalloc helper function in this case is more efficient as it avoids indefinite kzalloc retries when a small memory size is needed but is unavailable. This LWN article has further details on the advantages of using kvzalloc in case of fallback memory allocation needs: https://lwn.net/Articles/711653/ This patch proposal is based on following Coccinelle warning using the kvmalloc.cocci semantic patch. arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc Signed-off-by: Deepak R Varma --- Note: The patch proposal is compile tested only. arch/arm/mm/dma-mapping.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index c135f6e37a00..2b79af377a81 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -855,10 +855,7 @@ static struct page **__iommu_alloc_buffer(struct devic= e *dev, size_t size, int i =3D 0; int order_idx =3D 0; - if (array_size <=3D PAGE_SIZE) - pages =3D kzalloc(array_size, GFP_KERNEL); - else - pages =3D vzalloc(array_size); + pages =3D kvzalloc(array_size, GFP_KERNEL); if (!pages) return NULL; -- 2.34.1