Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7755046imu; Fri, 28 Dec 2018 04:24:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Wg7DW4UozDBdzqJR8QUTSIicaZ5zNYvvH3P2HtKzEaw1KhVwiufuTm9h2Lor4coufPtQx X-Received: by 2002:a62:435a:: with SMTP id q87mr27400292pfa.109.1545999876358; Fri, 28 Dec 2018 04:24:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545999876; cv=none; d=google.com; s=arc-20160816; b=jN62bblmuNjlyr+nSXGcxm1Q85aGwRwHxES7MF1BrRPQY8VO+SBmxf17yj0ePd2qpK Y0KLAkA0hUR8OwCe2BpM9RlIbJJyQa0lCIZGDWizEPluimMLIM6i4mcoxqCTfEswiUXo b7d9VA0CoDF+n5Lk7dW0rjxJfe5o/wyvhyV8cAHqs07cXiyAwd3/rK5pniFi5BgRJJ7n QsVTnYVoAah5bpfIwLcCYZdc3gUrEXJzxYugF2hU3d3aayEAPDWPGRTiTUUCmgpQOcWR 9d5FU/8eirwK8D0cK9fH4DixOTL/LXPCBq8NZWZaAGvRhkvYjMNieJDeTatVRRUo78g8 Oteg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Sl6n8Cyo7YEkkBVgEXoakF9zl/6bKqP1pjuQgucCGrE=; b=bxGYFTTfU7Y6vpHveK6ecreOU+YQLUDlRB9CB7vIQ2VU5tuXaCwqbcJ4yBSe9t2Yfy Ebd5DrXdNRTEDLsrcRLqCUF9+hwupQcycsU77GIGp4+i5Hlpbkt5EPmZt6CP1wD+tleF D0zksNl3IpkjIzV58b1X7XTyuBMiu+PbPWeHJr4CuQTbqhcndchhxaMMiYE/RsFJSLeM XJtNZzb756d/2qjq7VLaQGJByN1X64Enot9SvQJGCNPMVQ7iFquv0wqFnkRDEuIojMBN /5BrdtsWINATdq7WRWlEfilKs5nieIFBdznlceG5X98+qiT9HLfx9WQX08cZY50576if VgcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bIMdEaPF; 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 z5si25438216plh.133.2018.12.28.04.24.21; Fri, 28 Dec 2018 04:24:36 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bIMdEaPF; 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 S1730852AbeL1IgW (ORCPT + 99 others); Fri, 28 Dec 2018 03:36:22 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:51170 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730386AbeL1IgW (ORCPT ); Fri, 28 Dec 2018 03:36:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Sl6n8Cyo7YEkkBVgEXoakF9zl/6bKqP1pjuQgucCGrE=; b=bIMdEaPFlJk6NVoo9ZnqbqqVV OmwWGwL6TjXWI8PWiD6rWNaJldQ/57+S9CODJEkPwV3AoWCfRlCDwGaUssLM9LbY5zJH9h8cDbc3O YGrYP50JlPgVxFgHSg4hoIZ+iejQZUyi1Jh2KHJ704MtTBX4ID4GexdBYkNZyPzFs5WbDh4RRSllG 94ZOxzIn2PRTMQTV2BC2nLnPJmWAFWT3h+yhBPywTWORa6IvWgJFb0w3dNC1SQq7dzY0sYQWHWJvQ AgVFCmw8ClyC3MKd7b8uyZski+gy6kS47rD+SwbpFI+38tQB5hdXer02TpwKXMUbGG4H7I1VsZ8Kh 9tYdGHAPQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcncz-0001gB-EO; Fri, 28 Dec 2018 08:36:21 +0000 Date: Fri, 28 Dec 2018 00:36:21 -0800 From: Christoph Hellwig To: Corentin Labbe Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [BUG] net: sungem: device driver frees DMA memory with wrong function Message-ID: <20181228083621.GA25585@infradead.org> References: <20181223193821.GA24922@Red> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181223193821.GA24922@Red> User-Agent: Mutt/1.9.2 (2017-12-15) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please try this patch: diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index a52c6409bdc2..f454e0ed1398 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -284,32 +284,25 @@ static inline void dma_direct_sync_sg_for_cpu(struct device *dev, } #endif -static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, - size_t size, - enum dma_data_direction dir, - unsigned long attrs) +static inline dma_addr_t dma_map_page_attrs(struct device *dev, + struct page *page, size_t offset, size_t size, + enum dma_data_direction dir, unsigned long attrs) { const struct dma_map_ops *ops = get_dma_ops(dev); dma_addr_t addr; BUG_ON(!valid_dma_direction(dir)); - debug_dma_map_single(dev, ptr, size); if (dma_is_direct(ops)) - addr = dma_direct_map_page(dev, virt_to_page(ptr), - offset_in_page(ptr), size, dir, attrs); + addr = dma_direct_map_page(dev, page, offset, size, dir, attrs); else - addr = ops->map_page(dev, virt_to_page(ptr), - offset_in_page(ptr), size, dir, attrs); - debug_dma_map_page(dev, virt_to_page(ptr), - offset_in_page(ptr), size, - dir, addr, true); + addr = ops->map_page(dev, page, offset, size, dir, attrs); + debug_dma_map_page(dev, page, offset, size, dir, addr, false); + return addr; } -static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, - size_t size, - enum dma_data_direction dir, - unsigned long attrs) +static inline void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr, + size_t size, enum dma_data_direction dir, unsigned long attrs) { const struct dma_map_ops *ops = get_dma_ops(dev); @@ -321,12 +314,6 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, debug_dma_unmap_page(dev, addr, size, dir, true); } -static inline void dma_unmap_page_attrs(struct device *dev, dma_addr_t addr, - size_t size, enum dma_data_direction dir, unsigned long attrs) -{ - return dma_unmap_single_attrs(dev, addr, size, dir, attrs); -} - /* * dma_maps_sg_attrs returns 0 on error and > 0 on success. * It should never return a value < 0. @@ -363,25 +350,6 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg ops->unmap_sg(dev, sg, nents, dir, attrs); } -static inline dma_addr_t dma_map_page_attrs(struct device *dev, - struct page *page, - size_t offset, size_t size, - enum dma_data_direction dir, - unsigned long attrs) -{ - const struct dma_map_ops *ops = get_dma_ops(dev); - dma_addr_t addr; - - BUG_ON(!valid_dma_direction(dir)); - if (dma_is_direct(ops)) - addr = dma_direct_map_page(dev, page, offset, size, dir, attrs); - else - addr = ops->map_page(dev, page, offset, size, dir, attrs); - debug_dma_map_page(dev, page, offset, size, dir, addr, false); - - return addr; -} - static inline dma_addr_t dma_map_resource(struct device *dev, phys_addr_t phys_addr, size_t size, @@ -488,6 +456,19 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, } +static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr, + size_t size, enum dma_data_direction dir, unsigned long attrs) +{ + return dma_map_page_attrs(dev, virt_to_page(ptr), offset_in_page(ptr), + size, dir, attrs); +} + +static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr, + size_t size, enum dma_data_direction dir, unsigned long attrs) +{ + return dma_unmap_page_attrs(dev, addr, size, dir, attrs); +} + #define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0) #define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0) #define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0)