Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node
@ 2024-10-14  8:56 Javier Carrasco
  2024-10-14  8:56 ` [PATCH v2 1/2] staging: vchiq_arm: refactor goto instructions in vchiq_probe() Javier Carrasco
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Javier Carrasco @ 2024-10-14  8:56 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Greg Kroah-Hartman, Stefan Wahren, Umang Jain, Laurent Pinchart
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Javier Carrasco, stable

This series refactors some useless goto instructions as a preparation
for the fix of a missing of_node_put() by means of the cleanup
attribute.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Changes in v2:
- Refactor vchiq_probe() to remove goto instructions.
- Declare and initialize the node right before its first usage.
- Link to v1: https://lore.kernel.org/r/20241013-vchiq_arm-of_node_put-v1-1-f72b2a6e47d0@gmail.com

---
Javier Carrasco (2):
      staging: vchiq_arm: refactor goto instructions in vchiq_probe()
      staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node

 .../vc04_services/interface/vchiq_arm/vchiq_arm.c     | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
---
base-commit: d61a00525464bfc5fe92c6ad713350988e492b88
change-id: 20241013-vchiq_arm-of_node_put-60a5eaaafd70

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>



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

* [PATCH v2 1/2] staging: vchiq_arm: refactor goto instructions in vchiq_probe()
  2024-10-14  8:56 [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
@ 2024-10-14  8:56 ` Javier Carrasco
  2024-10-14  8:56 ` [PATCH v2 2/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Javier Carrasco @ 2024-10-14  8:56 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Greg Kroah-Hartman, Stefan Wahren, Umang Jain, Laurent Pinchart
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Javier Carrasco

The 'failed_platform_init' and 'error_exit' labels do not simplify the
code, there is a single jump to them in the code, and the actions taken
from then on can be easily carried out where the goto occurs.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 .../staging/vc04_services/interface/vchiq_arm/vchiq_arm.c   | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 27ceaac8f6cc..81b2887d1ae0 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1361,8 +1361,10 @@ static int vchiq_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, mgmt);
 
 	ret = vchiq_platform_init(pdev, &mgmt->state);
-	if (ret)
-		goto failed_platform_init;
+	if (ret) {
+		dev_err(&pdev->dev, "arm: Could not initialize vchiq platform\n");
+		return ret;
+	}
 
 	vchiq_debugfs_init(&mgmt->state);
 
@@ -1376,18 +1378,13 @@ static int vchiq_probe(struct platform_device *pdev)
 	ret = vchiq_register_chrdev(&pdev->dev);
 	if (ret) {
 		dev_err(&pdev->dev, "arm: Failed to initialize vchiq cdev\n");
-		goto error_exit;
+		return ret;
 	}
 
 	bcm2835_audio = vchiq_device_register(&pdev->dev, "bcm2835-audio");
 	bcm2835_camera = vchiq_device_register(&pdev->dev, "bcm2835-camera");
 
 	return 0;
-
-failed_platform_init:
-	dev_err(&pdev->dev, "arm: Could not initialize vchiq platform\n");
-error_exit:
-	return ret;
 }
 
 static void vchiq_remove(struct platform_device *pdev)

-- 
2.43.0



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

* [PATCH v2 2/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node
  2024-10-14  8:56 [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
  2024-10-14  8:56 ` [PATCH v2 1/2] staging: vchiq_arm: refactor goto instructions in vchiq_probe() Javier Carrasco
@ 2024-10-14  8:56 ` Javier Carrasco
  2024-10-14  9:26 ` [PATCH v2 0/2] " Umang Jain
  2024-10-14  9:31 ` Dan Carpenter
  3 siblings, 0 replies; 5+ messages in thread
From: Javier Carrasco @ 2024-10-14  8:56 UTC (permalink / raw)
  To: Florian Fainelli, Broadcom internal kernel review list,
	Greg Kroah-Hartman, Stefan Wahren, Umang Jain, Laurent Pinchart
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	Javier Carrasco, stable

An error path was introduced without including the required call to
of_node_put() to decrement the node's refcount and avoid leaking memory.
If the call to kzalloc() for 'mgmt' fails, the probe returns without
decrementing the refcount.

Use the automatic cleanup facility to fix the bug and protect the code
against new error paths where the call to of_node_put() might be missing
again.

Cc: stable@vger.kernel.org
Fixes: 1c9e16b73166 ("staging: vc04_services: vchiq_arm: Split driver static and runtime data")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 81b2887d1ae0..bf2024929d07 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -1332,7 +1332,6 @@ MODULE_DEVICE_TABLE(of, vchiq_of_match);
 
 static int vchiq_probe(struct platform_device *pdev)
 {
-	struct device_node *fw_node;
 	const struct vchiq_platform_info *info;
 	struct vchiq_drv_mgmt *mgmt;
 	int ret;
@@ -1341,8 +1340,8 @@ static int vchiq_probe(struct platform_device *pdev)
 	if (!info)
 		return -EINVAL;
 
-	fw_node = of_find_compatible_node(NULL, NULL,
-					  "raspberrypi,bcm2835-firmware");
+	struct device_node *fw_node __free(device_node) =
+		of_find_compatible_node(NULL, NULL, "raspberrypi,bcm2835-firmware");
 	if (!fw_node) {
 		dev_err(&pdev->dev, "Missing firmware node\n");
 		return -ENOENT;
@@ -1353,7 +1352,6 @@ static int vchiq_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	mgmt->fw = devm_rpi_firmware_get(&pdev->dev, fw_node);
-	of_node_put(fw_node);
 	if (!mgmt->fw)
 		return -EPROBE_DEFER;
 

-- 
2.43.0



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

* Re: [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node
  2024-10-14  8:56 [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
  2024-10-14  8:56 ` [PATCH v2 1/2] staging: vchiq_arm: refactor goto instructions in vchiq_probe() Javier Carrasco
  2024-10-14  8:56 ` [PATCH v2 2/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
@ 2024-10-14  9:26 ` Umang Jain
  2024-10-14  9:31 ` Dan Carpenter
  3 siblings, 0 replies; 5+ messages in thread
From: Umang Jain @ 2024-10-14  9:26 UTC (permalink / raw)
  To: Javier Carrasco, Florian Fainelli,
	Broadcom internal kernel review list, Greg Kroah-Hartman,
	Stefan Wahren, Laurent Pinchart
  Cc: linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	stable

Hi Javier,

Thank you for the patch

On 14/10/24 2:26 pm, Javier Carrasco wrote:
> This series refactors some useless goto instructions as a preparation
> for the fix of a missing of_node_put() by means of the cleanup
> attribute.
>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

For the series,

Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
> Changes in v2:
> - Refactor vchiq_probe() to remove goto instructions.
> - Declare and initialize the node right before its first usage.
> - Link to v1: https://lore.kernel.org/r/20241013-vchiq_arm-of_node_put-v1-1-f72b2a6e47d0@gmail.com
>
> ---
> Javier Carrasco (2):
>        staging: vchiq_arm: refactor goto instructions in vchiq_probe()
>        staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node
>
>   .../vc04_services/interface/vchiq_arm/vchiq_arm.c     | 19 +++++++------------
>   1 file changed, 7 insertions(+), 12 deletions(-)
> ---
> base-commit: d61a00525464bfc5fe92c6ad713350988e492b88
> change-id: 20241013-vchiq_arm-of_node_put-60a5eaaafd70
>
> Best regards,



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

* Re: [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node
  2024-10-14  8:56 [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
                   ` (2 preceding siblings ...)
  2024-10-14  9:26 ` [PATCH v2 0/2] " Umang Jain
@ 2024-10-14  9:31 ` Dan Carpenter
  3 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2024-10-14  9:31 UTC (permalink / raw)
  To: Javier Carrasco
  Cc: Florian Fainelli, Broadcom internal kernel review list,
	Greg Kroah-Hartman, Stefan Wahren, Umang Jain, Laurent Pinchart,
	linux-rpi-kernel, linux-arm-kernel, linux-staging, linux-kernel,
	stable

On Mon, Oct 14, 2024 at 10:56:35AM +0200, Javier Carrasco wrote:
> This series refactors some useless goto instructions as a preparation
> for the fix of a missing of_node_put() by means of the cleanup
> attribute.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> Changes in v2:
> - Refactor vchiq_probe() to remove goto instructions.
> - Declare and initialize the node right before its first usage.
> - Link to v1: https://lore.kernel.org/r/20241013-vchiq_arm-of_node_put-v1-1-f72b2a6e47d0@gmail.com
> 

Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter



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

end of thread, other threads:[~2024-10-14  9:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14  8:56 [PATCH v2 0/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
2024-10-14  8:56 ` [PATCH v2 1/2] staging: vchiq_arm: refactor goto instructions in vchiq_probe() Javier Carrasco
2024-10-14  8:56 ` [PATCH v2 2/2] staging: vchiq_arm: Fix missing refcount decrement in error path for fw_node Javier Carrasco
2024-10-14  9:26 ` [PATCH v2 0/2] " Umang Jain
2024-10-14  9:31 ` Dan Carpenter

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