From patchwork Sun Aug 11 17:23:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 11089299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FB446C5 for ; Mon, 12 Aug 2019 05:25:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FD6027FA8 for ; Mon, 12 Aug 2019 05:25:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F375227FAC; Mon, 12 Aug 2019 05:25:33 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 954AC27FA8 for ; Mon, 12 Aug 2019 05:25:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hx2oQ-00018V-8J; Mon, 12 Aug 2019 05:24:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hwrZG-00030Q-Jd for xen-devel@lists.xenproject.org; Sun, 11 Aug 2019 17:23:42 +0000 X-Inumbo-ID: c2f2122a-bc5c-11e9-b16e-af4f2310b143 Received: from mail-yw1-f67.google.com (unknown [209.85.161.67]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c2f2122a-bc5c-11e9-b16e-af4f2310b143; Sun, 11 Aug 2019 17:23:40 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id i18so2873454ywa.3 for ; Sun, 11 Aug 2019 10:23:40 -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=tn6nhjNQ7pdIDBNVvjNcCirLgHTb4d9vEhC1PgN0dmg=; b=HPA+aNecUagpqHodqC6t8wJRN++XWJHFKv++Q/cxtOHjNZnC++jugA0K+rRrTKoiy8 XXZ0iVhii9lgd6HG9MLSYop/CRmjw7urPzLQ5zvt8ImFPrAyoiaSXq1edO9fxN9CivUt UDrLLV7k5AEZnwA7l0fHWISldeKUq99B5nEdQ1zjMa4AVsJ5IfuX+CxFN9iOi5amieX5 XFb8ZeIZfohu01Vdq1KWTqhMhfEsCHr9p0GwDqGXWC1r8ic82VXw5GVvLqabpCkx8Voc 0HKWM0UudSnspN4swTW+DZGZfcmofQNoX4rx2ERRIqh01ApwutpEU9nuNoNbzrqZIxde JBwQ== X-Gm-Message-State: APjAAAVvtoelr21c1MHipbriM0GkTNB6i/MGQBlLHA/CMCXYB6gOKhDE b+kDNKh5+BCbdTJ+2cSrNP0= X-Google-Smtp-Source: APXvYqyQ0YGPfGErlB97Ql1pCAIUrzC/nGiwLC0F+lrA2nquYsm718zy1jqHZRJ/vG2HIjgexdP3cQ== X-Received: by 2002:a81:50c:: with SMTP id 12mr22280201ywf.380.1565544220073; Sun, 11 Aug 2019 10:23:40 -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 l4sm1027236ywd.0.2019.08.11.10.23.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Aug 2019 10:23:39 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Date: Sun, 11 Aug 2019 12:23:22 -0500 Message-Id: <1565544202-3927-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 X-Mailman-Approved-At: Mon, 12 Aug 2019 05:24:04 +0000 Subject: [Xen-devel] [PATCH] xen/blkback: fix memory leaks X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Jens Axboe , Konrad Rzeszutek Wilk , open list , "open list:BLOCK LAYER" , "moderated list:XEN BLOCK SUBSYSTEM" , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In read_per_ring_refs(), after 'req' and related memory regions are allocated, xen_blkif_map() is invoked to map the shared frame, irq, and etc. However, if this mapping process fails, no cleanup is performed, leading to memory leaks. To fix this issue, invoke the cleanup before returning the error. Signed-off-by: Wenwen Wang Acked-by: Roger Pau Monné Reviewed-by: Boris Ostrovsky --- drivers/block/xen-blkback/xenbus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 3ac6a5d..b90dbcd 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -965,6 +965,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir) } } + err = -ENOMEM; for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) { req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) @@ -987,7 +988,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir) err = xen_blkif_map(ring, ring_ref, nr_grefs, evtchn); if (err) { xenbus_dev_fatal(dev, err, "mapping ring-ref port %u", evtchn); - return err; + goto fail; } return 0; @@ -1007,8 +1008,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir) } kfree(req); } - return -ENOMEM; - + return err; } static int connect_ring(struct backend_info *be)