Skip to contentSkip to conversation

pwm: lp3943: Fix potential memory leak during request

PATCH In review Christian Engelmayer 4 participants 6 messages Jan 23, 2014 – Feb 26, 2014 PWM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pwm: lp3943: Fix potential memory leak during request

Fix a memory leak in the lp3943_pwm_request_map() error handling path. Make sure already allocated pwm map memory is freed correctly. Detected by Coverity: CID 1162829.

---
 drivers/pwm/pwm-lp3943.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lp3943.c +3 -1
index 8a843a0..a40b9c3 100644
@@ -52,8 +52,10 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)
 		offset = pwm_map->output[i];
 
 		/* Return an error if the pin is already assigned */
-		if (test_and_set_bit(offset, &lp3943->pin_used))
+		if (test_and_set_bit(offset, &lp3943->pin_used)) {
+			kfree(pwm_map);
 			return ERR_PTR(-EBUSY);
+		}
 	}
 
 	return pwm_map;
Signature · 1 line
1.8.3.2
Acked-by on v1 1/1
#2 lore raw
In reply to Christian Engelmayer
Quoted 27 lines · Christian Engelmayer

Fix a memory leak in the lp3943_pwm_request_map() error handling path. Make sure already allocated pwm map memory is freed correctly. Detected by Coverity: CID 1162829.

---
 drivers/pwm/pwm-lp3943.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lp3943.c +3 -1
index 8a843a0..a40b9c3 100644
@@ -52,8 +52,10 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)
 		offset = pwm_map->output[i];
 
 		/* Return an error if the pin is already assigned */
-		if (test_and_set_bit(offset, &lp3943->pin_used))
+		if (test_and_set_bit(offset, &lp3943->pin_used)) {
+			kfree(pwm_map);
 			return ERR_PTR(-EBUSY);
+		}
 	}
 
 	return pwm_map;
Signature · 1 line
1.8.3.2

Lee, since you took this driver via the MFD tree, would you mind picking up this fix as well?

In case you don't have it in your inbox somewhere, you should be able to grab it from here:

	http://patchwork.ozlabs.org/patch/313741/

In that case:

Thierry

#3 lore raw
Quoted 25 lines · Thierry Reding
Quoted 24 lines · Christian Engelmayer

Fix a memory leak in the lp3943_pwm_request_map() error handling path. Make sure already allocated pwm map memory is freed correctly. Detected by Coverity: CID 1162829.

---
 drivers/pwm/pwm-lp3943.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lp3943.c +3 -1
index 8a843a0..a40b9c3 100644
@@ -52,8 +52,10 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)
 		offset = pwm_map->output[i];
 
 		/* Return an error if the pin is already assigned */
-		if (test_and_set_bit(offset, &lp3943->pin_used))
+		if (test_and_set_bit(offset, &lp3943->pin_used)) {
+			kfree(pwm_map);
 			return ERR_PTR(-EBUSY);
+		}
 	}
 
Quoted 4 lines

drivers/pwm/pwm-lp3943.c lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm) · line 61

Quoted 1 line
drivers/pwm/pwm-lp3943.c +0 -0
 	return pwm_map;

Lee, since you took this driver via the MFD tree, would you mind picking up this fix as well?

Everything I have is now in Mainline.

It's best for you to apply it now I think?

Quoted 10 lines

In case you don't have it in your inbox somewhere, you should be able to grab it from here:

	http://patchwork.ozlabs.org/patch/313741/

In that case:

Thierry

Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#4 lore raw
Quoted 27 lines · Lee Jones
Quoted 25 lines · Thierry Reding
Quoted 24 lines · Christian Engelmayer

Fix a memory leak in the lp3943_pwm_request_map() error handling path. Make sure already allocated pwm map memory is freed correctly. Detected by Coverity: CID 1162829.

---
 drivers/pwm/pwm-lp3943.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pwm/pwm-lp3943.c +3 -1
index 8a843a0..a40b9c3 100644
@@ -52,8 +52,10 @@ lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm)
 		offset = pwm_map->output[i];
 
 		/* Return an error if the pin is already assigned */
-		if (test_and_set_bit(offset, &lp3943->pin_used))
+		if (test_and_set_bit(offset, &lp3943->pin_used)) {
+			kfree(pwm_map);
 			return ERR_PTR(-EBUSY);
+		}
 	}
 
Quoted 8 lines
Quoted 4 lines

drivers/pwm/pwm-lp3943.c lp3943_pwm_request_map(struct lp3943_pwm *lp3943_pwm, int hwpwm) · line 61

Quoted 1 line
drivers/pwm/pwm-lp3943.c +0 -0
 	return pwm_map;

Lee, since you took this driver via the MFD tree, would you mind picking up this fix as well?

Everything I have is now in Mainline.

It's best for you to apply it now I think?

Sure, I could do that after -rc1 is released. It's somewhat problematic because I can't really create a tree that's based on yours before -rc1. After -rc1 it shouldn't be a problem and this also isn't all that critical, so sending off another pull request to Linus after -rc1 is probably what I'll do.

Thierry

#5 lore raw
In reply to Christian Engelmayer
Quoted 8 lines · Christian Engelmayer

Fix a memory leak in the lp3943_pwm_request_map() error handling path. Make sure already allocated pwm map memory is freed correctly. Detected by Coverity: CID 1162829.

---
 drivers/pwm/pwm-lp3943.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

I've applied this and sent it off to Linus for inclusion in v3.14-rc5.

Thanks,
Thierry