Compare

205cccd06e545694754e1bf8d626ea96e742cd8a..b0f0c761ed3fa10754dc9295db85374a173123b7

spi: spi-fsl-lpspi: directly return ret in fsl_lpspi_transfer_one()

Both fsl_lpspi_dma_transfer() and fsl_lpspi_pio_transfer() only return
negative error values in case of error or 0 in case of success.

Directly return ret, there is no need to check for positive error values
and return them as 0.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://patch.msgid.link/20261009-spi-fsl-lpspi-more-cleanups-v1-2-2d4549d5205e@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>

Marc Kleine-Budde <mkl@pengutronix.de> · 2026-10-09 10:16 UTC · committed by Mark Brown

Browse files
9 files changed, +44 −70
modified drivers/gpio/gpio-mxc.c
@@ -7,7 +7,6 @@
7 7 // Authors: Daniel Mack, Juergen Beisert.
8 8 // Copyright (C) 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
9 9
10 - #include <linux/bitops.h>
11 10 #include <linux/cleanup.h>
12 11 #include <linux/clk.h>
13 12 #include <linux/err.h>
@@ -69,11 +68,11 @@ struct mxc_gpio_port {
69 68 struct irq_domain *domain;
70 69 struct gpio_generic_chip gen_gc;
71 70 struct device *dev;
72 - unsigned long both_edges;
71 + u32 both_edges;
73 72 struct mxc_gpio_reg_saved gpio_saved_reg;
74 73 bool power_off;
74 + u32 wakeup_pads;
75 75 bool is_pad_wakeup;
76 - unsigned long wakeup_pads;
77 76 u32 pad_type[32];
78 77 const struct mxc_gpio_hwdata *hwdata;
79 78 };
@@ -169,7 +168,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
169 168 int edge;
170 169 void __iomem *reg = port->base;
171 170
172 - clear_bit(gpio_idx, &port->both_edges);
171 + port->both_edges &= ~(1 << gpio_idx);
173 172 switch (type) {
174 173 case IRQ_TYPE_EDGE_RISING:
175 174 edge = GPIO_INT_RISE_EDGE;
@@ -189,7 +188,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
189 188 edge = GPIO_INT_HIGH_LEV;
190 189 pr_debug("mxc: set GPIO %d to high trigger\n", gpio_idx);
191 190 }
192 - set_bit(gpio_idx, &port->both_edges);
191 + port->both_edges |= 1 << gpio_idx;
193 192 }
194 193 break;
195 194 case IRQ_TYPE_LEVEL_LOW:
@@ -260,7 +259,7 @@ static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat)
260 259 while (irq_stat != 0) {
261 260 int irqoffset = fls(irq_stat) - 1;
262 261
263 - if (test_bit(irqoffset, &port->both_edges))
262 + if (port->both_edges & (1 << irqoffset))
264 263 mxc_flip_edge(port, irqoffset);
265 264
266 265 generic_handle_domain_irq(port->domain, irqoffset);
@@ -331,18 +330,16 @@ static int gpio_set_wake_irq(struct irq_data *d, u32 enable)
331 330 ret = enable_irq_wake(port->irq_high);
332 331 else
333 332 ret = enable_irq_wake(port->irq);
333 + port->wakeup_pads |= BIT(gpio_idx);
334 334 } else {
335 335 if (port->irq_high && (gpio_idx >= 16))
336 336 ret = disable_irq_wake(port->irq_high);
337 337 else
338 338 ret = disable_irq_wake(port->irq);
339 + port->wakeup_pads &= ~BIT(gpio_idx);
339 340 }
340 - if (ret)
341 - return ret;
342 -
343 - assign_bit(gpio_idx, &port->wakeup_pads, enable);
344 341
345 - return 0;
342 + return ret;
346 343 }
347 344
348 345 static int mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base)
@@ -477,6 +474,8 @@ static int mxc_gpio_probe(struct platform_device *pdev)
477 474 } else
478 475 port->mx_irq_handler = mx3_gpio_irq_handler;
479 476
477 + mxc_update_irq_chained_handler(port, true);
478 +
480 479 config.dev = &pdev->dev;
481 480 config.sz = 4;
482 481 config.dat = port->base + GPIO_PSR;
@@ -500,6 +499,10 @@ static int mxc_gpio_probe(struct platform_device *pdev)
500 499 else /* silence boot time warning */
501 500 port->gen_gc.gc.base = -1;
502 501
502 + err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port);
503 + if (err)
504 + goto out_bgio;
505 +
503 506 irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 32, numa_node_id());
504 507 if (irq_base < 0) {
505 508 err = irq_base;
@@ -520,19 +523,8 @@ static int mxc_gpio_probe(struct platform_device *pdev)
520 523 if (err < 0)
521 524 goto out_irqdomain_remove;
522 525
523 - /*
524 - * Register the GPIO chip last: devm_gpiochip_add_data() makes the
525 - * chip visible to consumers immediately, so the IRQ domain and
526 - * generic irq chip must be ready before any to_irq() call.
527 - */
528 - err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port);
529 - if (err)
530 - goto out_irqdomain_remove;
531 -
532 526 list_add_tail(&port->node, &mxc_gpio_ports);
533 527
534 - mxc_update_irq_chained_handler(port, true);
535 -
536 528 platform_set_drvdata(pdev, port);
537 529 pm_runtime_put_autosuspend(&pdev->dev);
538 530
modified drivers/gpio/gpio-nct6694.c
@@ -444,7 +444,7 @@ static int nct6694_gpio_probe(struct platform_device *pdev)
444 444 data->gpio.set_config = nct6694_set_config;
445 445 data->gpio.init_valid_mask = nct6694_init_valid_mask;
446 446 data->gpio.base = -1;
447 - data->gpio.can_sleep = true;
447 + data->gpio.can_sleep = false;
448 448 data->gpio.owner = THIS_MODULE;
449 449 data->gpio.ngpio = NCT6694_NR_GPIO;
450 450
modified drivers/gpio/gpiolib-kunit.c
@@ -28,8 +28,6 @@
28 28
29 29 #define GPIO_TEST_PROVIDER_NGPIO 4
30 30
31 - KUNIT_DEFINE_ACTION_WRAPPER(gpio_device_put_wrapper, gpio_device_put, struct gpio_device *);
32 -
33 31 /*
34 32 * The test provider tracks per-line direction and value so that lines can be
35 33 * driven as both inputs and outputs - this is needed to exercise input as well
@@ -772,7 +770,6 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
772 770 struct property_entry properties[2];
773 771 struct platform_device *pdev;
774 772 struct fwnode_handle *fwnode;
775 - struct gpio_device *gdev;
776 773 struct gpio_desc *desc;
777 774 bool bound = true;
778 775 int ret;
@@ -792,12 +789,10 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
792 789 wait_for_device_probe();
793 790
794 791 /* The hog must have configured the line with the expected direction. */
795 - gdev = gpio_device_find_by_label(GPIO_CONSUMER_NAME);
792 + struct gpio_device *gdev __free(gpio_device_put) =
793 + gpio_device_find_by_label(GPIO_CONSUMER_NAME);
796 794 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gdev);
797 795
798 - ret = kunit_add_action_or_reset(test, gpio_device_put_wrapper, gdev);
799 - KUNIT_ASSERT_EQ(test, ret, 0);
800 -
801 796 desc = gpio_device_get_desc(gdev, offset);
802 797 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc);
803 798
modified drivers/gpio/gpiolib-shared.c
@@ -449,14 +449,10 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
449 449 int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *fwnode,
450 450 const char *con_id, unsigned long lflags)
451 451 {
452 + const char *dev_id = dev_name(consumer);
453 + struct gpiod_lookup_table *lookup;
452 454 struct gpio_shared_entry *entry;
453 455 struct gpio_shared_ref *ref;
454 - const char *dev_id;
455 -
456 - if (!consumer)
457 - return -EOPNOTSUPP;
458 -
459 - dev_id = dev_name(consumer);
460 456
461 457 list_for_each_entry(entry, &gpio_shared_list, list) {
462 458 list_for_each_entry(ref, &entry->refs, list) {
@@ -484,22 +480,18 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
484 480 if (!key)
485 481 return -ENOMEM;
486 482
487 - struct gpiod_lookup_table *lookup __free(kfree) =
488 - kzalloc_flex(*lookup, table, 2);
483 + lookup = kzalloc_flex(*lookup, table, 2);
489 484 if (!lookup)
490 485 return -ENOMEM;
491 486
492 487 pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
493 488 dev_id, key, ref->con_id ?: "none");
494 489
495 - lookup->dev_id = kstrdup(dev_id, GFP_KERNEL);
496 - if (!lookup->dev_id)
497 - return -ENOMEM;
498 -
490 + lookup->dev_id = dev_id;
499 491 lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
500 492 ref->con_id, lflags);
501 493
502 - ref->lookup = no_free_ptr(lookup);
494 + ref->lookup = lookup;
503 495 gpiod_add_lookup_table(ref->lookup);
504 496
505 497 return 0;
@@ -619,7 +611,6 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
619 611 if (ref->lookup) {
620 612 gpiod_remove_lookup_table(ref->lookup);
621 613 kfree(ref->lookup->table[0].key);
622 - kfree(ref->lookup->dev_id);
623 614 kfree(ref->lookup);
624 615 ref->lookup = NULL;
625 616 }
modified drivers/gpio/gpiolib.c
@@ -3954,17 +3954,16 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
3954 3954 } while ((i < array_size) &&
3955 3955 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3956 3956 /* push collected bits to outputs */
3957 - ret = 0;
3958 - if (count != 0)
3957 + if (count != 0) {
3959 3958 ret = gpiochip_set_multiple(guard.gc, mask, bits);
3959 + if (ret)
3960 + return ret;
3961 + }
3960 3962
3961 3963 if (mask != fastpath_mask)
3962 3964 bitmap_free(mask);
3963 3965 if (bits != fastpath_bits)
3964 3966 bitmap_free(bits);
3965 -
3966 - if (ret)
3967 - return ret;
3968 3967 }
3969 3968 return 0;
3970 3969 }
modified drivers/spi/spi-fsl-lpspi.c
@@ -550,11 +550,8 @@ static int fsl_lpspi_target_abort(struct spi_controller *controller)
550 550 return 0;
551 551 }
552 552
553 - static int fsl_lpspi_wait_for_completion(struct spi_controller *controller)
553 + static int fsl_lpspi_wait_for_completion(struct fsl_lpspi_data *fsl_lpspi)
554 554 {
555 - struct fsl_lpspi_data *fsl_lpspi =
556 - spi_controller_get_devdata(controller);
557 -
558 555 if (fsl_lpspi->is_target) {
559 556 if (wait_for_completion_interruptible(&fsl_lpspi->xfer_done) ||
560 557 fsl_lpspi->target_aborted) {
@@ -758,11 +755,9 @@ err:
758 755 return ret;
759 756 }
760 757
761 - static int fsl_lpspi_pio_transfer(struct spi_controller *controller,
758 + static int fsl_lpspi_pio_transfer(struct fsl_lpspi_data *fsl_lpspi,
762 759 struct spi_transfer *t)
763 760 {
764 - struct fsl_lpspi_data *fsl_lpspi =
765 - spi_controller_get_devdata(controller);
766 761 int ret;
767 762
768 763 fsl_lpspi->tx_buf = t->tx_buf;
@@ -774,7 +769,7 @@ static int fsl_lpspi_pio_transfer(struct spi_controller *controller,
774 769
775 770 fsl_lpspi_write_tx_fifo(fsl_lpspi);
776 771
777 - ret = fsl_lpspi_wait_for_completion(controller);
772 + ret = fsl_lpspi_wait_for_completion(fsl_lpspi);
778 773
779 774 fsl_lpspi_reset(fsl_lpspi);
780 775
@@ -803,11 +798,9 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller,
803 798 if (fsl_lpspi->usedma)
804 799 ret = fsl_lpspi_dma_transfer(controller, fsl_lpspi, t);
805 800 else
806 - ret = fsl_lpspi_pio_transfer(controller, t);
807 - if (ret < 0)
808 - return ret;
801 + ret = fsl_lpspi_pio_transfer(fsl_lpspi, t);
809 802
810 - return 0;
803 + return ret;
811 804 }
812 805
813 806 static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id)
modified drivers/spi/spi-imx.c
@@ -1578,11 +1578,13 @@ static int spi_imx_dma_tx_data_handle(struct spi_imx_data *spi_imx,
1578 1578 dma_data->dma_len = ALIGN(dma_data->data_len, BYTES_PER_32BITS_WORD);
1579 1579 }
1580 1580
1581 - dma_data->dma_tx_buf = kzalloc(dma_data->dma_len, GFP_KERNEL);
1581 + dma_data->dma_tx_buf = kzalloc(DMA_CACHE_ALIGNED_LEN(dma_data->dma_len),
1582 + GFP_KERNEL);
1582 1583 if (!dma_data->dma_tx_buf)
1583 1584 return -ENOMEM;
1584 1585
1585 - dma_data->dma_rx_buf = kzalloc(dma_data->dma_len, GFP_KERNEL);
1586 + dma_data->dma_rx_buf = kzalloc(DMA_CACHE_ALIGNED_LEN(dma_data->dma_len),
1587 + GFP_KERNEL);
1586 1588 if (!dma_data->dma_rx_buf) {
1587 1589 kfree(dma_data->dma_tx_buf);
1588 1590 return -ENOMEM;
@@ -1920,7 +1922,8 @@ static int spi_imx_dma_package_transfer(struct spi_imx_data *spi_imx,
1920 1922
1921 1923 /* Trim the DMA RX buffer and copy the actual data to rx_buf */
1922 1924 dma_sync_single_for_cpu(controller->dma_rx->device->dev, dma_data->dma_rx_addr,
1923 - dma_data->dma_len, DMA_FROM_DEVICE);
1925 + DMA_CACHE_ALIGNED_LEN(dma_data->dma_len),
1926 + DMA_FROM_DEVICE);
1924 1927 spi_imx_dma_rx_data_handle(spi_imx, dma_data, transfer->rx_buf + spi_imx->rx_offset,
1925 1928 word_delay);
1926 1929 spi_imx->rx_offset += dma_data->data_len;
modified drivers/spi/spi-tegra114.c
@@ -859,6 +859,13 @@ static u32 tegra_spi_setup_transfer_one(struct spi_device *spi,
859 859 command1 |= SPI_BIT_LENGTH(bits_per_word - 1);
860 860 }
861 861
862 + /*
863 + * Re-assert the CS GPIO for every transfer: transfer_end() drops it
864 + * on cs_change, and the assert above only covers is_first_of_msg.
865 + */
866 + if (spi_get_csgpiod(spi, 0))
867 + gpiod_set_value(spi_get_csgpiod(spi, 0), 1);
868 +
862 869 return command1;
863 870 }
864 871
modified tools/gpio/Makefile
@@ -7,13 +7,7 @@ bindir ?= /usr/bin
7 7 # isn't set and when invoked from selftests build, where srctree
8 8 # is set to ".". building_out_of_srctree is undefined for in srctree
9 9 # builds
10 - ifeq ($(srctree),)
11 - update_srctree := 1
12 - endif
13 10 ifndef building_out_of_srctree
14 - update_srctree := 1
15 - endif
16 - ifeq ($(update_srctree),1)
17 11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
18 12 srctree := $(patsubst %/,%,$(dir $(srctree)))
19 13 endif