From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753808AbdIDPTs (ORCPT ); Mon, 4 Sep 2017 11:19:48 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33680 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753658AbdIDPTr (ORCPT ); Mon, 4 Sep 2017 11:19:47 -0400 X-Google-Smtp-Source: ADKCNb4+IykhTedxnP42+/+HcE2/aoJ1XErLmqdjYF/qjniEZfoNqSvJBXN89U0j/r0PGtPjnRbcQw== Date: Mon, 4 Sep 2017 23:17:09 +0800 From: Wang YanQing To: tiwai@suse.de Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ALSA: hda: Fix forget to free resource in error handling code path in hda_codec_driver_probe Message-ID: <20170904151709.GA19742@udknight> Mail-Followup-To: Wang YanQing , tiwai@suse.de, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When hda_codec_driver_probe meet error and return failure, we need to free resource with patch_ops.free, or we will get resource leak. Signed-off-by: Wang YanQing --- Changes v1-v2: 1: Fix calling patch_ops.free after module_put, reported by Takashi Iwai. Hi! Takashi Iwai Because the only one calling site of patch_ops.free is in hda_codec_driver_remove, and if hda_codec_driver_probe return failure, we will no chance to call the hda_codec_driver_remove, so I think we don't need to care below case: "Or, for safety, we may put an internal flag to indicate that the codec free got already called, and check it at before calling patch_ops.free, too." Thanks! sound/pci/hda/hda_bind.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 6efadbf..d361bb7 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -100,7 +100,7 @@ static int hda_codec_driver_probe(struct device *dev) if (patch) { err = patch(codec); if (err < 0) - goto error_module; + goto error_module_put; } err = snd_hda_codec_build_pcms(codec); @@ -120,6 +120,9 @@ static int hda_codec_driver_probe(struct device *dev) return 0; error_module: + if (codec->patch_ops.free) + codec->patch_ops.free(codec); + error_module_put: module_put(owner); error: -- 1.8.5.6.2.g3d8a54e.dirty