Received: by 10.192.165.148 with SMTP id m20csp981140imm; Wed, 25 Apr 2018 10:36:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpA+Pfe0n5hej7V2hgj0YOOnF3t5TpPGkR31/dNVN4yOY2vjPdQb/8bthwbqXdCm1L19JQU X-Received: by 10.98.251.20 with SMTP id x20mr2608768pfm.48.1524677760169; Wed, 25 Apr 2018 10:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524677760; cv=none; d=google.com; s=arc-20160816; b=yD7tjWxy+Vlsv9B183wUXMhb7p4pC6wKomfBy5SUzgSgAmA7CFXqKT+TY3xOT3T8uX uxTkVCvelY/dxd4ZvBJrTMGaN0AyuGUfnt94Dq2otdABeCiVXRms8UkVlKVQoclKhonv spbYUhWX3dmoohdXihbnRQ0eiZJx6GKFTIIicUMIBOGkBl42wPpNuSMOKW5MZJt/Feal chA2jUQPcnfvZ2r1U0JYFBgkWUGuv0xLKAeFOKREkohp17jjulEuGzMQLkB6LLY7wKV1 L4BWJDXXBnq3sIwBpPpeuPWPDnmyeF6ZEQxx57ZQlLRILEYSvd28xf6KfnBKh25fh1r4 6B0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=6m6pEO3MZcHkJ/Mf5QyaahtD9Uw3cOF7WeyIWTXZzoA=; b=Oct+GV75BQTQJAqPUWOTtwEp7Jgxhe8GUwmZK57nFNjCKiHCNpHFEelyhGMjIGH1Ft issVFVW0MvsNW4NYLbGnZA5rgRwFoYQHPZ5+nwghvmx87H0pbB6vz4VhlpxahBGk18k1 trDHHQRgz0UFQfZnxTRf5e0gwPRB4KqC/gx+42+A8IF2EsefB98IhPTaHsKaw1l+gUJL zg/OFHM4MF4GlupXzthCFzWOY6aD41J27ilzyEsy9GV8VoOw5p2dmOO8/+j+BxfhXGeX 4NVyYGrZzxmFMhOXa3Zf4b8W4h9WOYt1NXuozh1+p/Y/WLwsH5BglI0atijDLwrpapyQ 1beA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mcozP/0O; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9-v6si6600627pll.393.2018.04.25.10.35.45; Wed, 25 Apr 2018 10:36:00 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mcozP/0O; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755382AbeDYReh (ORCPT + 99 others); Wed, 25 Apr 2018 13:34:37 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:46047 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754654AbeDYReg (ORCPT ); Wed, 25 Apr 2018 13:34:36 -0400 Received: by mail-wr0-f193.google.com with SMTP id p5-v6so26352673wre.12 for ; Wed, 25 Apr 2018 10:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=6m6pEO3MZcHkJ/Mf5QyaahtD9Uw3cOF7WeyIWTXZzoA=; b=mcozP/0OftNNqYtQhaJb7hUZAe6Cf8TEacPSUJkh6YCx/hxVe/LBqg/ItRk+8/ta2I dVVv4doygM4rL9AT/MXZv7lfsTPDOdutbxt20L8gXtAmAmysYlQPai3L4pq0DriOeQOH iLkiqQzoesBmlhXWDzxE8geJAepFwGtAFfWVD1aTSS/3cBBiXRbNGx1Zl2LjWf1WQUo4 /3wVqvYKoRxReZA31JIXw3SB73nYh+iRDinK8lxlCVWGTUgqLOXP9iYQYaE1LS1/fYCm yNrUdhNrLnqnpoF/lUM/KTvjbWkkaf22PNdoM4iMBoLO4gTcPtEj/FOM7oMo3O8VRZfU 2Vxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=6m6pEO3MZcHkJ/Mf5QyaahtD9Uw3cOF7WeyIWTXZzoA=; b=pZRQR1+dz1OAz/4eJltynNWqxUY4BB7ZK294+jUpYsp5pxuU0ROYpfw/plSRtxLkaP 3f0vM4S9NSnZ/aCewOyNV1kFMJbtO/f9h/mYb94U8Oo2LUyGW3ARX9XLlQY9sboSjADD +o4m1nceI6Rj+u6E1yJq6C4aGhILKmEB9qeeDf82tHDziKbO47qB33Tdrz6vjQ6jDCJx +FF94N85TJW645PMjG5QPvIJIhW0mF31HTs0e1fRH+DKWD4HFoGONYd0adyDkvKc0FHb P1XylaGoTeKhT+i8kE5rtKugazk0RETDn9BoSGoaedej4PfBU4XhaWKV2Z3qc3D1eIIo dnXg== X-Gm-Message-State: ALQs6tBh4CcPAT6ZyRF2fVNCyBwlewXXOGXTEy1barXKSPvTsP/4gape 1Xr6sFvxjvuT8VGyEn6NXL8= X-Received: by 2002:adf:bd01:: with SMTP id j1-v6mr17969063wrh.69.1524677674669; Wed, 25 Apr 2018 10:34:34 -0700 (PDT) Received: from [192.168.1.3] (x55b0b428.dyn.telefonica.de. [85.176.180.40]) by smtp.gmail.com with ESMTPSA id a129sm20201914wme.3.2018.04.25.10.34.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 10:34:33 -0700 (PDT) Subject: Re: [PATCH v2] staging: bcm2835-audio: Disconnect and free vchi_instance on module_exit() To: Greg Kroah-Hartman 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 References: <9e4fc4a0-370b-9101-2809-4040de58553c@gmail.com> <20180424195729.8433-1-k.marinushkin@gmail.com> <20180425061638.GA1450@kroah.com> From: Kirill Marinushkin Message-ID: Date: Wed, 25 Apr 2018 19:35:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20180425061638.GA1450@kroah.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/25/18 08:16, Greg Kroah-Hartman wrote: > 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 :) Below is the git diff v1..v2 ~~~~ diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c index 009c972d93d6..662e05bd8f05 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835.c @@ -165,7 +165,7 @@ static int snd_bcm2835_create(struct snd_card *card,                                      bcm2835_devm_free_vchi_ctx, NULL, NULL);         if (!chip->vchi_ctx) {                 kfree(chip); -               return err; +               return -ENODEV;         }           err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); ~~~~ Best Regards, Kirill