From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385011; b=jWZiYgn1NbGvqy5dJKq/b/usH00GdwLz5iVIwEON583Vx0KxC+U6n/OYAZ7I/6Kp8hhR stIcI3dxNbmlmw7bmXZ0Gyn4iOubwIvXVoX17TcaC9hxWHQ6h0cmqctzldYu5qYGDDfu1 3VMYSkCb/CZKygUPMcACkdt2BiitWbv/UHWAY7K0ECFEoJMxgTTHpmW1psOMzv21c9CWo oGNMDhEUTPzLxrWGwj196lYA7db+p4hg2o45NmDUieIMGCs4Vpv8Mgnb7p4f5iFQy9sk7 uVlSKOqwG4b2r4st5zzN/0z0Nt2Q1QxUAWrfWG811LjAoex+R5qppiVbOh2YFBodvsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385011; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=wfZtmWjwyJk89oA2eaitrbVgLLeM8xXYXjyk/cXd/J8=; b=t1akHclRiguJoXuVfXoyK38d8GdCtcYoibLs8xgXb6E9MPZNIlFaR8aRNwe3fE36qTwq u5fdhWQPD8SYvCacenlkWMLWmVbD+mRISa0Hws7hLCHQ0UaXF1onATsBzt2bGSllm9gkW v1dGaIoV+OarZLJnrrQGJQUhfnLhgiTkcqCl2VRpW7aK7WrthBoLj8oMAXAmEipDneqZs 252ByBGC7yoohiIUCbIogQKoj1dZJlIJcS3xYpJh51zRS3Ic35W/K5YBwdK3+/4jPb3UQ qgjmt/HHXvRnrgAxT2qkDJ7KMov4PnapiWa1PUcQoymXsaeY0Ka7Gaux67dwxJyjF0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vgicqWCO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C2F6606A337; Fri, 4 Dec 2026 11:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vgicqWCO Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6C811F00A06; Fri, 4 Dec 2026 11:50:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385011; bh=wfZtmWjwyJk89oA2eaitrbVgLLeM8xXYXjyk/cXd/J8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vgicqWCOyPSFEjL+eI4lrZc8ouLx93nxGJ8vd+U7r4User0lv2TPSYhmxrH97Hkh9 EJK3su5P2+9A1ibCkpHOp75jpdmxpCsUj5bCnjbgubpc/1d1/iAhKjJ8ter0OULNBi bLcdskpwkyu2xQ2kA+FSSV3DtrB+WqqTg+wQfmmI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Takashi Iwai , Sasha Levin Subject: [PATCH 6.6 0384/1167] ALSA: pcmtest: Fix leak at probe error Date: Fri, 4 Dec 2026 18:56:51 +0900 Message-ID: <20261204100712.024186074@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai [ Upstream commit d0f2ca62e89f3c666d0ec203eaa23b8d965e5443 ] When an error happens at probe of pcmtest driver before snd_card_register() succeeds, we have to release the card explicitly, but it's not done, leading to a potential memory leak. Also, pcmtest driver manages struct pcmtst object unnecessarily complicatedly by a dynamic allocation and release. This patch fixes and cleans up the resource management: - Use card's private_data allocation for struct sndpcmtst at the card creation, which is released automatically together with the card - Since the allocation of pcmtest is gone, snd_pcmtst_create() is rather pointless, so just directly calling snd_pcmtst_new_pcm() - Use the new auto-clean mechanism to handle the error case at probe. - Many release handlers became superfluous and dropped In the end we got a good amount of code reduction. Fixes: 315a3d57c64c ("ALSA: Implement the new Virtual PCM Test Driver") Reported-by: Sashiko Signed-off-by: Takashi Iwai Link: https://patch.msgid.link/20261007172533.14667-3-tiwai@suse.de [ sashal: adjusted context for older APIs: the deleted kzalloc() in snd_pcmtst_create() and the removed .remove_new field in the platform driver, in place of kzalloc_obj() and .remove. ] Signed-off-by: Sasha Levin --- sound/drivers/pcmtest.c | 66 +++++++---------------------------------- 1 file changed, 10 insertions(+), 56 deletions(-) diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c index ac4a3149601ec..6b237d8274897 100644 --- a/sound/drivers/pcmtest.c +++ b/sound/drivers/pcmtest.c @@ -463,20 +463,6 @@ static snd_pcm_uframes_t snd_pcmtst_pcm_pointer(struct snd_pcm_substream *substr return bytes_to_frames(substream->runtime, v_iter->buf_pos); } -static int snd_pcmtst_free(struct pcmtst *pcmtst) -{ - if (!pcmtst) - return 0; - kfree(pcmtst); - return 0; -} - -// These callbacks are required, but empty - all freeing occurs in pdev_remove -static int snd_pcmtst_dev_free(struct snd_device *device) -{ - return 0; -} - static void pcmtst_pdev_release(struct device *dev) { } @@ -580,40 +566,9 @@ static int snd_pcmtst_new_pcm(struct pcmtst *pcmtst) return err; } -static int snd_pcmtst_create(struct snd_card *card, struct platform_device *pdev, - struct pcmtst **r_pcmtst) -{ - struct pcmtst *pcmtst; - int err; - static const struct snd_device_ops ops = { - .dev_free = snd_pcmtst_dev_free, - }; - - pcmtst = kzalloc(sizeof(*pcmtst), GFP_KERNEL); - if (!pcmtst) - return -ENOMEM; - pcmtst->card = card; - pcmtst->pdev = pdev; - - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, pcmtst, &ops); - if (err < 0) - goto _err_free_chip; - - err = snd_pcmtst_new_pcm(pcmtst); - if (err < 0) - goto _err_free_chip; - - *r_pcmtst = pcmtst; - return 0; - -_err_free_chip: - snd_pcmtst_free(pcmtst); - return err; -} - static int pcmtst_probe(struct platform_device *pdev) { - struct snd_card *card; + struct snd_card *card __free(snd_card_free) = NULL; struct pcmtst *pcmtst; int err; @@ -621,10 +576,16 @@ static int pcmtst_probe(struct platform_device *pdev) if (err) return err; - err = snd_devm_card_new(&pdev->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pdev->dev, index, id, THIS_MODULE, + sizeof(*pcmtst), &card); if (err < 0) return err; - err = snd_pcmtst_create(card, pdev, &pcmtst); + + pcmtst = card->private_data; + pcmtst->card = card; + pcmtst->pdev = pdev; + + err = snd_pcmtst_new_pcm(pcmtst); if (err < 0) return err; @@ -637,17 +598,11 @@ static int pcmtst_probe(struct platform_device *pdev) return err; platform_set_drvdata(pdev, pcmtst); + card = NULL; /* probe succeeded, don't release as error */ return 0; } -static void pdev_remove(struct platform_device *pdev) -{ - struct pcmtst *pcmtst = platform_get_drvdata(pdev); - - snd_pcmtst_free(pcmtst); -} - static struct platform_device pcmtst_pdev = { .name = "pcmtest", .dev.release = pcmtst_pdev_release, @@ -655,7 +610,6 @@ static struct platform_device pcmtst_pdev = { static struct platform_driver pcmtst_pdrv = { .probe = pcmtst_probe, - .remove_new = pdev_remove, .driver = { .name = "pcmtest", }, -- 2.53.0