mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang YanQing <udknight@gmail.com>
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
Date: Mon, 4 Sep 2017 23:17:09 +0800	[thread overview]
Message-ID: <20170904151709.GA19742@udknight> (raw)

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 <udknight@gmail.com>
---
 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

             reply	other threads:[~2017-09-04 15:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-04 15:17 Wang YanQing [this message]
2017-09-04 15:34 ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170904151709.GA19742@udknight \
    --to=udknight@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome