Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753921AbdFNAQU (ORCPT ); Tue, 13 Jun 2017 20:16:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45384 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752259AbdFNAQT (ORCPT ); Tue, 13 Jun 2017 20:16:19 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9812520B1A Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mchristi@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9812520B1A Subject: Re: [PATCH 1/1] uio: Fix uio_device memory leak To: Greg KH References: <1496866004-32328-1-git-send-email-mchristi@redhat.com> <20170613140146.GA29175@kroah.com> Cc: manish.rangankar@cavium.com, target-devel@vger.kernel.org, nab@linux-iscsi.org, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, mst@redhat.com, linux-kernel@vger.kernel.org From: Mike Christie Message-ID: <5940804E.1060000@redhat.com> Date: Tue, 13 Jun 2017 19:16:14 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <20170613140146.GA29175@kroah.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 14 Jun 2017 00:16:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1105 Lines: 27 On 06/13/2017 09:01 AM, Greg KH wrote: > On Wed, Jun 07, 2017 at 03:06:44PM -0500, Mike Christie wrote: >> It looks like there might be 2 issues with the uio_device allocation, or it >> looks like we are leaking the device for possibly a specific type of device >> case that I could not find but one of you may know about. >> >> Issues: >> 1. We use devm_kzalloc to allocate the uio_device, but the release >> function, devm_kmalloc_release, is just a noop, so the memory is never freed. > > What do you mean by this? If the release function is a noop, lots of > memory in the kernel is leaking. UIO shouldn't have to do anything > special here, is the devm api somehow broken? Sorry. I misdiagnosed the problem. It's a noop, but we did kfree on the entire devres and its data later. The problem I was hitting is that memory is not freed until the parent is removed. __uio_register_device does: idev = devm_kzalloc(parent, sizeof(*idev), GFP_KERNEL); if (!idev) { return -ENOMEM; } so the devres's memory is associated with the parent. Is that intentional?