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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 BDF9FC38A2D for ; Mon, 24 Oct 2022 14:05:20 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C73F17410; Mon, 24 Oct 2022 16:04:28 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C73F17410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1666620318; bh=f+j3Dm6Dsf6l61MU4fSlRirttep5qPT12IBzNs5XB94=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=hi/wqKWwTel5YrGICCY9IFZNmO6rp7Mov7/VeB7VSpikUbArLioU85ycvsHRureKA i+PMSTnRW3FAhnGVsMMKp6W1ONoVLqVKZEgyxwhO3/UAHKwh6wz4FczTiuaKUeOSXi xs1XNKGIaFDiOmTWeXraSCaxdc77xpasNv0ZLP4Y= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 6EE45F80533; Mon, 24 Oct 2022 16:04:28 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D65DCF8053D; Mon, 24 Oct 2022 16:04:26 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D306FF80240 for ; Mon, 24 Oct 2022 16:04:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D306FF80240 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="NF5mdkdl"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="US14vegp" 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-out2.suse.de (Postfix) with ESMTPS id 469181FD59; Mon, 24 Oct 2022 14:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1666620260; 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=Qaq9WInof3zmvpJCEWXSq0S+lrAq7e87Op2R9pRdblM=; b=NF5mdkdlnbh6A6YAdscChKAVCtW35Uj8T6CEDD2JfvSWuxxGrr+yXS1zLCpdfuP82jFCtc Nv+JbMW6BvqE0vjI25Qxp27wyXgKiAlZ+fwM0N73403iywyLLrLu+esA/+zIpDToUPC1ln HYLBAlmaeeBIlWTCAmSMaIArz/UIaHY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1666620260; 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=Qaq9WInof3zmvpJCEWXSq0S+lrAq7e87Op2R9pRdblM=; b=US14vegpHlV9SsjBrETQNhKDk9/IFqXxxQwRvzuvpFxq5nQdA5RN5GGDiEUY/torDO4Dec g0+iJU4y2LV9ctDA== 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 23F3E13357; Mon, 24 Oct 2022 14:04:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2W/0B2SbVmPlEgAAMHmgww (envelope-from ); Mon, 24 Oct 2022 14:04:20 +0000 Date: Mon, 24 Oct 2022 16:04:19 +0200 Message-ID: <87edux8gik.wl-tiwai@suse.de> From: Takashi Iwai To: Yang Yingliang Subject: Re: [PATCH] ALSA: hda: fix possible memory leak in azx_codec_configure() In-Reply-To: <20221024122646.1175390-1-yangyingliang@huawei.com> References: <20221024122646.1175390-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 Cc: alsa-devel@alsa-project.org, tiwai@suse.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Mon, 24 Oct 2022 14:26:46 +0200, Yang Yingliang wrote: > > If the codec device is registered, after calling snd_hdac_device_unregister(), > codec has already been removed from chip bus, it should call put_device() to > give up reference to free codec and device name. > > Fixes: c0f1886de7e1 ("ALSA: hda: intel: Allow repeatedly probing on codec configuration errors") > Signed-off-by: Yang Yingliang Hrm, are you sure that this will result in a memory leak? put_device() is called at snd_hda_codec_unregister() that is invoked via dev_free callback of the snd_hda_codec object -- which is called when the top-level driver is removed. I'm afraid that your patch will lead to a double-free. thanks, Takashi > --- > sound/pci/hda/hda_controller.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c > index 0ff286b7b66b..f6a73ce300a4 100644 > --- a/sound/pci/hda/hda_controller.c > +++ b/sound/pci/hda/hda_controller.c > @@ -1257,8 +1257,11 @@ int azx_codec_configure(struct azx *chip) > /* unregister failed codecs if any codec has been probed */ > list_for_each_codec_safe(codec, next, &chip->bus) { > if (!codec->configured) { > + bool is_registered = device_is_registered(&codec->core.dev); > codec_err(codec, "Unable to configure, disabling\n"); > snd_hdac_device_unregister(&codec->core); > + if (is_registered) > + put_device(&codec->core.dev); > } > } > } > -- > 2.25.1 >