From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F50EFA373D for ; Thu, 27 Oct 2022 06:39:14 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Mybcc3G6Jz3byZ for ; Thu, 27 Oct 2022 17:39:12 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=LzHkFzDw; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KD4RglaC; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.220.28; helo=smtp-out1.suse.de; envelope-from=tiwai@suse.de; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=LzHkFzDw; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KD4RglaC; dkim-atps=neutral Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MybbZ0nzcz2xbK for ; Thu, 27 Oct 2022 17:38:17 +1100 (AEDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 09366229AD; Thu, 27 Oct 2022 06:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666852692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HAfG3fxO5nB+zy7DQ0VrMelHumsdPtpgcNkAR3o65r8=; b=LzHkFzDwVTwUrl9FtPI+xSP5wcd2kRNmIXOpJsdcR82Mb5UjzIkBYUGeoLuhPhKEnKZEGq lhzN6Fpx8BTnYj7mAnrjCZ82weDRIbTKrnp9+zM1xETwP7rDpdHH9U65waepala6ktSm8e NjFso6fM+dvKKnkp+MAhJaY7Xd7gOuM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666852692; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=HAfG3fxO5nB+zy7DQ0VrMelHumsdPtpgcNkAR3o65r8=; b=KD4RglaCNmhEIG8W5X8Gdl9J7rH5TgzeD/dlaCBNR5//iBOUWXRCxn45l7yfq3mIRLm+qU uV0PA56KIIjCUcCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DCA3D134CA; Thu, 27 Oct 2022 06:38:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +SpONVMnWmM8EAAAMHmgww (envelope-from ); Thu, 27 Oct 2022 06:38:11 +0000 Date: Thu, 27 Oct 2022 08:38:11 +0200 Message-ID: <87r0ytojos.wl-tiwai@suse.de> From: Takashi Iwai To: Yang Yingliang Subject: Re: [PATCH] ALSA: aoa: i2sbus: fix possible memory leak in i2sbus_add_dev() In-Reply-To: <20221027013438.991920-1-yangyingliang@huawei.com> References: <20221027013438.991920-1-yangyingliang@huawei.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, tiwai@suse.com, linuxppc-dev@lists.ozlabs.org, johannes@sipsolutions.net, perex@perex.cz Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, 27 Oct 2022 03:34:38 +0200, Yang Yingliang wrote: > > dev_set_name() in soundbus_add_one() allocates memory for name, it need be > freed when of_device_register() fails, call soundbus_dev_put() to give up > the reference that hold in device_initialize(), so that it can be freed in > kobject_cleanup() when the refcount hit to 0. And other resources are also > freed in i2sbus_release_dev(), so it can return 0 directly. > > Fixes: f3d9478b2ce4 ("[ALSA] snd-aoa: add snd-aoa") > Signed-off-by: Yang Yingliang The check of kobj state is awkward, but it seems to be the simplest way... Applied now. Thanks! Takashi > --- > sound/aoa/soundbus/i2sbus/core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c > index faf6b03131ee..f6841daf9e3b 100644 > --- a/sound/aoa/soundbus/i2sbus/core.c > +++ b/sound/aoa/soundbus/i2sbus/core.c > @@ -302,6 +302,10 @@ static int i2sbus_add_dev(struct macio_dev *macio, > > if (soundbus_add_one(&dev->sound)) { > printk(KERN_DEBUG "i2sbus: device registration error!\n"); > + if (dev->sound.ofdev.dev.kobj.state_initialized) { > + soundbus_dev_put(&dev->sound); > + return 0; > + } > goto err; > } > > -- > 2.25.1 >