Received: by 10.192.165.148 with SMTP id m20csp318074imm; Tue, 24 Apr 2018 23:19:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+74eRDX09t3Dd4NVNTH8eHg7+/OCdLnZUj+s9og4jRvl5Su1O5z0qqgNkpNNAZ4Nolplvr X-Received: by 10.101.67.139 with SMTP id m11mr6730996pgp.153.1524637161617; Tue, 24 Apr 2018 23:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524637161; cv=none; d=google.com; s=arc-20160816; b=m0fb+vIxitAMkXU6pepKLSXDstr+dnHCWLg790dt3V+DXu6MIsDxs4thAj9c0ThBHS NtvVlI205OxA+2wq3kndfZ/Xgpr7C54HDWNgzzPve+UxQJQhXFeNCjWoqnwLjUmivCC0 iHwn9EeVur1Y+jddifkjRE75skx6KhMQ3OEG6RSk4FQwRLO/cPou6HFDqgAoetm4Z6iP xO1VQguNt9HiqqVo080oGFhCWYY6z2MWndc9DYvvSbpfXejvnE9BhEM3hHNQT2VcV1Te tCN2ibS2UVKcA+Zgo/FIh+k6fLCEEBLSgHW8pwdM6YWeUQNi8Mbq3cID+/Tfaje0YlyC dhwA== 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:arc-authentication-results; bh=JsLQkwdl32Ki8+6E0IuAvkmYQHpBReCa4U2jtEXFiGM=; b=mDCkVgnvIJ8un34SlcN0Vvq0Ed/CUB/zYI1VDMEiwil4BzNnP8ST8/EZS0GIZZfEsb Jp88MCjH8NwB5Kf1vaa+kkTY2LK93CQlYsYUNkCHlhUM7WqFrZNUa2fKnRWKQU/53Ur6 PSGUPkJSzZaivLIvMLFks7JFomP0Pdbjihy+68XH7QQi1rPj1iqkONkYIcskoxMHnpQ1 55Yuft0jb8/ncrekDQU+OmhfqW6CyDwt5sIjrdP422d584X4BgQHIUCmUvBnd8pqNuN7 pV2XPOAguXl0T5CV/7NjM9X/QIuCJyvMEj3jl6BsbACFEpC/BaSpj9UwTtOY7As/hKKb hSOA== 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 u10si12823928pgp.45.2018.04.24.23.19.07; Tue, 24 Apr 2018 23:19:21 -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 S1751414AbeDYGQt (ORCPT + 99 others); Wed, 25 Apr 2018 02:16:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60258 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750949AbeDYGQp (ORCPT ); Wed, 25 Apr 2018 02:16:45 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 37F3E2D; Wed, 25 Apr 2018 06:16:44 +0000 (UTC) Date: Wed, 25 Apr 2018 08:16:38 +0200 From: Greg Kroah-Hartman To: Kirill Marinushkin Cc: Eric Anholt , Stefan Wahren , Florian Fainelli , Ray Jui , Scott Branden , Andy Shevchenko , Dan Carpenter , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit() Message-ID: <20180425061638.GA1450@kroah.com> References: <9e4fc4a0-370b-9101-2809-4040de58553c@gmail.com> <20180424195729.8433-1-k.marinushkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180424195729.8433-1-k.marinushkin@gmail.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 24, 2018 at 09:57:29PM +0200, Kirill Marinushkin wrote: > In the current implementation, vchi_instance is inited during the first > call of bcm2835_audio_open_connection(), and is never freed. It causes a > memory leak when the module `snd_bcm2835` is removed. > > Here is how this commit fixes it: > > * the VCHI context (including vchi_instance) is created once in the > platform's devres > * the VCHI context is allocated and connected once during module_init() > * all created bcm2835_chips have a pointer to this VCHI context > * bcm2835_audio_open_connection() can access the VCHI context through the > associated bcm2835_chip > * the VCHI context is disconnected and freed once during module_exit() > > After this commit is applied, I don't see other issues with the module's > init/exit, so I also remove the associated TODO task. > > Steps to reproduce the memory leak before this commit: > > ~~~~ > root@raspberrypi:/home/pi# aplay test0.wav > Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster > ^CAborted by signal Interrupt... > root@raspberrypi:/home/pi# rmmod snd_bcm2835 > root@raspberrypi:/home/pi# modprobe snd_bcm2835 > root@raspberrypi:/home/pi# aplay test0.wav > Playing WAVE 'test0.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Ster > ^CAborted by signal Interrupt... > root@raspberrypi:/home/pi# echo scan > /sys/kernel/debug/kmemleak > root@raspberrypi:/home/pi# cat /sys/kernel/debug/kmemleak > unreferenced object 0xb6794c00 (size 128): > comm "aplay", pid 406, jiffies 36870 (age 116.650s) > hex dump (first 32 bytes): > 08 a5 82 81 01 00 00 00 08 4c 79 b6 08 4c 79 b6 .........Ly..Ly. > 00 00 00 00 00 00 00 00 ad 4e ad de ff ff ff ff .........N...... > backtrace: > [<802af5e0>] kmem_cache_alloc_trace+0x294/0x3d0 > [<806ce620>] vchiq_initialise+0x98/0x1b0 > [<806d0b34>] vchi_initialise+0x24/0x34 > [<7f1311ec>] 0x7f1311ec > [<7f1303bc>] 0x7f1303bc > [<7f130590>] 0x7f130590 > [<7f111fd8>] snd_pcm_open_substream+0x68/0xc4 [snd_pcm] > [<7f112108>] snd_pcm_open+0xd4/0x248 [snd_pcm] > [<7f112334>] snd_pcm_playback_open+0x4c/0x6c [snd_pcm] > [<7f0e250c>] snd_open+0xa8/0x14c [snd] > [<802ce590>] chrdev_open+0xac/0x188 > [<802c57b4>] do_dentry_open+0x10c/0x314 > [<802c6ba8>] vfs_open+0x5c/0x88 > [<802d9a68>] path_openat+0x368/0x944 > [<802dacd4>] do_filp_open+0x70/0xc4 > [<802c6f70>] do_sys_open+0x110/0x1d4 > ~~~~ > > Signed-off-by: Kirill Marinushkin > Cc: Eric Anholt > Cc: Stefan Wahren > Cc: Greg Kroah-Hartman > Cc: Florian Fainelli > Cc: Ray Jui > Cc: Scott Branden > Cc: Andy Shevchenko > Cc: Dan Carpenter > Cc: bcm-kernel-feedback-list@broadcom.com > Cc: linux-rpi-kernel@lists.infradead.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: devel@driverdev.osuosl.org > Cc: linux-kernel@vger.kernel.org > --- > .../vc04_services/bcm2835-audio/bcm2835-vchiq.c | 64 +++++++++++++--------- > .../staging/vc04_services/bcm2835-audio/bcm2835.c | 43 ++++++++++++++- > .../staging/vc04_services/bcm2835-audio/bcm2835.h | 12 ++++ > 3 files changed, 91 insertions(+), 28 deletions(-) What changed from v1? Always put that below the --- line as the documentation says to do so. v3? :) thanks, greg k-h