Skip to contentSkip to conversation

spi: Unify and simplify fwnode related checks

PATCH In review Andy Shevchenko 3 participants 7 messages Dec 8, 2024 – Dec 11, 2024 SPI

lore
Share & tools
lore
#0 lore raw

cover spi: Unify and simplify fwnode related checks

A couple of cleanups on top of recently added change.

Andy Shevchenko (2):
spi: Unify firmware node type checks
spi: Deduplicate deferred probe checks in spi_probe()

 drivers/spi/spi.c | 41 ++++++++++++++++++-----------------------
 1 file changed, 18 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#1 lore raw

PATCH 1/2 spi: Unify firmware node type checks

The few functions are using different approaches on how to check for the type of firmware node. Unify them to use a modern way of it.

With that in place it becomes obvious that no need to have independent conditionals when they are dependent and hence the code generation can be improved a little bit (clang-18, x86_64):

add/remove: 0/0 grow/shrink: 2/2 up/down: 16/-46 (-30)
Total: Before=49801, After=49771, chg -0.06%

Meanwhile no functional changes intended.

---
 drivers/spi/spi.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/spi/spi.c +14 -14
index ff1add2ecb91..88f785b9e6ec 100644
@@ -410,24 +410,21 @@ static int spi_probe(struct device *dev)
 {
 	const struct spi_driver		*sdrv = to_spi_driver(dev->driver);
 	struct spi_device		*spi = to_spi_device(dev);
+	struct fwnode_handle		*fwnode = dev_fwnode(dev);
 	int ret;
 
 	ret = of_clk_set_defaults(dev->of_node, false);
 	if (ret)
 		return ret;
 
-	if (dev->of_node) {
+	if (is_of_node(fwnode)) {
 		spi->irq = of_irq_get(dev->of_node, 0);
 		if (spi->irq == -EPROBE_DEFER)
 			return dev_err_probe(dev, -EPROBE_DEFER, "Failed to get irq\n");
 		if (spi->irq < 0)
 			spi->irq = 0;
-	}
-
-	if (has_acpi_companion(dev) && spi->irq < 0) {
-		struct acpi_device *adev = to_acpi_device_node(dev->fwnode);
-
-		spi->irq = acpi_dev_gpio_irq_get(adev, 0);
+	} else if (is_acpi_device_node(fwnode) && spi->irq < 0) {
+		spi->irq = acpi_dev_gpio_irq_get(to_acpi_device_node(fwnode), 0);
 		if (spi->irq == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
 		if (spi->irq < 0)
@@ -874,15 +871,18 @@ EXPORT_SYMBOL_GPL(spi_new_device);
  */
 void spi_unregister_device(struct spi_device *spi)
 {
+	struct fwnode_handle *fwnode;
+
 	if (!spi)
 		return;
 
-	if (spi->dev.of_node) {
-		of_node_clear_flag(spi->dev.of_node, OF_POPULATED);
-		of_node_put(spi->dev.of_node);
+	fwnode = dev_fwnode(&spi->dev);
+	if (is_of_node(fwnode)) {
+		of_node_clear_flag(to_of_node(fwnode), OF_POPULATED);
+		of_node_put(to_of_node(fwnode));
+	} else if (is_acpi_device_node(fwnode)) {
+		acpi_device_clear_enumerated(to_acpi_device_node(fwnode));
 	}
-	if (ACPI_COMPANION(&spi->dev))
-		acpi_device_clear_enumerated(ACPI_COMPANION(&spi->dev));
 	device_remove_software_node(&spi->dev);
 	device_del(&spi->dev);
 	spi_cleanup(spi);
@@ -1059,7 +1059,7 @@ static void spi_toggle_csgpiod(struct spi_device *spi, u8 idx, bool enable, bool
 	 * ambiguity. That's why we use enable, that takes SPI_CS_HIGH
 	 * into account.
 	 */
-	if (has_acpi_companion(&spi->dev))
+	if (is_acpi_device_node(dev_fwnode(&spi->dev)))
 		gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx), !enable);
 	else
 		/* Polarity handled by GPIO library */
@@ -4841,7 +4841,7 @@ extern struct notifier_block spi_of_notifier;
 #if IS_ENABLED(CONFIG_ACPI)
 static int spi_acpi_controller_match(struct device *dev, const void *data)
 {
-	return ACPI_COMPANION(dev->parent) == data;
+	return device_match_acpi_dev(dev->parent, data);
 }
 
 struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
#2 lore raw

PATCH 2/2 spi: Deduplicate deferred probe checks in spi_probe()

In reply to Andy Shevchenko

Deduplicate deferred probe checks in spi_probe() and enable the error message for ACPI case as well.

---
 drivers/spi/spi.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/spi/spi.c +6 -11
index 88f785b9e6ec..e0f79773be70 100644
@@ -417,19 +417,14 @@ static int spi_probe(struct device *dev)
 	if (ret)
 		return ret;
 
-	if (is_of_node(fwnode)) {
+	if (is_of_node(fwnode))
 		spi->irq = of_irq_get(dev->of_node, 0);
-		if (spi->irq == -EPROBE_DEFER)
-			return dev_err_probe(dev, -EPROBE_DEFER, "Failed to get irq\n");
-		if (spi->irq < 0)
-			spi->irq = 0;
-	} else if (is_acpi_device_node(fwnode) && spi->irq < 0) {
+	else if (is_acpi_device_node(fwnode) && spi->irq < 0)
 		spi->irq = acpi_dev_gpio_irq_get(to_acpi_device_node(fwnode), 0);
-		if (spi->irq == -EPROBE_DEFER)
-			return -EPROBE_DEFER;
-		if (spi->irq < 0)
-			spi->irq = 0;
-	}
+	if (spi->irq == -EPROBE_DEFER)
+		return dev_err_probe(dev, spi->irq, "Failed to get irq\n");
+	if (spi->irq < 0)
+		spi->irq = 0;
 
 	ret = dev_pm_domain_attach(dev, true);
 	if (ret)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer
#3 lore raw
In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

A couple of cleanups on top of recently added change.

Andy Shevchenko (2):
spi: Unify firmware node type checks
spi: Deduplicate deferred probe checks in spi_probe()

drivers/spi/spi.c | 41 ++++++++++++++++++-----------------------

 1 file changed, 18 insertions(+), 23 deletions(-)

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/2] spi: Unify firmware node type checks

      commit: b6ffe0e6147915fe3d31705e14dfbbecb724fb81
[2/2] spi: Deduplicate deferred probe checks in spi_probe()
      commit: 0020c9d2d572b49c55b2e1fabe6f6687e11a3ced

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

#4 lore raw
In reply to Andy Shevchenko
Quoted 1 line · Andy Shevchenko

couple of cleanups on top of recently added change.

please add what exactly cleanups done ? Recently added change is not that something someone would check as part of this patch. Description would be helpful.

#5 lore raw
Quoted 5 lines · Mukesh Kumar Savaliya
Quoted 1 line · Andy Shevchenko

couple of cleanups on top of recently added change.

please add what exactly cleanups done ? Recently added change is not that something someone would check as part of this patch. Description would be helpful.

But each patch has its description. Or I didn't get the request, sorry.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Mukesh Kumar Savaliya
Quoted 1 line · Andy Shevchenko

couple of cleanups on top of recently added change.

please add what exactly cleanups done ? Recently added change is not that something someone would check as part of this patch. Description would be helpful.

But each patch has its description. Or I didn't get the request, sorry.

FWIW, the change induced this mini-series is this one: d24cfee7f63d ("spi: Fix acpi deferred irq probe").

Signature · 2 lines
With Best Regards,
Andy Shevchenko