From patchwork Mon Aug 31 12:17:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Matias_Bj=C3=B8rling?= X-Patchwork-Id: 7099621 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B685BBEEC1 for ; Mon, 31 Aug 2015 12:17:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E0AC4206FD for ; Mon, 31 Aug 2015 12:17:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C26C20706 for ; Mon, 31 Aug 2015 12:17:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752703AbbHaMR1 (ORCPT ); Mon, 31 Aug 2015 08:17:27 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:37933 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752276AbbHaMRZ (ORCPT ); Mon, 31 Aug 2015 08:17:25 -0400 Received: by wicpl12 with SMTP id pl12so25812695wic.1 for ; Mon, 31 Aug 2015 05:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bjorling.me; s=google; h=from:to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=9P0wCFIKUa7oVabfDEnWdhWxH8r03HSSqa5+dccjCg8=; b=E6DVmjxabIsbWFTJlucc0qeFhGFiNPdHidOh36kCA0TQXMvOhEFubfLV+mqKpuPqVO VJIoxZgkTamQXqMeQnPphzktNKpGj96K3Qw0+AaSurkPBQ03oZhAdi8ydzATJidfrrvD XCDT+kyrO3U9e43xqXCQ+KiQtOdZ32dkQwXB4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=9P0wCFIKUa7oVabfDEnWdhWxH8r03HSSqa5+dccjCg8=; b=kDGCyx2yo4qkYSXOZiWTSvda4BqJV2U+b+G5IK1EcZJzd/AVUcp5v8UWnx4c5vXdC4 FEqIck754ofjOh70Gqjy9OjHtEBIIACRQwLesDmKGxuvNpaC/MEjR1/RgmOJFQsA3O19 3dua99nCVl9KR7DhZD6fr0Y8IoINgNngoCHQ5tYEOH+i4lQbN75TPJECoPnFvWZJBIXB Jg0EnqHNopJ443lrE6I7K+w9s+MI1v4ma0qJEP8zlEVxylqipvqmtmXH8M4AVN/8ZY9a v8BdK0xe0uzV3xGuCY71nlvX/uAq2eOS6irfFoq53jWB7Dp8Mcb0Afnro6f9Xra0SMwy FtGw== X-Gm-Message-State: ALoCoQmb1IN645rplywo0VINLxrCdYwweE1yThJaMKvyCZP/MuPAwDz45aL3ADoMWqO8zi3pdsOZ X-Received: by 10.194.90.70 with SMTP id bu6mr27126219wjb.149.1441023444704; Mon, 31 Aug 2015 05:17:24 -0700 (PDT) Received: from localhost.localdomain (6164198-cl69.boa.fiberby.dk. [193.106.164.198]) by smtp.gmail.com with ESMTPSA id d7sm17743955wiz.22.2015.08.31.05.17.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 31 Aug 2015 05:17:24 -0700 (PDT) From: =?UTF-8?q?Matias=20Bj=C3=B8rling?= To: axboe@fb.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Matias=20Bj=C3=B8rling?= Subject: [PATCH] null_blk: fix memory leak on cleanup Date: Mon, 31 Aug 2015 14:17:18 +0200 Message-Id: <1441023438-16249-1-git-send-email-m@bjorling.me> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matias Bjørling Driver was not freeing the memory allocated for internal nullb queues. This patch frees the memory during driver unload. Signed-off-by: Matias Bjørling --- drivers/block/null_blk.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c index 69de41a..90f6781 100644 --- a/drivers/block/null_blk.c +++ b/drivers/block/null_blk.c @@ -406,6 +406,22 @@ static struct blk_mq_ops null_mq_ops = { .complete = null_softirq_done_fn, }; +static void cleanup_queue(struct nullb_queue *nq) +{ + kfree(nq->tag_map); + kfree(nq->cmds); +} + +static void cleanup_queues(struct nullb *nullb) +{ + int i; + + for (i = 0; i < nullb->nr_queues; i++) + cleanup_queue(&nullb->queues[i]); + + kfree(nullb->queues); +} + static void null_del_dev(struct nullb *nullb) { list_del_init(&nullb->list); @@ -415,6 +431,7 @@ static void null_del_dev(struct nullb *nullb) if (queue_mode == NULL_Q_MQ) blk_mq_free_tag_set(&nullb->tag_set); put_disk(nullb->disk); + cleanup_queues(nullb); kfree(nullb); } @@ -459,22 +476,6 @@ static int setup_commands(struct nullb_queue *nq) return 0; } -static void cleanup_queue(struct nullb_queue *nq) -{ - kfree(nq->tag_map); - kfree(nq->cmds); -} - -static void cleanup_queues(struct nullb *nullb) -{ - int i; - - for (i = 0; i < nullb->nr_queues; i++) - cleanup_queue(&nullb->queues[i]); - - kfree(nullb->queues); -} - static int setup_queues(struct nullb *nullb) { nullb->queues = kzalloc(submit_queues * sizeof(struct nullb_queue),