Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1712834ybl; Sun, 18 Aug 2019 08:54:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqx74iP25T/aB8Mjr8UJTCIGChVILa2nnVMksmr1ck40wHOMdg6X23+ORmrOIaJLmEx6qafG X-Received: by 2002:a63:5f01:: with SMTP id t1mr14819818pgb.200.1566143675371; Sun, 18 Aug 2019 08:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566143675; cv=none; d=google.com; s=arc-20160816; b=RTGziSXpnpaPwB8rGDHKtYPYXQpFkRqRUKTGkb1EV4V/eJaSQJxd17AZkzg/xTweXP lEgSRLKoqbNWHRYTxkA5bTzFCJdbxopv8Om+PeFzGOFH1ED0VqufucVcA+wBjhtE3tKr yNgTU8r/PtRyxIeUTer8XKz0Txw15XLJmWlylmx2sGyuII4IBsNJoD8yzGFAjtN8MbQ5 GAXcqBB4BVrey76zo4C7PZ8nRq2H5TyMReD/2l98Zdt/P4R3cbQSQ69dkJjiCgpwSlO3 JaV8k629MfB/vrx+QuoFN5KsiQ/EBggvrn9cvQXR5gT28FXs1siB63hJEbOPznRCeuef fjOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=g1IQSZ36049sL5m/iNqflUFI3mH7QgkOZ4xc+pWsHjk=; b=XB7AAoL9So4aRbplDoFd39cOYFW9e2yfeuARzbHJOjbPWBQb8T30pTuak5OE9Yqeny jZHyMNZ2uAndRvkwWw0fFDTrrZSh58AcmcxbGG7xyGDKItFDVNw9QUC2Y+4P3DUsS/kh CGBlGIJdd1+cjQeRiSaYcJAIzxMwaOQ074qsJt1KIHdzKGGfkCm1wyUta76dkH+jh1Ut W7FXuGRNQr7gd8yf7FXZ3CmWQT98Zy5ZMlXeJLukpIco+hZOwtfjnOjfrcu2zhTAbuJA aQOCF1wXjjdp2Xcz5BWbtC25vZs8PpkupyI48i2Szbu/wKmhAck97FbHqIJnemjWnH2D c/wQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11si7986264pga.407.2019.08.18.08.54.20; Sun, 18 Aug 2019 08:54:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726824AbfHRPwz (ORCPT + 99 others); Sun, 18 Aug 2019 11:52:55 -0400 Received: from mail-yw1-f68.google.com ([209.85.161.68]:39371 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfHRPwz (ORCPT ); Sun, 18 Aug 2019 11:52:55 -0400 Received: by mail-yw1-f68.google.com with SMTP id x74so3362174ywx.6 for ; Sun, 18 Aug 2019 08:52:54 -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=g1IQSZ36049sL5m/iNqflUFI3mH7QgkOZ4xc+pWsHjk=; b=SdqIYLIGXAoRtbHoezdLO5tZXMevWq38ZyNxPvQC6zteyHhQ1PcQYTXYB+lFaaSz5h 4VyOu3D6Se2AQQ7xmko99edOi773yxZcUAML3x8qLAdv2vzH5HsaGLsbWcg/mVETaUSf znD8w743RG8A50UWKXze1rYhhEWmftaWiN3BIZeBGmhcx7fO8NhOjnQdeh/LleL5qf3x 78+goX/N5b1e3flqnKHVHSsEtmT6RgPuiXu32/dKYzwG3rJkic0D9WDyEKT+G+S0Hm/R CCNWHHqWIVMyd3S3sHI7anNHsyDcF1ulmmBHbjwGpIqy0HkWOsDwJ96Ykhghtebxbq5q 7KcA== X-Gm-Message-State: APjAAAVy1WD/dGiSKaKRwa/FGZzjnZH8LWsaFHlzl6+5AW81lqTDRomu i6r+TdOKpIkwsdwUJCBTH/c= X-Received: by 2002:a81:48cc:: with SMTP id v195mr13809539ywa.140.1566143574212; Sun, 18 Aug 2019 08:52:54 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id r20sm2648984ywe.41.2019.08.18.08.52.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Aug 2019 08:52:53 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Kyungmin Park , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Vignesh Raghavendra , linux-mtd@lists.infradead.org (open list:ONENAND FLASH DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] mtd: onenand_base: Fix a memory leak bug Date: Sun, 18 Aug 2019 10:52:49 -0500 Message-Id: <1566143569-2109-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In onenand_scan(), if CONFIG_MTD_ONENAND_VERIFY_WRITE is defined, 'this->verify_buf' is allocated through kzalloc(). However, it is not deallocated in the following execution, if the allocation for 'this->oob_buf' fails, leading to a memory leak bug. To fix this issue, free 'this->verify_buf' before returning the error. Signed-off-by: Wenwen Wang --- drivers/mtd/nand/onenand/onenand_base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c index e082d63..77bd32a 100644 --- a/drivers/mtd/nand/onenand/onenand_base.c +++ b/drivers/mtd/nand/onenand/onenand_base.c @@ -3880,6 +3880,9 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) if (!this->oob_buf) { if (this->options & ONENAND_PAGEBUF_ALLOC) { this->options &= ~ONENAND_PAGEBUF_ALLOC; +#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE + kfree(this->verify_buf); +#endif kfree(this->page_buf); } return -ENOMEM; -- 2.7.4