Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp3566353rwj; Mon, 19 Dec 2022 21:39:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ZTuOoZqscwp9FC93aa+VvDyQkZ4eIUm2TzToIcO0wbfumGUSJR+J2+hJ4njKk1gQU3Moc X-Received: by 2002:a17:90a:9bcc:b0:219:2ac2:425c with SMTP id b12-20020a17090a9bcc00b002192ac2425cmr47670303pjw.47.1671514754677; Mon, 19 Dec 2022 21:39:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671514754; cv=none; d=google.com; s=arc-20160816; b=0RRiH/4U3p+HinRLuq8qyQFnZ2G7jjSFW5JjnaZH6Gks80oQIK7ZGmSLnxgr9M6i9z VC30Pr7n174JgqfVmkh9eusxsa7lHr3d6gXVb+3zydI7ivyLLzyBx3gVRLb54kasSu/r Wppsuk/XnNG9obqJwvtuwus2tmy0UdRS+8IEmDtInV2tPSaTWgxi92ATcqnJUZWHEG1x JW2hdOEz7Z+cNk5M1KRj4oaePgq0ilCu2ootayoPlzUdHCgrSAyzacj5IFaWn67oS7V4 yDDQd4j8btXAHxytJAJSTrtBXgL1k0htAKfhbIY/G1DgSMG2TOsW5DhOBp52/0C0yTuI T0PA== 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=IDZY0exge1y0ypk/10nNU3r8ZayyqxLCW56Ho7hV0v8=; b=VqiNkyhFvXIKaZpXLqOV1ch94Y30i66sGPe2AVlNN9gGhYp44R9H42Fypa/WiA+lQe hTuX+PFTX6j3GXfu7i7UhkPVpwTaNnxF8BJJn5+s2QWxB46b+rGky8fvHaTlc5ohIbYy 73Sw4M48T/hFJwOjz8kdLd3yoddE/Wm+EOzrF/tLedyxT3vW7hlI0NbmArBm9PoGyjak cX6oTyKrQalrIYhM4i06QVRsZR4qObMFMgsjfLFoTSbLhFIfTKH7oNJiO6dZy0SFxUHL DP76EA+HfsoCQ9Z96rPsFhvp2lIPv0wBvJwO2Iwk8bC1gTsyV1WMEveR5GEEllzXwXl8 N2Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=e0NyAsLb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hi9-20020a17090b30c900b001fab0d18bcasi12375521pjb.66.2022.12.19.21.39.05; Mon, 19 Dec 2022 21:39:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=e0NyAsLb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232716AbiLTFZi (ORCPT + 70 others); Tue, 20 Dec 2022 00:25:38 -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-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 device *dev, size_t size, int i = 0; int order_idx = 0; - if (array_size <= PAGE_SIZE) - pages = kzalloc(array_size, GFP_KERNEL); - else - pages = vzalloc(array_size); + pages = kvzalloc(array_size, GFP_KERNEL); if (!pages) return NULL; -- 2.34.1