linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Input: sparcspkr - use cleanup facility for device_node
@ 2024-10-20 18:27 Javier Carrasco
  2024-10-21  7:15 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Javier Carrasco @ 2024-10-20 18:27 UTC (permalink / raw)
  To: Dmitry Torokhov, Matthias Brugger, AngeloGioacchino Del Regno,
	Hans de Goede, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Florian Fainelli, Broadcom internal kernel review list
  Cc: linux-input, linux-kernel, linux-arm-kernel, linux-mediatek,
	linux-sunxi, linux-rpi-kernel, Javier Carrasco

Use the 'free(device_node)' macro to simplify the code by automatically
freeing the device node, which removes the need for explicit calls to
'of_node_put()'.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Changes in v2:
- rebase onto input/next, drop applied patches.
- sparcspkr: drop goto before node declaration and return -ENOMEM.
- Link to v1: https://lore.kernel.org/r/20241010-input_automate_of_node_put-v1-0-ebc62138fbf8@gmail.com
---
 drivers/input/misc/sparcspkr.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/input/misc/sparcspkr.c b/drivers/input/misc/sparcspkr.c
index ff7b6291894a..66ddea9a203a 100644
--- a/drivers/input/misc/sparcspkr.c
+++ b/drivers/input/misc/sparcspkr.c
@@ -182,25 +182,23 @@ static int bbc_beep_probe(struct platform_device *op)
 {
 	struct sparcspkr_state *state;
 	struct bbc_beep_info *info;
-	struct device_node *dp;
-	int err = -ENOMEM;
+	int err;
 
 	state = kzalloc(sizeof(*state), GFP_KERNEL);
 	if (!state)
-		goto out_err;
+		return -ENOMEM;
 
 	state->name = "Sparc BBC Speaker";
 	state->event = bbc_spkr_event;
 	spin_lock_init(&state->lock);
 
-	dp = of_find_node_by_path("/");
 	err = -ENODEV;
+	struct device_node *dp __free(device_node) = of_find_node_by_path("/");
 	if (!dp)
 		goto out_free;
 
 	info = &state->u.bbc;
 	info->clock_freq = of_getintprop_default(dp, "clock-frequency", 0);
-	of_node_put(dp);
 	if (!info->clock_freq)
 		goto out_free;
 
@@ -221,7 +219,6 @@ static int bbc_beep_probe(struct platform_device *op)
 
 out_free:
 	kfree(state);
-out_err:
 	return err;
 }
 

---
base-commit: 00850d7b542aa4a8240cf977d43dc6d2158e48d7
change-id: 20241009-input_automate_of_node_put-1bae9f5c02d9

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


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

* Re: [PATCH v2] Input: sparcspkr - use cleanup facility for device_node
  2024-10-20 18:27 [PATCH v2] Input: sparcspkr - use cleanup facility for device_node Javier Carrasco
@ 2024-10-21  7:15 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2024-10-21  7:15 UTC (permalink / raw)
  To: Javier Carrasco
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, Hans de Goede,
	Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Florian Fainelli,
	Broadcom internal kernel review list, linux-input, linux-kernel,
	linux-arm-kernel, linux-mediatek, linux-sunxi, linux-rpi-kernel

Hi Javier,

On Sun, Oct 20, 2024 at 08:27:13PM +0200, Javier Carrasco wrote:
> Use the 'free(device_node)' macro to simplify the code by automatically
> freeing the device node, which removes the need for explicit calls to
> 'of_node_put()'.
> 
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> Changes in v2:
> - rebase onto input/next, drop applied patches.
> - sparcspkr: drop goto before node declaration and return -ENOMEM.

Can we switch the driver to devm so that issues with cleanup and gotos
will have less chances of resurfacing?

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2024-10-21  7:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-20 18:27 [PATCH v2] Input: sparcspkr - use cleanup facility for device_node Javier Carrasco
2024-10-21  7:15 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).