From: Takashi Iwai <tiwai@suse.de> To: Yang Yingliang <yangyingliang@huawei.com> Cc: alsa-devel@alsa-project.org, tiwai@suse.com, linuxppc-dev@lists.ozlabs.org, johannes@sipsolutions.net Subject: Re: [PATCH] ALSA: aoa: i2sbus: fix possible memory leak in i2sbus_add_dev() Date: Thu, 27 Oct 2022 08:38:11 +0200 [thread overview] Message-ID: <87r0ytojos.wl-tiwai@suse.de> (raw) In-Reply-To: <20221027013438.991920-1-yangyingliang@huawei.com> 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 <yangyingliang@huawei.com> 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 >
WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de> To: Yang Yingliang <yangyingliang@huawei.com> Cc: alsa-devel@alsa-project.org, tiwai@suse.com, linuxppc-dev@lists.ozlabs.org, johannes@sipsolutions.net, perex@perex.cz Subject: Re: [PATCH] ALSA: aoa: i2sbus: fix possible memory leak in i2sbus_add_dev() Date: Thu, 27 Oct 2022 08:38:11 +0200 [thread overview] Message-ID: <87r0ytojos.wl-tiwai@suse.de> (raw) In-Reply-To: <20221027013438.991920-1-yangyingliang@huawei.com> 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 <yangyingliang@huawei.com> 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 >
next prev parent reply other threads:[~2022-10-27 6:39 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-27 1:34 [PATCH] ALSA: aoa: i2sbus: fix possible memory leak in i2sbus_add_dev() Yang Yingliang 2022-10-27 1:34 ` Yang Yingliang 2022-10-27 6:38 ` Takashi Iwai [this message] 2022-10-27 6:38 ` Takashi Iwai 2022-10-27 7:41 ` Yang Yingliang 2022-10-27 7:41 ` Yang Yingliang 2022-10-27 8:06 ` Takashi Iwai 2022-10-27 8:06 ` 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=87r0ytojos.wl-tiwai@suse.de \ --to=tiwai@suse.de \ --cc=alsa-devel@alsa-project.org \ --cc=johannes@sipsolutions.net \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=tiwai@suse.com \ --cc=yangyingliang@huawei.com \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.