Skip to contentSkip to conversation

staging: vt6655: fix some erroneous memory clean-up loops

PATCH In review Nam Cao 2 participants 2 messages Sep 12, 2022 Staging

lore
Share & tools
lore

Nam Cao

author
#0 lore raw

PATCH 1/1 staging: vt6655: fix some erroneous memory clean-up loops

In some initialization functions of this driver, memory is allocated with 'i' acting as an index variable and increasing from 0. The commit in "Fixes" introduces some clean-up codes in case of allocation failure, which free memory in reverse order with 'i' decreasing to 0. However, there are some problems:
- The case i=0 is left out. Thus memory is leaked.
- In case memory allocation fails right from the start, the memory freeing loops will start with i=-1 and invalid memory locations will be accessed.

One of these loops has been fixed in commit c8ff91535880 ("staging:
vt6655: fix potential memory leak"). Fix the remaining erroneous loops.

Fixes 5341ee0adb17 ("staging: vt6655: check for memory allocation failures")
---
 drivers/staging/vt6655/device_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/vt6655/device_main.c +3 -3
index 04d737012cef..56c3cf3ba53d 100644
@@ -631,7 +631,7 @@ static int device_init_rd0_ring(struct vnt_private *priv)
 	kfree(desc->rd_info);
 
 err_free_desc:
-	while (--i) {
+	while (i--) {
 		desc = &priv->aRD0Ring[i];
 		device_free_rx_buf(priv, desc);
 		kfree(desc->rd_info);
@@ -677,7 +677,7 @@ static int device_init_rd1_ring(struct vnt_private *priv)
 	kfree(desc->rd_info);
 
 err_free_desc:
-	while (--i) {
+	while (i--) {
 		desc = &priv->aRD1Ring[i];
 		device_free_rx_buf(priv, desc);
 		kfree(desc->rd_info);
@@ -782,7 +782,7 @@ static int device_init_td1_ring(struct vnt_private *priv)
 	return 0;
 
 err_free_desc:
-	while (--i) {
+	while (i--) {
 		desc = &priv->apTD1Rings[i];
 		kfree(desc->td_info);
 	}
Signature · 1 line
2.25.1
Tested-by on v1 1/1
#1 lore raw
Quoted 44 lines · Nam Cao

In some initialization functions of this driver, memory is allocated with 'i' acting as an index variable and increasing from 0. The commit in "Fixes" introduces some clean-up codes in case of allocation failure, which free memory in reverse order with 'i' decreasing to 0. However, there are some problems:
- The case i=0 is left out. Thus memory is leaked.
- In case memory allocation fails right from the start, the memory freeing loops will start with i=-1 and invalid memory locations will be accessed.

One of these loops has been fixed in commit c8ff91535880 ("staging:
vt6655: fix potential memory leak"). Fix the remaining erroneous loops.

Fixes 5341ee0adb17 ("staging: vt6655: check for memory allocation failures")
---
  drivers/staging/vt6655/device_main.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/vt6655/device_main.c +2 -2
index 04d737012cef..56c3cf3ba53d 100644
@@ -631,7 +631,7 @@ static int device_init_rd0_ring(struct vnt_private *priv)
  	kfree(desc->rd_info);
 
  err_free_desc:
-	while (--i) {
+	while (i--) {
  		desc = &priv->aRD0Ring[i];
  		device_free_rx_buf(priv, desc);
  		kfree(desc->rd_info);
@@ -677,7 +677,7 @@ static int device_init_rd1_ring(struct vnt_private *priv)
  	kfree(desc->rd_info);
 
  err_free_desc:
-	while (--i) {
+	while (i--) {
  		desc = &priv->aRD1Ring[i];
  		device_free_rx_buf(priv, desc);
  		kfree(desc->rd_info);

drivers/staging/vt6655/device_main.c static int device_init_td1_ring(struct vnt_private *priv) · line 788

Quoted 8 lines
drivers/staging/vt6655/device_main.c +1 -1
@@ -782,7 +782,7 @@ static int device_init_td1_ring(struct vnt_private *priv)
  	return 0;
 
  err_free_desc:
-	while (--i) {
+	while (i--) {
  		desc = &priv->apTD1Rings[i];
  		kfree(desc->td_info);
  	}