android_kernel_motorola_sm6375/drivers/soundwire
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Tom Rix fe0278843b soundwire: fix double free of dangling pointer
[ Upstream commit 3fbbf2148a406b3e350fe91e6fdd78eb42ecad24 ]

clang static analysis flags this problem

stream.c:844:9: warning: Use of memory after
  it is freed
        kfree(bus->defer_msg.msg->buf);
              ^~~~~~~~~~~~~~~~~~~~~~~

This happens in an error handler cleaning up memory
allocated for elements in a list.

	list_for_each_entry(m_rt, &stream->master_list, stream_node) {
		bus = m_rt->bus;

		kfree(bus->defer_msg.msg->buf);
		kfree(bus->defer_msg.msg);
	}

And is triggered when the call to sdw_bank_switch() fails.
There are a two problems.

First, when sdw_bank_switch() fails, though it frees memory it
does not clear bus's reference 'defer_msg.msg' to that memory.

The second problem is the freeing msg->buf. In some cases
msg will be NULL so this will dereference a null pointer.
Need to check before freeing.

Fixes: 99b8a5d608 ("soundwire: Add bank switch routine")
Signed-off-by: Tom Rix <[email protected]>
Reviewed-by: Nick Desaulniers <[email protected]>
Reviewed-by: Pierre-Louis Bossart <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Vinod Koul <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
2020-09-17 13:47:43 +02:00
..
bus.c
bus.h
bus_type.c
cadence_master.c
cadence_master.h
debugfs.c
intel.c soundwire: intel: fix memory leak with devm_kasprintf 2020-07-22 09:33:00 +02:00
intel.h
intel_init.c
Kconfig
Makefile
mipi_disco.c
slave.c
stream.c soundwire: fix double free of dangling pointer 2020-09-17 13:47:43 +02:00