]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
soundwire: stream: sdw_stream_remove_slave(): Check stream is valid
authorRichard Fitzgerald <rf@opensource.cirrus.com>
Thu, 30 Apr 2026 14:33:53 +0000 (15:33 +0100)
committerVinod Koul <vkoul@kernel.org>
Sun, 3 May 2026 16:27:43 +0000 (21:57 +0530)
In sdw_stream_remove_slave() check that stream is a valid pointer
before passing it to functions that dereference it. Return 0 if the
pointer is invalid.

This is a convenience for callers. They can safely call this function
during cleanup code without needing a pointer validity check duplicated
at every call point.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.dev>
Link: https://patch.msgid.link/20260430143353.2702714-1-rf@opensource.cirrus.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/stream.c

index 4ed8fb7663ad40cef67a07710a00401ab4b0271c..c1ef177a00217abef9a6c969b88911fd9412ba1d 100644 (file)
@@ -2229,11 +2229,15 @@ EXPORT_SYMBOL(sdw_stream_add_slave);
  * @slave: SDW Slave instance
  * @stream: SoundWire stream
  *
- * This removes and frees port_rt and slave_rt from a stream
+ * This removes and frees port_rt and slave_rt from a stream.
+ * If stream is NULL or an ERR_PTR, do nothing and return 0.
  */
 int sdw_stream_remove_slave(struct sdw_slave *slave,
                            struct sdw_stream_runtime *stream)
 {
+       if (IS_ERR_OR_NULL(stream))
+               return 0;
+
        mutex_lock(&slave->bus->bus_lock);
 
        sdw_slave_port_free(slave, stream);