From patchwork Wed Jul 13 02:41:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 12915899 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F533C433EF for ; Wed, 13 Jul 2022 02:41:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBC569400F8; Tue, 12 Jul 2022 22:41:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6C8B9400E5; Tue, 12 Jul 2022 22:41:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5ADE9400F8; Tue, 12 Jul 2022 22:41:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A7EBB9400E5 for ; Tue, 12 Jul 2022 22:41:18 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6F45A34A15 for ; Wed, 13 Jul 2022 02:41:18 +0000 (UTC) X-FDA: 79680525036.03.2701493 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf20.hostedemail.com (Postfix) with ESMTP id 1ACD51C0099 for ; Wed, 13 Jul 2022 02:41:17 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id fz10so10087210pjb.2 for ; Tue, 12 Jul 2022 19:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ug/iYyU8Y2LYfkSANaeOBwHOpsae97E43YefQnjMlgI=; b=GuHqHjJoz5lA0Wlh1degTH0DjfZyKQsicqSOdE6pvYhJkdnPCew2bxsrWJQpaS7dFA 4RqN50W4Jd5IlkR2W319WTv+m9zhQAAxMriFFu4fjDLEL6INd2QEH2XvZC4csPvyPdmN w+Epagp0tk29n8uRYUogmpWhCr3TxTbxvq8ZewyyWaYWzs31D/Mzy6O8LRRyMcKCmwsj 5OMefGEbL9nvgyIUPcg1SbX6hEiAcwVbkTrKq0ADUlEpmk+9SpjO9UtrvFdez1cGThEn 00/zPbMQ4TWzSyxw3WH4TT1oNoRJyhQU8/1OnZw0/V3DbKTqdpbY3TY0Elg0ghjq5lyp K/nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ug/iYyU8Y2LYfkSANaeOBwHOpsae97E43YefQnjMlgI=; b=p/9TrU53/gL4HcUuFMojDZJxG0bjpCyWuPXu+tlon6yHnkdOslkIhb7Kj1SJDtfyNP +ARG38r2jiq4EKaqXE1XdjUoeDcEEmz1MyOe1LPTYvT8jhq0qOV+OsMUQimSFz0bPEaY g+x7yA4ftG0xqpsFuCA96ApLx9bJYfTsqp0F0wgzJC6hrcjWHUiVu9d3q64F8FuvwMvS 887IP4a2sCZEmJFBNl0uFvRIocPEXV0XbI5D1Med0WLTiWzYSVMBv3IQD4GTgltP9OkQ Kdl5SgaVQNw42CBy4lQi0RWppq6hSc6Y1avYnj+VtarEbzcZH+/9NdfJF/1URBSSvgel dnkA== X-Gm-Message-State: AJIora/sNsN815u5fdOvPeJzKeTL/WavenaCm1g7nu5CwnoFtrFkoGRz diM0w3Kui/FTsXOSiH9kfmE= X-Google-Smtp-Source: AGRyM1uf+07kc+nyIgZjOz7tvF8Xan3hUYQyrAtZn/XW58Uf0z6XPew7fdi78pAG2UjAFAjBdzYrwg== X-Received: by 2002:a17:902:854a:b0:16b:a3c3:ed8c with SMTP id d10-20020a170902854a00b0016ba3c3ed8cmr1255709plo.167.1657680076962; Tue, 12 Jul 2022 19:41:16 -0700 (PDT) Received: from localhost.localdomain ([122.171.73.195]) by smtp.gmail.com with ESMTPSA id n30-20020aa7985e000000b00528d41a998csm7724182pfq.15.2022.07.12.19.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jul 2022 19:41:16 -0700 (PDT) From: Souptick Joarder To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Souptick Joarder (HPE)" , kernel test robot , Dan Carpenter Subject: [PATCH] mm/khugepaged: Avoid possible memory leak in failure path Date: Wed, 13 Jul 2022 08:11:09 +0530 Message-Id: <20220713024109.62810-1-jrdr.linux@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657680078; a=rsa-sha256; cv=none; b=DCAcmpJF0gXKQ2vKSE435QcgCLKGu8j0mI5eSzxrbfouRJt76q6Lcv+eva4Ym5Op+kM3pw epiqqG5/NX3EZjw7VSjR8MnA0PGVqAMHWS8H5x6+iMt+aUp8ZjrhzuhjiFnGDTcV8cH8eU UQWlC40LlKi35uxwyKCc6t/fJ1KJafw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GuHqHjJo; spf=pass (imf20.hostedemail.com: domain of jrdr.linux@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657680078; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=Ug/iYyU8Y2LYfkSANaeOBwHOpsae97E43YefQnjMlgI=; b=TGmIywnpnERsaipzLGOzdwtIOSJyjibvH5Qg4kPU0pmG5pEHbSJQrDLhyroVRd3kyCGkqg fzYxF2KAtIAsrIO8JvN45B72a2IEGEvXmybK79dNIoJYHCczZClmCAozxSQ8qOx+dE/HrD 7uS5/QtZx40VJ5pOjDP41aCXaw44Uuc= X-Rspamd-Queue-Id: 1ACD51C0099 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GuHqHjJo; spf=pass (imf20.hostedemail.com: domain of jrdr.linux@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam02 X-Rspam-User: X-Stat-Signature: ogee5brti55fk1xnanc6q9zdtane797p X-HE-Tag: 1657680077-23394 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Souptick Joarder (HPE)" smatch warnings: mm/khugepaged.c:2409 madvise_collapse() warn: possible memory leak of 'cc' Avoiding possible memory leak. Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Souptick Joarder (HPE) --- mm/khugepaged.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 0207fc0a5b2a..8da9e7467543 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2397,12 +2397,6 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, BUG_ON(vma->vm_start > start); BUG_ON(vma->vm_end < end); - cc = kmalloc(sizeof(*cc), GFP_KERNEL); - if (!cc) - return -ENOMEM; - cc->is_khugepaged = false; - cc->last_target_node = NUMA_NO_NODE; - *prev = vma; /* TODO: Support file/shmem */ @@ -2415,6 +2409,12 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, if (!hugepage_vma_check(vma, vma->vm_flags, false, false, false)) return -EINVAL; + cc = kmalloc(sizeof(*cc), GFP_KERNEL); + if (!cc) + return -ENOMEM; + cc->is_khugepaged = false; + cc->last_target_node = NUMA_NO_NODE; + mmgrab(mm); lru_add_drain_all();