public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mfd: pcf50633-adc: Fix potential memleak in pcf50633_adc_async_read()
@ 2022-12-08  6:15 Qiheng Lin
  2023-01-04 16:12 ` Lee Jones
  0 siblings, 1 reply; 2+ messages in thread
From: Qiheng Lin @ 2022-12-08  6:15 UTC (permalink / raw)
  To: lee; +Cc: linux-kernel, linqiheng

`req` is allocated in pcf50633_adc_async_read(), but
adc_enqueue_request() could fail to insert the `req` into queue.
We need to check the return value and free it in the case of failure.

Fixes: 08c3e06a5eb2 ("mfd: PCF50633 adc driver")
Signed-off-by: Qiheng Lin <linqiheng@huawei.com>
---
 drivers/mfd/pcf50633-adc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/pcf50633-adc.c b/drivers/mfd/pcf50633-adc.c
index 5cd653e61512..191b1bc6141c 100644
--- a/drivers/mfd/pcf50633-adc.c
+++ b/drivers/mfd/pcf50633-adc.c
@@ -136,6 +136,7 @@ int pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
 			     void *callback_param)
 {
 	struct pcf50633_adc_request *req;
+	int ret;
 
 	/* req is freed when the result is ready, in interrupt handler */
 	req = kmalloc(sizeof(*req), GFP_KERNEL);
@@ -147,7 +148,11 @@ int pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
 	req->callback = callback;
 	req->callback_param = callback_param;
 
-	return adc_enqueue_request(pcf, req);
+	ret = adc_enqueue_request(pcf, req);
+	if (ret)
+		kfree(req);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(pcf50633_adc_async_read);
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mfd: pcf50633-adc: Fix potential memleak in pcf50633_adc_async_read()
  2022-12-08  6:15 [PATCH] mfd: pcf50633-adc: Fix potential memleak in pcf50633_adc_async_read() Qiheng Lin
@ 2023-01-04 16:12 ` Lee Jones
  0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2023-01-04 16:12 UTC (permalink / raw)
  To: Qiheng Lin; +Cc: linux-kernel

On Thu, 08 Dec 2022, Qiheng Lin wrote:

> `req` is allocated in pcf50633_adc_async_read(), but
> adc_enqueue_request() could fail to insert the `req` into queue.
> We need to check the return value and free it in the case of failure.
> 
> Fixes: 08c3e06a5eb2 ("mfd: PCF50633 adc driver")
> Signed-off-by: Qiheng Lin <linqiheng@huawei.com>
> ---
>  drivers/mfd/pcf50633-adc.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Applied, thanks

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-04 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08  6:15 [PATCH] mfd: pcf50633-adc: Fix potential memleak in pcf50633_adc_async_read() Qiheng Lin
2023-01-04 16:12 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox