Skip to content

Commit b6ffe0e

Browse files
andy-shevbroonie
authored andcommitted
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. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20241208195635.1271656-2-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent e5fca61 commit b6ffe0e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

drivers/spi/spi.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -410,24 +410,21 @@ static int spi_probe(struct device *dev)
410410
{
411411
const struct spi_driver *sdrv = to_spi_driver(dev->driver);
412412
struct spi_device *spi = to_spi_device(dev);
413+
struct fwnode_handle *fwnode = dev_fwnode(dev);
413414
int ret;
414415

415416
ret = of_clk_set_defaults(dev->of_node, false);
416417
if (ret)
417418
return ret;
418419

419-
if (dev->of_node) {
420+
if (is_of_node(fwnode)) {
420421
spi->irq = of_irq_get(dev->of_node, 0);
421422
if (spi->irq == -EPROBE_DEFER)
422423
return dev_err_probe(dev, -EPROBE_DEFER, "Failed to get irq\n");
423424
if (spi->irq < 0)
424425
spi->irq = 0;
425-
}
426-
427-
if (has_acpi_companion(dev) && spi->irq < 0) {
428-
struct acpi_device *adev = to_acpi_device_node(dev->fwnode);
429-
430-
spi->irq = acpi_dev_gpio_irq_get(adev, 0);
426+
} else if (is_acpi_device_node(fwnode) && spi->irq < 0) {
427+
spi->irq = acpi_dev_gpio_irq_get(to_acpi_device_node(fwnode), 0);
431428
if (spi->irq == -EPROBE_DEFER)
432429
return -EPROBE_DEFER;
433430
if (spi->irq < 0)
@@ -874,15 +871,18 @@ EXPORT_SYMBOL_GPL(spi_new_device);
874871
*/
875872
void spi_unregister_device(struct spi_device *spi)
876873
{
874+
struct fwnode_handle *fwnode;
875+
877876
if (!spi)
878877
return;
879878

880-
if (spi->dev.of_node) {
881-
of_node_clear_flag(spi->dev.of_node, OF_POPULATED);
882-
of_node_put(spi->dev.of_node);
879+
fwnode = dev_fwnode(&spi->dev);
880+
if (is_of_node(fwnode)) {
881+
of_node_clear_flag(to_of_node(fwnode), OF_POPULATED);
882+
of_node_put(to_of_node(fwnode));
883+
} else if (is_acpi_device_node(fwnode)) {
884+
acpi_device_clear_enumerated(to_acpi_device_node(fwnode));
883885
}
884-
if (ACPI_COMPANION(&spi->dev))
885-
acpi_device_clear_enumerated(ACPI_COMPANION(&spi->dev));
886886
device_remove_software_node(&spi->dev);
887887
device_del(&spi->dev);
888888
spi_cleanup(spi);
@@ -1059,7 +1059,7 @@ static void spi_toggle_csgpiod(struct spi_device *spi, u8 idx, bool enable, bool
10591059
* ambiguity. That's why we use enable, that takes SPI_CS_HIGH
10601060
* into account.
10611061
*/
1062-
if (has_acpi_companion(&spi->dev))
1062+
if (is_acpi_device_node(dev_fwnode(&spi->dev)))
10631063
gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx), !enable);
10641064
else
10651065
/* Polarity handled by GPIO library */
@@ -4841,7 +4841,7 @@ extern struct notifier_block spi_of_notifier;
48414841
#if IS_ENABLED(CONFIG_ACPI)
48424842
static int spi_acpi_controller_match(struct device *dev, const void *data)
48434843
{
4844-
return ACPI_COMPANION(dev->parent) == data;
4844+
return device_match_acpi_dev(dev->parent, data);
48454845
}
48464846

48474847
struct spi_controller *acpi_spi_find_controller_by_adev(struct acpi_device *adev)

0 commit comments

Comments
 (0)