From: Christian Engelmayer Date: Thu, 23 Jan 2014 21:32:20 +0000 (+0100) Subject: pwm: lp3943: Fix potential memory leak during request X-Git-Tag: firefly_0821_release~176^2~4354^2 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=0b7d25c347900e2550398e29e25caf0fefe3cab2;p=firefly-linux-kernel-4.4.55.git 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. Signed-off-by: Christian Engelmayer Acked-by: Milo Kim Signed-off-by: Thierry Reding --- diff --git a/drivers/pwm/pwm-lp3943.c b/drivers/pwm/pwm-lp3943.c index 8a843a04c224..a40b9c34e9ff 100644 --- a/drivers/pwm/pwm-lp3943.c +++ b/drivers/pwm/pwm-lp3943.c @@ -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;