Skip to content

soundwire: intel: fix memory leak with stream name - #1795

Merged
plbossart merged 1 commit into
thesofproject:topic/sof-devfrom
plbossart:sdw/fix_stream_name_memleak
Feb 18, 2020
Merged

soundwire: intel: fix memory leak with stream name#1795
plbossart merged 1 commit into
thesofproject:topic/sof-devfrom
plbossart:sdw/fix_stream_name_memleak

Conversation

@plbossart

Copy link
Copy Markdown
Member

We free the stream name on errors but not in the regular case. Fix.

Signed-off-by: Pierre-Louis Bossart pierre-louis.bossart@linux.intel.com

We free the stream name on errors but not in the regular case. Fix.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Comment thread drivers/soundwire/intel.c

dma->hw_params = NULL;
dma->pdi = NULL;
kfree(dma->stream->name);

@lyakh lyakh Feb 18, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdw_release_stream() below just does a kfree(stream) so after it dma->stream contains an invalid pointer. Does the dma object get freed after that too? If not, maybe it would be good to set dma->stream = NULL; after calling sdw_release_stream()? In fact, I see that dma gets freed in intel_shutdown(). Both dma and name are allocated in sdw_stream_setup() so, maybe they should also be freed in one function, that's its counterpart? intel_hw_free() seems more like a counterpart to intel_prepare() and intel_hw_params() to me?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, @lyakh you raise a good point. startup() should be a pair with shutdown() and prepare() with hw_free(). So if you follow that, the stream (and the name) should not be free here, but rather in shutdown.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 'name' is not allocated as part of the stream allocation

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching up with how sdw stack works, but it seems to follow ASoC DAI ops semantics, the alloc/frees are not paired correctly.

Comment thread drivers/soundwire/intel.c

dma->hw_params = NULL;
dma->pdi = NULL;
kfree(dma->stream->name);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, @lyakh you raise a good point. startup() should be a pair with shutdown() and prepare() with hw_free(). So if you follow that, the stream (and the name) should not be free here, but rather in shutdown.

@plbossart

Copy link
Copy Markdown
Member Author

SOFCI TEST

@plbossart
plbossart merged commit 861c308 into thesofproject:topic/sof-dev Feb 18, 2020
oder-chiou pushed a commit to oder-chiou/linux-soundwire that referenced this pull request May 5, 2026
We do not use struct socket in unix_autobind() and pass struct sock to
unix_bind_bsd() and unix_bind_abstract().  Let's pass it to unix_autobind()
as well.

Also, this patch fixes these errors by checkpatch.pl.

  ERROR: do not use assignment in if condition
  thesofproject#1795: FILE: net/unix/af_unix.c:1795:
  +	if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr

  CHECK: Logical continuations should be on the previous line
  thesofproject#1796: FILE: net/unix/af_unix.c:1796:
  +	if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr
  +	    && (err = unix_autobind(sock)) != 0)

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants