Skip to contentSkip to conversation

media: c8sectpfe: fix double free in configure_channels()

PATCH In review Dan Carpenter 2 participants 2 messages Dec 8, 2021 – Dec 10, 2021

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

PATCH 1/1 media: c8sectpfe: fix double free in configure_channels()

The configure_channels() function has a double free because configure_memdma_and_inputblock() calls free_input_block() and then it's called again in the error handling code.

Fixes c5f5d0f99794 ("[media] c8sectpfe: STiH407/10 Linux DVB demux support")
---
 drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c +3 -5
index e1f520903248..7bb1384e4bad 100644
@@ -925,7 +925,6 @@ static int c8sectpfe_remove(struct platform_device *pdev)
 static int configure_channels(struct c8sectpfei *fei)
 {
 	int index = 0, ret;
-	struct channel_info *tsin;
 	struct device_node *child, *np = fei->dev->of_node;
 
 	/* iterate round each tsin and configure memdma descriptor and IB hw */
@@ -943,10 +942,9 @@ static int configure_channels(struct c8sectpfei *fei)
 	return 0;
 
 err_unmap:
-	for (index = 0; index < fei->tsin_count; index++) {
-		tsin = fei->channel_data[index];
-		free_input_block(fei, tsin);
-	}
+	while (--index >= 0)
+		free_input_block(fei, fei->channel_data[index]);
+
 	return ret;
 }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Dan

Quoted 27 lines · Dan Carpenter

The configure_channels() function has a double free because configure_memdma_and_inputblock() calls free_input_block() and then it's called again in the error handling code.

Fixes c5f5d0f99794 ("[media] c8sectpfe: STiH407/10 Linux DVB demux support")
---
 drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c +0 -1
index e1f520903248..7bb1384e4bad 100644
@@ -925,7 +925,6 @@ static int c8sectpfe_remove(struct platform_device *pdev)
 static int configure_channels(struct c8sectpfei *fei)
 {
 	int index = 0, ret;
-	struct channel_info *tsin;
 	struct device_node *child, *np = fei->dev->of_node;
 
 	/* iterate round each tsin and configure memdma descriptor and IB hw */
@@ -943,10 +942,9 @@ static int configure_channels(struct c8sectpfei *fei)
 	return 0;
 
 err_unmap:

drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c static int configure_channels(struct c8sectpfei *fei) · line 950

Quoted 10 lines
drivers/media/platform/sti/c8sectpfe/c8sectpfe-core.c +3 -4
-	for (index = 0; index < fei->tsin_count; index++) {
-		tsin = fei->channel_data[index];
-		free_input_block(fei, tsin);
-	}
+	while (--index >= 0)
+		free_input_block(fei, fei->channel_data[index]);
+
 	return ret;
 }
 

Thanks
Patrice