From patchwork Tue May 16 09:06:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 9732101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C0CE6022E for ; Wed, 17 May 2017 23:38:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5756287D6 for ; Wed, 17 May 2017 23:38:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A537287F4; Wed, 17 May 2017 23:38:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E2E0287D6 for ; Wed, 17 May 2017 23:38:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1D2996E504; Wed, 17 May 2017 23:36:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pg0-f65.google.com (mail-pg0-f65.google.com [74.125.83.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4DBCD6E2D3 for ; Tue, 16 May 2017 09:06:15 +0000 (UTC) Received: by mail-pg0-f65.google.com with SMTP id i63so20674463pgd.2 for ; Tue, 16 May 2017 02:06:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=4eIvwnmNLsjka8Y7c7TX4ehNpq8ThNt4PyF7HjNmpvw=; b=nnOwq25ZPCbx3zENcFHF5oXsJDdzisiDBBtV/sNTQbuwNMDvQfqx5WzTVrh2tDcDv7 lJBXhmSTGaUVwbi3yoHVOBe4WjRlqYmGbvJ90e4LCVrefFyjFuioUVn+YXXPi9uFxfN7 zsKQ56yD0aO9KXE7Tgk8JhPJ379MyAtczkGeJP3nIK0du4q3CZ6d5de9al4wTHphn3s6 s60TyjmQTwpqRF4PvxDKS7R/7/VRaPMCn/06PCRI1PVdW6/Ien6jNnJ8e1uzQIzTFs5f r/yve0n8OuSHOEzG2CJRa2N1HbLHMBC3bUuqEi6dbECATV80D/rsyqkTGRo7bBCMl3I1 Mg+Q== X-Gm-Message-State: AODbwcA9yARwZ6Iin+Z43K26owKUVAIIrL2VQmvIILljLwNj2Y5ZsxPa a7kT5y4zBdLcFQ== X-Received: by 10.98.110.138 with SMTP id j132mr10705865pfc.51.1494925574911; Tue, 16 May 2017 02:06:14 -0700 (PDT) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id q64sm27411666pfi.69.2017.05.16.02.06.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 May 2017 02:06:14 -0700 (PDT) From: Michal Hocko To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: use kvmalloc_array for drm_malloc* Date: Tue, 16 May 2017 11:06:06 +0200 Message-Id: <20170516090606.5891-1-mhocko@kernel.org> X-Mailer: git-send-email 2.11.0 X-Mailman-Approved-At: Wed, 17 May 2017 23:35:44 +0000 Cc: Michal Hocko , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko drm_malloc* has grown their own kmalloc with vmalloc fallback implementations. MM has grown kvmalloc* helpers in the meantime. Let's use those because it a) reduces the code and b) MM has a better idea how to implement fallbacks (e.g. do not vmalloc before kmalloc is tried with __GFP_NORETRY). Signed-off-by: Michal Hocko --- include/drm/drm_mem_util.h | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h index d0f6cf2e5324..b461e4e4e6db 100644 --- a/include/drm/drm_mem_util.h +++ b/include/drm/drm_mem_util.h @@ -43,31 +43,12 @@ static __inline__ void *drm_calloc_large(size_t nmemb, size_t size) /* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */ static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size) { - if (size != 0 && nmemb > SIZE_MAX / size) - return NULL; - - if (size * nmemb <= PAGE_SIZE) - return kmalloc(nmemb * size, GFP_KERNEL); - - return vmalloc(size * nmemb); + return kvmalloc_array(nmemb, size, GFP_KERNEL); } static __inline__ void *drm_malloc_gfp(size_t nmemb, size_t size, gfp_t gfp) { - if (size != 0 && nmemb > SIZE_MAX / size) - return NULL; - - if (size * nmemb <= PAGE_SIZE) - return kmalloc(nmemb * size, gfp); - - if (gfp & __GFP_RECLAIMABLE) { - void *ptr = kmalloc(nmemb * size, - gfp | __GFP_NOWARN | __GFP_NORETRY); - if (ptr) - return ptr; - } - - return __vmalloc(size * nmemb, gfp, PAGE_KERNEL); + return kvmalloc_array(nmemb, size, gfp); } static __inline void drm_free_large(void *ptr)