media: ir_toy: fix a memleak in irtoy_tx

Message ID 20240117081419.3819911-1-alexious@zju.edu.cn (mailing list archive)
State Accepted
Delegated to: Sean Young
Headers
Series media: ir_toy: fix a memleak in irtoy_tx |

Commit Message

Zhipeng Lu Jan. 17, 2024, 8:14 a.m. UTC
  When irtoy_command fails, buf should be freed since it is allocated by irtoy_tx.
Or there would be a memleak.

Fixes: 4114978dcd24 ("media: ir_toy: prevent device from hanging during transmit")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
---
 drivers/media/rc/ir_toy.c | 2 ++
 1 file changed, 2 insertions(+)
  

Patch

diff --git a/drivers/media/rc/ir_toy.c b/drivers/media/rc/ir_toy.c
index 196806709259..69e630d85262 100644
--- a/drivers/media/rc/ir_toy.c
+++ b/drivers/media/rc/ir_toy.c
@@ -332,6 +332,7 @@  static int irtoy_tx(struct rc_dev *rc, uint *txbuf, uint count)
 			    sizeof(COMMAND_SMODE_EXIT), STATE_COMMAND_NO_RESP);
 	if (err) {
 		dev_err(irtoy->dev, "exit sample mode: %d\n", err);
+		kfree(buf);
 		return err;
 	}
 
@@ -339,6 +340,7 @@  static int irtoy_tx(struct rc_dev *rc, uint *txbuf, uint count)
 			    sizeof(COMMAND_SMODE_ENTER), STATE_COMMAND);
 	if (err) {
 		dev_err(irtoy->dev, "enter sample mode: %d\n", err);
+		kfree(buf);
 		return err;
 	}