alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] soundwire: stream: add s_rt into slave_rt_list before sdw_config_stream
@ 2021-07-22 10:56 Dongliang Mu
  2021-07-22 11:16 ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Dongliang Mu @ 2021-07-22 10:56 UTC (permalink / raw)
  To: Vinod Koul, Bard Liao, Pierre-Louis Bossart, Sanyog Kale
  Cc: alsa-devel, Dongliang Mu, dan.carpenter, linux-kernel

The commit 48f17f96a817 ("soundwire: stream: fix memory leak in stream
config error path") fixes the memory leak by implicitly freeing the s_rt
object. However, this fixing style is not very good.

The better fix is to move list_add_tail before sdw_config_stream and
revert the previous commit.

Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 drivers/soundwire/stream.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
index 1a18308f4ef4..66a4ce4f923f 100644
--- a/drivers/soundwire/stream.c
+++ b/drivers/soundwire/stream.c
@@ -1373,19 +1373,11 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
 		goto stream_error;
 	}
 
+	list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list);
+
 	ret = sdw_config_stream(&slave->dev, stream, stream_config, true);
-	if (ret) {
-		/*
-		 * sdw_release_master_stream will release s_rt in slave_rt_list in
-		 * stream_error case, but s_rt is only added to slave_rt_list
-		 * when sdw_config_stream is successful, so free s_rt explicitly
-		 * when sdw_config_stream is failed.
-		 */
-		kfree(s_rt);
+	if (ret)
 		goto stream_error;
-	}
-
-	list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list);
 
 	ret = sdw_slave_port_config(slave, s_rt, port_config, num_ports);
 	if (ret)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] soundwire: stream: add s_rt into slave_rt_list before sdw_config_stream
  2021-07-22 10:56 [PATCH] soundwire: stream: add s_rt into slave_rt_list before sdw_config_stream Dongliang Mu
@ 2021-07-22 11:16 ` Dan Carpenter
  2021-07-22 11:24   ` Dongliang Mu
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-07-22 11:16 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: alsa-devel, Pierre-Louis Bossart, linux-kernel, Vinod Koul,
	Sanyog Kale, Bard Liao

On Thu, Jul 22, 2021 at 06:56:11PM +0800, Dongliang Mu wrote:
> The commit 48f17f96a817 ("soundwire: stream: fix memory leak in stream
> config error path") fixes the memory leak by implicitly freeing the s_rt
> object. However, this fixing style is not very good.
> 
> The better fix is to move list_add_tail before sdw_config_stream and
> revert the previous commit.
> 
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> ---
>  drivers/soundwire/stream.c | 14 +++-----------
>  1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> index 1a18308f4ef4..66a4ce4f923f 100644
> --- a/drivers/soundwire/stream.c
> +++ b/drivers/soundwire/stream.c
> @@ -1373,19 +1373,11 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
>  		goto stream_error;
>  	}
>  
> +	list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list);
> +
>  	ret = sdw_config_stream(&slave->dev, stream, stream_config, true);

There some sanity checks on the stream inside sdw_config_stream() so
that's probably why we didn't add it until later.  (I don't know the
code well, but that's what I would suspect from a glance).

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soundwire: stream: add s_rt into slave_rt_list before sdw_config_stream
  2021-07-22 11:16 ` Dan Carpenter
@ 2021-07-22 11:24   ` Dongliang Mu
  2021-07-22 11:36     ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Dongliang Mu @ 2021-07-22 11:24 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: alsa-devel, Pierre-Louis Bossart, linux-kernel, Vinod Koul,
	Sanyog Kale, Bard Liao

On Thu, Jul 22, 2021 at 7:17 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Thu, Jul 22, 2021 at 06:56:11PM +0800, Dongliang Mu wrote:
> > The commit 48f17f96a817 ("soundwire: stream: fix memory leak in stream
> > config error path") fixes the memory leak by implicitly freeing the s_rt
> > object. However, this fixing style is not very good.
> >
> > The better fix is to move list_add_tail before sdw_config_stream and
> > revert the previous commit.
> >
> > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > ---
> >  drivers/soundwire/stream.c | 14 +++-----------
> >  1 file changed, 3 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> > index 1a18308f4ef4..66a4ce4f923f 100644
> > --- a/drivers/soundwire/stream.c
> > +++ b/drivers/soundwire/stream.c
> > @@ -1373,19 +1373,11 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
> >               goto stream_error;
> >       }
> >
> > +     list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list);
> > +
> >       ret = sdw_config_stream(&slave->dev, stream, stream_config, true);
>
> There some sanity checks on the stream inside sdw_config_stream() so
> that's probably why we didn't add it until later.  (I don't know the
> code well, but that's what I would suspect from a glance).

I think those sanity checks are not much related to list_add_tail.

Except that, do you have other concerns?

I think this patch could improve the readability of code, so I submit
this patch to the mailing list. But I am not sure if the community
favors this kind of patch.

>
> regards,
> dan carpenter
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] soundwire: stream: add s_rt into slave_rt_list before sdw_config_stream
  2021-07-22 11:24   ` Dongliang Mu
@ 2021-07-22 11:36     ` Dan Carpenter
  0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-07-22 11:36 UTC (permalink / raw)
  To: Dongliang Mu
  Cc: alsa-devel, Pierre-Louis Bossart, linux-kernel, Vinod Koul,
	Sanyog Kale, Bard Liao

On Thu, Jul 22, 2021 at 07:24:16PM +0800, Dongliang Mu wrote:
> On Thu, Jul 22, 2021 at 7:17 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Thu, Jul 22, 2021 at 06:56:11PM +0800, Dongliang Mu wrote:
> > > The commit 48f17f96a817 ("soundwire: stream: fix memory leak in stream
> > > config error path") fixes the memory leak by implicitly freeing the s_rt
> > > object. However, this fixing style is not very good.
> > >
> > > The better fix is to move list_add_tail before sdw_config_stream and
> > > revert the previous commit.
> > >
> > > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
> > > ---
> > >  drivers/soundwire/stream.c | 14 +++-----------
> > >  1 file changed, 3 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c
> > > index 1a18308f4ef4..66a4ce4f923f 100644
> > > --- a/drivers/soundwire/stream.c
> > > +++ b/drivers/soundwire/stream.c
> > > @@ -1373,19 +1373,11 @@ int sdw_stream_add_slave(struct sdw_slave *slave,
> > >               goto stream_error;
> > >       }
> > >
> > > +     list_add_tail(&s_rt->m_rt_node, &m_rt->slave_rt_list);
> > > +
> > >       ret = sdw_config_stream(&slave->dev, stream, stream_config, true);
> >
> > There some sanity checks on the stream inside sdw_config_stream() so
> > that's probably why we didn't add it until later.  (I don't know the
> > code well, but that's what I would suspect from a glance).
> 
> I think those sanity checks are not much related to list_add_tail.

Yeah.  I can't point to a bug that it causes, it just feels ugly to add
invalid data to the list.

You didn't add Rander to the CC list and he may have had a good reason
to do it that way.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-07-22 11:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-22 10:56 [PATCH] soundwire: stream: add s_rt into slave_rt_list before sdw_config_stream Dongliang Mu
2021-07-22 11:16 ` Dan Carpenter
2021-07-22 11:24   ` Dongliang Mu
2021-07-22 11:36     ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).