diff mbox series

[v2] spi: cs42l43: Clean up of firmware node

Message ID 20240201172649.794161-1-ckeepax@opensource.cirrus.com (mailing list archive)
State Superseded
Headers show
Series [v2] spi: cs42l43: Clean up of firmware node | expand

Commit Message

Charles Keepax Feb. 1, 2024, 5:26 p.m. UTC
As we get a child node in the OF case, we should also clean up the
reference, add code to do so.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Changes since v1:
 - Switch to using devm_add_action to clean up the of_node

Thanks,
Charles

 drivers/spi/spi-cs42l43.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Comments

Andy Shevchenko Feb. 1, 2024, 5:36 p.m. UTC | #1
On Thu, Feb 1, 2024 at 7:26 PM Charles Keepax
<ckeepax@opensource.cirrus.com> wrote:
>
> As we get a child node in the OF case, we should also clean up the
> reference, add code to do so.

...

> +       if (is_of_node(fwnode)) {
> +               fwnode = fwnode_get_named_child_node(fwnode, "spi");

> +               devm_add_action(priv->dev, cs42l43_release_of_node, fwnode);

ret = ...
if (ret)
  return ret;

> +       }

With that being addressed,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
diff mbox series

Patch

diff --git a/drivers/spi/spi-cs42l43.c b/drivers/spi/spi-cs42l43.c
index b24190526ce9..adf6ec4833a5 100644
--- a/drivers/spi/spi-cs42l43.c
+++ b/drivers/spi/spi-cs42l43.c
@@ -202,6 +202,11 @@  static size_t cs42l43_spi_max_length(struct spi_device *spi)
 	return CS42L43_SPI_MAX_LENGTH;
 }
 
+static void cs42l43_release_of_node(void *data)
+{
+	fwnode_handle_put(data);
+}
+
 static int cs42l43_spi_probe(struct platform_device *pdev)
 {
 	struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent);
@@ -228,12 +233,6 @@  static int cs42l43_spi_probe(struct platform_device *pdev)
 	priv->ctlr->transfer_one = cs42l43_transfer_one;
 	priv->ctlr->set_cs = cs42l43_set_cs;
 	priv->ctlr->max_transfer_size = cs42l43_spi_max_length;
-
-	if (is_of_node(fwnode))
-		fwnode = fwnode_get_named_child_node(fwnode, "spi");
-
-	device_set_node(&priv->ctlr->dev, fwnode);
-
 	priv->ctlr->mode_bits = SPI_3WIRE | SPI_MODE_X_MASK;
 	priv->ctlr->flags = SPI_CONTROLLER_HALF_DUPLEX;
 	priv->ctlr->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
@@ -257,6 +256,13 @@  static int cs42l43_spi_probe(struct platform_device *pdev)
 	regmap_write(priv->regmap, CS42L43_SPI_CONFIG3, 0);
 	regmap_write(priv->regmap, CS42L43_SPI_CONFIG4, CS42L43_SPI_STALL_ENA_MASK);
 
+	if (is_of_node(fwnode)) {
+		fwnode = fwnode_get_named_child_node(fwnode, "spi");
+		devm_add_action(priv->dev, cs42l43_release_of_node, fwnode);
+	}
+
+	device_set_node(&priv->ctlr->dev, fwnode);
+
 	ret = devm_spi_register_controller(priv->dev, priv->ctlr);
 	if (ret) {
 		dev_err(priv->dev, "Failed to register SPI controller: %d\n", ret);