Skip to contentSkip to conversation

soundwire: stream: sdw_stream_remove_slave(): Check stream is valid

PATCH Applied Richard Fitzgerald 3 participants 3 messages Apr 30 – May 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soundwire: stream: sdw_stream_remove_slave(): Check stream is valid

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.

---
 drivers/soundwire/stream.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soundwire/stream.c +5 -1
index 4ed8fb7663ad..c1ef177a0021 100644
@@ -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);
Signature · 1 line
2.47.3
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Richard Fitzgerald

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.

LGTM

Quoted 25 lines
---
 drivers/soundwire/stream.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/soundwire/stream.c +5 -1
index 4ed8fb7663ad..c1ef177a0021 100644
@@ -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);
maintainer Applied
#2 lore raw
In reply to Richard Fitzgerald
Quoted 9 lines · Richard Fitzgerald

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.

[...]

Applied, thanks!

[1/1] soundwire: stream: sdw_stream_remove_slave(): Check stream is valid

      commit: 9a0afdd19a01c6edddb92eb6a464f9e99d946b90

Best regards,

Signature · 1 line
~Vinod