From patchwork Mon Nov 12 15:42:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Battersby X-Patchwork-Id: 10678863 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 9556114E2 for ; Mon, 12 Nov 2018 15:42:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82E8F2A000 for ; Mon, 12 Nov 2018 15:42:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 731D92A07D; Mon, 12 Nov 2018 15:42:59 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 555F22A000 for ; Mon, 12 Nov 2018 15:42:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FA7E6B0296; Mon, 12 Nov 2018 10:42:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5D4406B0298; Mon, 12 Nov 2018 10:42:57 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 498BA6B0299; Mon, 12 Nov 2018 10:42:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id 18E5F6B0296 for ; Mon, 12 Nov 2018 10:42:57 -0500 (EST) Received: by mail-qk1-f200.google.com with SMTP id 92so24498462qkx.19 for ; Mon, 12 Nov 2018 07:42:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:subject :to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=QH1IIg0CaNqSGBNxYjpd2D1uslcpAwDjwG+aYibniNg=; b=k1+KRbloaSs5TcU0OPCBA2zzWzdpdsBe79mL0k15fA8Ry+zoEOoCg7GgCAZGpYHmWi VGanFkpCo+ykmFBjJDQBsPa82wKWafc2DIxVtdzlFMr1cA8IKXjVKj6HTLR0zSZez/Gg EdnObpanFkGpqO5BD9SJRZueIhs1QCylE50vXYs5GeCGg/Vv/+sgat4FLmC43/Sra7Qv LROenc4tk4gretKLJxZtL8sEbSxskxQ5oHaoxa9LoPPv6Rl9g9oObgF+RPfoWBIYH+jS 9iYEhYd7NE9GRFcJHa5FJzBhSJOIhc7F6YPFuC6sj+Oco8cBL/vZu+0iq2mbDc0S2QSu iSbw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of btv1==854ac0a7dab==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==854ac0a7dab==tonyb@cybernetics.com" X-Gm-Message-State: AGRZ1gKAZOKtW8ACCtV/IvXkvVAkvwf6VK7nUCevKJqpyRh/0HlJ7LNp it4z+VvHS0G9yX44Lqyb9BteNolr5Qi2OjJgB16VQ++6srBTuY73wDOQeIajC6OZNETu6Z73qZq kruL/T7Eky2ggHossBMjz4O339OyZSfvURITbkgDBM/QOtR3cPOLS8OwDK+anPMCGWA== X-Received: by 2002:a37:781:: with SMTP id 123mr1336267qkh.231.1542037376770; Mon, 12 Nov 2018 07:42:56 -0800 (PST) X-Google-Smtp-Source: AJdET5dAXbrA/nQUjE6Hm/F/Xcg8jjPcXyLHFzHS5AAEGU0WIQ1PDUzC0yqwnWEMEzq4BFYQqjU8 X-Received: by 2002:a37:781:: with SMTP id 123mr1336205qkh.231.1542037375901; Mon, 12 Nov 2018 07:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542037375; cv=none; d=google.com; s=arc-20160816; b=dE9CKZECNo2HTRyPgYHbkNZz4wOyMlmFdT6SX2+0OqrP8Y/TbPBCpSwy5DGLVwD8rj Y/a147jhmVuEGQu0/k9FmX/A8t6euFUVv8DTQlLvDHe/YoAE0MLTznj5zscAv1kb+OK4 bsy8jCz+4bS7F3oe54xkAQoCTA9Bz9Fdby6Zfcggr7MlyBxHAgs7vA5zU3PbzZp2O64J vCte/e5iF8fDokad3+icFyOOsd5bLxbMigssoVllFoKL177o4ld9OnTQn3dt25EePvDX hDuZ9A19GW+N956bUMGjNBe7DPj8QGBSsvOqw0stBIrEM5Byu0s/fa/BAyLTrjVknZ4Y d+vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-language:content-transfer-encoding:mime-version:user-agent :date:message-id:cc:to:subject:from; bh=QH1IIg0CaNqSGBNxYjpd2D1uslcpAwDjwG+aYibniNg=; b=Qpxy+D/l2rxGCNYkd5bTLO3Bd/7+MzMihjXEj8kdCZCpAES1LQqRpy09xKoZ14dyaa ZJuyv+aYrrynopDGH+YI43iMdBiieCpcUJSurZ+BEgQ1N+QswFv6FQuzUYe7uQFeublB Cm+vMM6SDBsxDU9pdnXPvr1/xnJtfPp/jRKoZyuJmcu1QRYwiSdbWmYHabt8F6o8qGhg 7+soaBw1QHhCghOm8e2A41Pn9BMJD3+28h29OUulgVuRx7LVqqXMl7l8S63Q+EaT0vCw JpUUvf/7Hk8C4T3Ka0WgHmFWc2ahg08BoLh7wUA8QxTUWAe7eyl8Yi96OQe7Fy0jjw0l K5gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of btv1==854ac0a7dab==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==854ac0a7dab==tonyb@cybernetics.com" Received: from mail.cybernetics.com (mail.cybernetics.com. [173.71.130.66]) by mx.google.com with ESMTPS id d9si3485494qto.61.2018.11.12.07.42.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 07:42:55 -0800 (PST) Received-SPF: pass (google.com: domain of btv1==854ac0a7dab==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) client-ip=173.71.130.66; Authentication-Results: mx.google.com; spf=pass (google.com: domain of btv1==854ac0a7dab==tonyb@cybernetics.com designates 173.71.130.66 as permitted sender) smtp.mailfrom="btv1==854ac0a7dab==tonyb@cybernetics.com" X-ASG-Debug-ID: 1542037368-0fb3b01fb3add520001-v9ZeMO Received: from cybernetics.com ([10.157.1.126]) by mail.cybernetics.com with ESMTP id jmZTy47Ba0bTisqy (version=SSLv3 cipher=DES-CBC3-SHA bits=112 verify=NO); Mon, 12 Nov 2018 10:42:48 -0500 (EST) X-Barracuda-Envelope-From: tonyb@cybernetics.com X-ASG-Whitelist: Client Received: from [10.157.2.224] (account tonyb HELO [192.168.200.1]) by cybernetics.com (CommuniGate Pro SMTP 5.1.14) with ESMTPSA id 8529345; Mon, 12 Nov 2018 10:42:48 -0500 From: Tony Battersby Subject: [PATCH v4 3/9] dmapool: cleanup dma_pool_destroy To: Matthew Wilcox , Christoph Hellwig , Marek Szyprowski , iommu@lists.linux-foundation.org, linux-mm@kvack.org X-ASG-Orig-Subj: [PATCH v4 3/9] dmapool: cleanup dma_pool_destroy Cc: linux-scsi@vger.kernel.org Message-ID: <2ff327bb-59f7-5105-0bba-72329cb73154@cybernetics.com> Date: Mon, 12 Nov 2018 10:42:48 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Language: en-US X-Barracuda-Connect: UNKNOWN[10.157.1.126] X-Barracuda-Start-Time: 1542037368 X-Barracuda-Encrypted: DES-CBC3-SHA X-Barracuda-URL: https://10.157.1.122:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 2073 X-Virus-Scanned: by bsmtpd at cybernetics.com X-Barracuda-BRTS-Status: 1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Remove a small amount of code duplication between dma_pool_destroy() and pool_free_page() in preparation for adding more code without having to duplicate it. No functional changes. Signed-off-by: Tony Battersby Acked-by: Matthew Wilcox --- linux/mm/dmapool.c.orig 2018-08-02 09:59:15.000000000 -0400 +++ linux/mm/dmapool.c 2018-08-02 10:01:26.000000000 -0400 @@ -249,13 +249,22 @@ static inline bool is_page_busy(struct d static void pool_free_page(struct dma_pool *pool, struct dma_page *page) { + void *vaddr = page->vaddr; dma_addr_t dma = page->dma; + list_del(&page->page_list); + + if (is_page_busy(page)) { + dev_err(pool->dev, + "dma_pool_destroy %s, %p busy\n", + pool->name, vaddr); + /* leak the still-in-use consistent memory */ + } else { #ifdef DMAPOOL_DEBUG - memset(page->vaddr, POOL_POISON_FREED, pool->allocation); + memset(vaddr, POOL_POISON_FREED, pool->allocation); #endif - dma_free_coherent(pool->dev, pool->allocation, page->vaddr, dma); - list_del(&page->page_list); + dma_free_coherent(pool->dev, pool->allocation, vaddr, dma); + } kfree(page); } @@ -269,6 +278,7 @@ static void pool_free_page(struct dma_po */ void dma_pool_destroy(struct dma_pool *pool) { + struct dma_page *page; bool empty = false; if (unlikely(!pool)) @@ -284,19 +294,10 @@ void dma_pool_destroy(struct dma_pool *p device_remove_file(pool->dev, &dev_attr_pools); mutex_unlock(&pools_reg_lock); - while (!list_empty(&pool->page_list)) { - struct dma_page *page; - page = list_entry(pool->page_list.next, - struct dma_page, page_list); - if (is_page_busy(page)) { - dev_err(pool->dev, - "dma_pool_destroy %s, %p busy\n", - pool->name, page->vaddr); - /* leak the still-in-use consistent memory */ - list_del(&page->page_list); - kfree(page); - } else - pool_free_page(pool, page); + while ((page = list_first_entry_or_null(&pool->page_list, + struct dma_page, + page_list))) { + pool_free_page(pool, page); } kfree(pool);