From nobody Sat Apr 20 06:42:57 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1565587519; cv=none; d=zoho.com; s=zohoarc; b=L2Extdv3D5IiZ8nQ/xNHB9asCKT32m72YMAlHsUZBevwOx7cyqX6nso0+ODrtqJIUs1VdWzMylniIhzuXhPAkn6zbS+ZiruU0cKU9gLeE2Meb1Ol0vSsLRO2KRh2oKJxdkUlUO91r617B395p1klGCVj3rBcMB/9z0yr9iFjqIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565587519; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=FheVI0yI7lYEChG4b65+AR9WWlyIRJhCmhds9xW/gBY=; b=TWVeCamcyRewkc+s9Ajfw/dl1vwmOsPavznbOK0Td+cmK6xKh5ogT2hMAHnQNoQXAsan1+R0oWoPDs9U06YnyXotfNH+onOUA8bOlzfur0tKoPt6Q2TnR7kes4rG2yV6HocgHM6XbaNqLK8VMMyIZd3w33VXLPFYNUmjm3pX/zI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1565587519672502.8544558682829; Sun, 11 Aug 2019 22:25:19 -0700 (PDT) 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 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) 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) X-Inumbo-ID: c2f2122a-bc5c-11e9-b16e-af4f2310b143 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) 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=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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=C3=A9 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 *ri= ng, const char *dir) } } =20 + err =3D -ENOMEM; for (i =3D 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) { req =3D kzalloc(sizeof(*req), GFP_KERNEL); if (!req) @@ -987,7 +988,7 @@ static int read_per_ring_refs(struct xen_blkif_ring *ri= ng, const char *dir) err =3D 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; } =20 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; } =20 static int connect_ring(struct backend_info *be) --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel