Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2875049ybl; Sun, 11 Aug 2019 10:26:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwCwoKo9j4jottPg5Irba0gD5DrxV1GT75wu2hjpHKzHgdengUbygBSElZ7qItwR3NIiv+D X-Received: by 2002:a17:902:20c2:: with SMTP id v2mr17188582plg.209.1565544388267; Sun, 11 Aug 2019 10:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565544388; cv=none; d=google.com; s=arc-20160816; b=JEo2bvDlLIPsXISoP3t4AcdcBdm6Us0ZwQpCfx3YjJKpo39PrLZaojFACYQKbcq8QX 6c4PUTWpwaxvu32GC36mLvJYtUtcFhvwDTmJrhsYhb0gXXWSTWAPB5bnipGOASdDW3Ty kNtTuw7lfE06Hl/7TxfUrJF94ryvyYQZbYYbyvMzfjRF8w7ZV1s57t7ZadJyLoPKZcDL 7R4zossuE5C/uZevX2ATrGYHcmoWn6c9TgQw47hn9LgalGL6wVpXwFgWGJcV21kgP32V JAoNEkuJXqjYp9dng0Uvat19N17moE5bs8aWNT5TdyPrfmnfKjFI6Jxqzi56pVSem+u6 z9kA== 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=tn6nhjNQ7pdIDBNVvjNcCirLgHTb4d9vEhC1PgN0dmg=; b=ZhQcclSjyVMe5TUXvmZ72NXoqCfAlBw3+cbr4TNIAx/5q8hi/5V2fJWID8ler7Gh2t mOC6YI/wKZxYX0hmXnU85xrHX4qJlCtHB54hi0yoIL32+AttdhgavsO5tyDbUIid/8nM C5ew0QajjrPObbm0VhPUOTLnJmNmK0+nEwSmXOQLSZNBKzKQI06lK2y0zggllCT6c9Z2 0/sUS5rawr2V45ObqJayI+P7tMdBF5vPilIg/OCOKWQEqdKv+2HbVpmknE6DzP1s/u7B m4mdljTBjdd3G6cvNJ1Xqp667X8/Yc1HP0FKubFz8qBUgGPQ9GFnVfGI35GKTuKjZZf7 kTYQ== 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 g1si55561770plg.353.2019.08.11.10.25.43; Sun, 11 Aug 2019 10:26:28 -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 S1726144AbfHKRXm (ORCPT + 99 others); Sun, 11 Aug 2019 13:23:42 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:43813 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbfHKRXl (ORCPT ); Sun, 11 Aug 2019 13:23:41 -0400 Received: by mail-yw1-f66.google.com with SMTP id n205so37953992ywb.10; 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=Q4HxoqNQmDtNQG+lssU+Y9bv60ghSM7/KASV/auxtsiUOQQACxYd0jfDCBz1zp1otq ijytVPKRnPklz5rW4gVMY3aeiiDfQtjji8tD7gM8kG1/icmXA97OgLeWQEkihf/qYdb7 y8eCe0uVu7iPZoScrjjaeCLbdJ9/PqfQ3yN9nhRkkBR4r4YG6G75iVo9i7sb+rhOtbkV jNPhiGyvuk3SfW5cxySYn1787idvlqrp8xL4aJC1RpX+jSkw2kq+7c1oRqhJzpIDBvft y4VhHrNUuMWjyOr9WzAI/FFZUCj77gB/gKx7q41QAC9RLA3+rU6Nyd0Wgeugvnxadrzp I2kQ== X-Gm-Message-State: APjAAAV1XJkdQbB6Qsqe6DdRGW8G2GGM51q57+ql/hMISnY7pF4T3eKi viwTBo/I2r/KwEWWLw+pPP5Z+usWh4w= 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 Cc: Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe , xen-devel@lists.xenproject.org (moderated list:XEN BLOCK SUBSYSTEM), linux-block@vger.kernel.org (open list:BLOCK LAYER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] xen/blkback: fix memory leaks 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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) -- 2.7.4