[v2] input: raspberrypi-ts: Fix refcount leak in rpi_ts_probe

Message ID 20221223074657.810346-1-linmq006@gmail.com
State New
Headers
Series [v2] input: raspberrypi-ts: Fix refcount leak in rpi_ts_probe |

Commit Message

Miaoqian Lin Dec. 23, 2022, 7:46 a.m. UTC
  rpi_firmware_get() take reference, we need to release it in error paths
as well. Use devm_rpi_firmware_get() helper to handling the resources.
Also remove the existing rpi_firmware_put().

Fixes: 0b9f28fed3f7 ("Input: add official Raspberry Pi's touchscreen driver")
Fixes: 3b8ddff780b7 ("input: raspberrypi-ts: Release firmware handle when not needed")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
changes in v2:
- use devm_rpi_firmware_get().
- remove rpi_firmware_put().
---
 drivers/input/touchscreen/raspberrypi-ts.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Mattijs Korpershoek Jan. 24, 2023, 10:15 a.m. UTC | #1
On Fri, Dec 23, 2022 at 11:46, Miaoqian Lin <linmq006@gmail.com> wrote:

> rpi_firmware_get() take reference, we need to release it in error paths
> as well. Use devm_rpi_firmware_get() helper to handling the resources.
> Also remove the existing rpi_firmware_put().
>
> Fixes: 0b9f28fed3f7 ("Input: add official Raspberry Pi's touchscreen driver")
> Fixes: 3b8ddff780b7 ("input: raspberrypi-ts: Release firmware handle when not needed")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
> changes in v2:
> - use devm_rpi_firmware_get().
> - remove rpi_firmware_put().

Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

> ---
>  drivers/input/touchscreen/raspberrypi-ts.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/input/touchscreen/raspberrypi-ts.c b/drivers/input/touchscreen/raspberrypi-ts.c
> index 5000f5fd9ec3..45c575df994e 100644
> --- a/drivers/input/touchscreen/raspberrypi-ts.c
> +++ b/drivers/input/touchscreen/raspberrypi-ts.c
> @@ -134,7 +134,7 @@ static int rpi_ts_probe(struct platform_device *pdev)
>  		return -ENOENT;
>  	}
>  
> -	fw = rpi_firmware_get(fw_node);
> +	fw = devm_rpi_firmware_get(&pdev->dev, fw_node);
>  	of_node_put(fw_node);
>  	if (!fw)
>  		return -EPROBE_DEFER;
> @@ -160,7 +160,6 @@ static int rpi_ts_probe(struct platform_device *pdev)
>  	touchbuf = (u32)ts->fw_regs_phys;
>  	error = rpi_firmware_property(fw, RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF,
>  				      &touchbuf, sizeof(touchbuf));
> -	rpi_firmware_put(fw);
>  	if (error || touchbuf != 0) {
>  		dev_warn(dev, "Failed to set touchbuf, %d\n", error);
>  		return error;
> -- 
> 2.25.1
  
Dmitry Torokhov April 14, 2023, 6:06 a.m. UTC | #2
On Fri, Dec 23, 2022 at 11:46:53AM +0400, Miaoqian Lin wrote:
> rpi_firmware_get() take reference, we need to release it in error paths
> as well. Use devm_rpi_firmware_get() helper to handling the resources.
> Also remove the existing rpi_firmware_put().
> 
> Fixes: 0b9f28fed3f7 ("Input: add official Raspberry Pi's touchscreen driver")
> Fixes: 3b8ddff780b7 ("input: raspberrypi-ts: Release firmware handle when not needed")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Applied, thank you.
  

Patch

diff --git a/drivers/input/touchscreen/raspberrypi-ts.c b/drivers/input/touchscreen/raspberrypi-ts.c
index 5000f5fd9ec3..45c575df994e 100644
--- a/drivers/input/touchscreen/raspberrypi-ts.c
+++ b/drivers/input/touchscreen/raspberrypi-ts.c
@@ -134,7 +134,7 @@  static int rpi_ts_probe(struct platform_device *pdev)
 		return -ENOENT;
 	}
 
-	fw = rpi_firmware_get(fw_node);
+	fw = devm_rpi_firmware_get(&pdev->dev, fw_node);
 	of_node_put(fw_node);
 	if (!fw)
 		return -EPROBE_DEFER;
@@ -160,7 +160,6 @@  static int rpi_ts_probe(struct platform_device *pdev)
 	touchbuf = (u32)ts->fw_regs_phys;
 	error = rpi_firmware_property(fw, RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF,
 				      &touchbuf, sizeof(touchbuf));
-	rpi_firmware_put(fw);
 	if (error || touchbuf != 0) {
 		dev_warn(dev, "Failed to set touchbuf, %d\n", error);
 		return error;