1. 02 9月, 2020 1 次提交
  2. 28 6月, 2020 2 次提交
  3. 27 12月, 2019 2 次提交
    • C
      spi: Fix zero length xfer bug · 3376b393
      Chris Lesiak 提交于
      [ Upstream commit 5442dcaa0d90fc376bdfc179a018931a8f43dea4 ]
      
      This fixes a bug for messages containing both zero length and
      unidirectional xfers.
      
      The function spi_map_msg will allocate dummy tx and/or rx buffers
      for use with unidirectional transfers when the hardware can only do
      a bidirectional transfer.  That dummy buffer will be used in place
      of a NULL buffer even when the xfer length is 0.
      
      Then in the function __spi_map_msg, if he hardware can dma,
      the zero length xfer will have spi_map_buf called on the dummy
      buffer.
      
      Eventually, __sg_alloc_table is called and returns -EINVAL
      because nents == 0.
      
      This fix prevents the error by not using the dummy buffer when
      the xfer length is zero.
      Signed-off-by: NChris Lesiak <chris.lesiak@licor.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      3376b393
    • J
      spi: add ACPI support for SPI controller chip select lines(cs-gpios) · 70866373
      Jay Fang 提交于
      euler inclusion
      category: feature (SPI ACPI for Hi1620)
      bugzilla: 5443
      CVE: NA
      
      TPM chip on D06 is SPI based, so we need to add SPI ACPI support
      for Hi1620.
      
      Two patches already merged for 4.21, but the core support for spi
      has another patchset needs lots of refactor, so just use the patch
      from Fang Jian to enable this feature on 4.19
      
      [PATCH 1/4] spi: dw-mmio: add ACPI support
      [PATCH 2/4] ACPI / APD: Add clock frequency for Hisilicon Hip08 SPI controller
      [PATCH 3/4] spi: add ACPI support for SPI controller chip select lines(cs-gpios)
      [PATCH 4/4] hulk_defconfig: ensble SPI designware driver for Hi1620
      -----------------------------------------
      
      This will also allow to use cs-gpios for chip select in ACPI code
      with no modification in the driver binding, like it be used in DT.
      We could share almost all of the code with the DT path.
      Signed-off-by: NJay Fang <f.fangjian@huawei.com>
      Signed-off-by: NHanjun Guo <guohanjun@huawei.com>
      Reviewed-by: NYang Yingliang <yangyingliang@huawei.com>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      70866373
  4. 29 8月, 2018 1 次提交
  5. 15 8月, 2018 1 次提交
  6. 13 6月, 2018 1 次提交
    • K
      treewide: devm_kzalloc() -> devm_kcalloc() · a86854d0
      Kees Cook 提交于
      The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
      This patch replaces cases of:
      
              devm_kzalloc(handle, a * b, gfp)
      
      with:
              devm_kcalloc(handle, a * b, gfp)
      
      as well as handling cases of:
      
              devm_kzalloc(handle, a * b * c, gfp)
      
      with:
      
              devm_kzalloc(handle, array3_size(a, b, c), gfp)
      
      as it's slightly less ugly than:
      
              devm_kcalloc(handle, array_size(a, b), c, gfp)
      
      This does, however, attempt to ignore constant size factors like:
      
              devm_kzalloc(handle, 4 * 1024, gfp)
      
      though any constants defined via macros get caught up in the conversion.
      
      Any factors with a sizeof() of "unsigned char", "char", and "u8" were
      dropped, since they're redundant.
      
      Some manual whitespace fixes were needed in this patch, as Coccinelle
      really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
      
      The Coccinelle script used for this was:
      
      // Fix redundant parens around sizeof().
      @@
      expression HANDLE;
      type TYPE;
      expression THING, E;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(sizeof(TYPE)) * E
      +	sizeof(TYPE) * E
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(sizeof(THING)) * E
      +	sizeof(THING) * E
        , ...)
      )
      
      // Drop single-byte sizes and redundant parens.
      @@
      expression HANDLE;
      expression COUNT;
      typedef u8;
      typedef __u8;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * (COUNT)
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(__u8) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(char) * COUNT
      +	COUNT
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(unsigned char) * COUNT
      +	COUNT
        , ...)
      )
      
      // 2-factor product with sizeof(type/expression) and identifier or constant.
      @@
      expression HANDLE;
      type TYPE;
      expression THING;
      identifier COUNT_ID;
      constant COUNT_CONST;
      @@
      
      (
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_ID)
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_ID
      +	COUNT_ID, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * COUNT_CONST
      +	COUNT_CONST, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_ID)
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_ID
      +	COUNT_ID, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (COUNT_CONST)
      +	COUNT_CONST, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * COUNT_CONST
      +	COUNT_CONST, sizeof(THING)
        , ...)
      )
      
      // 2-factor product, only identifiers.
      @@
      expression HANDLE;
      identifier SIZE, COUNT;
      @@
      
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	SIZE * COUNT
      +	COUNT, SIZE
        , ...)
      
      // 3-factor product with 1 sizeof(type) or sizeof(expression), with
      // redundant parens removed.
      @@
      expression HANDLE;
      expression THING;
      identifier STRIDE, COUNT;
      type TYPE;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(TYPE))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * (COUNT) * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * (STRIDE)
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING) * COUNT * STRIDE
      +	array3_size(COUNT, STRIDE, sizeof(THING))
        , ...)
      )
      
      // 3-factor product with 2 sizeof(variable), with redundant parens removed.
      @@
      expression HANDLE;
      expression THING1, THING2;
      identifier COUNT;
      type TYPE1, TYPE2;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(TYPE2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(THING1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(THING1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * COUNT
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	sizeof(TYPE1) * sizeof(THING2) * (COUNT)
      +	array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
        , ...)
      )
      
      // 3-factor product, only identifiers, with redundant parens removed.
      @@
      expression HANDLE;
      identifier STRIDE, SIZE, COUNT;
      @@
      
      (
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * STRIDE * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(COUNT) * (STRIDE) * (SIZE)
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	COUNT * STRIDE * SIZE
      +	array3_size(COUNT, STRIDE, SIZE)
        , ...)
      )
      
      // Any remaining multi-factor products, first at least 3-factor products,
      // when they're not all constants...
      @@
      expression HANDLE;
      expression E1, E2, E3;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * E3
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	(E1) * (E2) * (E3)
      +	array3_size(E1, E2, E3)
        , ...)
      |
        devm_kzalloc(HANDLE,
      -	E1 * E2 * E3
      +	array3_size(E1, E2, E3)
        , ...)
      )
      
      // And then all remaining 2 factors products when they're not all constants,
      // keeping sizeof() as the second factor argument.
      @@
      expression HANDLE;
      expression THING, E1, E2;
      type TYPE;
      constant C1, C2, C3;
      @@
      
      (
        devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
      |
        devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
      |
        devm_kzalloc(HANDLE, C1 * C2, ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * (E2)
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(TYPE) * E2
      +	E2, sizeof(TYPE)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * (E2)
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	sizeof(THING) * E2
      +	E2, sizeof(THING)
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * E2
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	(E1) * (E2)
      +	E1, E2
        , ...)
      |
      - devm_kzalloc
      + devm_kcalloc
        (HANDLE,
      -	E1 * E2
      +	E1, E2
        , ...)
      )
      Signed-off-by: NKees Cook <keescook@chromium.org>
      a86854d0
  7. 21 5月, 2018 1 次提交
  8. 15 5月, 2018 1 次提交
  9. 11 5月, 2018 2 次提交
  10. 26 4月, 2018 1 次提交
  11. 23 4月, 2018 2 次提交
  12. 20 3月, 2018 1 次提交
    • J
      spi: Fix unregistration of controller with fixed SPI bus number · 613bd1ea
      Jarkko Nikula 提交于
      Commit 9b61e302 (spi: Pick spi bus number from Linux idr or spi alias)
      ceased to unregister SPI buses with fixed bus numbers. Moreover this is
      visible only if CONFIG_SPI_DEBUG=y is set or when trying to re-register
      the same SPI controller.
      
      rmmod spi_pxa2xx_platform (with CONFIG_SPI_DEBUG=y):
      [   26.788362] spi_master spi1: attempting to delete unregistered controller [spi1]
      
      modprobe spi_pxa2xx_platform:
      [   37.883137] sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:19.0/pxa2xx-spi.12/spi_master/spi1'
      [   37.894984] CPU: 1 PID: 1467 Comm: modprobe Not tainted 4.16.0-rc4+ #21
      [   37.902384] Call Trace:
      ...
      [   38.122680] kobject_add_internal failed for spi1 with -EEXIST, don't try to register things with the same name in the same directory.
      [   38.136154] WARNING: CPU: 1 PID: 1467 at lib/kobject.c:238 kobject_add_internal+0x2a5/0x2f0
      ...
      [   38.513817] pxa2xx-spi pxa2xx-spi.12: problem registering spi master
      [   38.521036] pxa2xx-spi: probe of pxa2xx-spi.12 failed with error -17
      
      Fix this by not returning immediately from spi_unregister_controller() if
      idr_find() doesn't find controller with given ID/bus number. It finds
      only those controllers that were registered with dynamic SPI bus
      numbers. Only conditional cleanup between dynamic and fixed bus numbers
      is to remove allocated IDR.
      
      Fixes: 9b61e302 (spi: Pick spi bus number from Linux idr or spi alias)
      Cc: stable@vger.kernel.org
      Signed-off-by: NJarkko Nikula <jarkko.nikula@linux.intel.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      613bd1ea
  13. 03 3月, 2018 1 次提交
    • M
      spi: Fix scatterlist elements size in spi_map_buf · ce99319a
      Maxime Chevallier 提交于
      When SPI transfers can be offloaded using DMA, the SPI core need to
      build a scatterlist to make sure that the buffer to be transferred is
      dma-able.
      
      This patch fixes the scatterlist entry size computation in the case
      where the maximum acceptable scatterlist entry supported by the DMA
      controller is less than PAGE_SIZE, when the buffer is vmalloced.
      
      For each entry, the actual size is given by the minimum between the
      desc_len (which is the max buffer size supported by the DMA controller)
      and the remaining buffer length until we cross a page boundary.
      
      Fixes: 65598c13 ("spi: Fix per-page mapping of unaligned vmalloc-ed buffer")
      Signed-off-by: NMaxime Chevallier <maxime.chevallier@bootlin.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      Cc: stable@vger.kernel.org
      ce99319a
  14. 03 11月, 2017 1 次提交
  15. 31 10月, 2017 2 次提交
  16. 17 10月, 2017 1 次提交
  17. 18 8月, 2017 1 次提交
  18. 16 8月, 2017 1 次提交
  19. 07 8月, 2017 1 次提交
  20. 04 8月, 2017 1 次提交
  21. 26 7月, 2017 1 次提交
  22. 19 7月, 2017 1 次提交
  23. 14 6月, 2017 1 次提交
    • G
      spi: Generalize SPI "master" to "controller" · 8caab75f
      Geert Uytterhoeven 提交于
      Now struct spi_master is used for both SPI master and slave controllers,
      it makes sense to rename it to struct spi_controller, and replace
      "master" by "controller" where appropriate.
      
      For now this conversion is done for SPI core infrastructure only.
      Wrappers are provided for backwards compatibility, until all SPI drivers
      have been converted.
      
      Noteworthy details:
        - SPI_MASTER_GPIO_SS is retained, as it only makes sense for SPI
          master controllers,
        - spi_busnum_to_master() is retained, as it looks up masters only,
        - A new field spi_device.controller is added, but spi_device.master is
          retained for compatibility (both are always initialized by
          spi_alloc_device()),
        - spi_flash_read() is used by SPI masters only.
      Signed-off-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      8caab75f
  24. 26 5月, 2017 1 次提交
    • G
      spi: core: Add support for registering SPI slave controllers · 6c364062
      Geert Uytterhoeven 提交于
      Add support for registering SPI slave controllers using the existing SPI
      master framework:
        - SPI slave controllers must use spi_alloc_slave() instead of
          spi_alloc_master(), and should provide an additional callback
          "slave_abort" to abort an ongoing SPI transfer request,
        - SPI slave controllers are added to a new "spi_slave" device class,
        - SPI slave handlers can be bound to the SPI slave device represented
          by an SPI slave controller using a DT child node named "slave",
        - Alternatively, (un)binding an SPI slave handler to the SPI slave
          device represented by an SPI slave controller can be done by
          (un)registering the slave device through a sysfs virtual file named
          "slave".
      
      From the point of view of an SPI slave protocol handler, an SPI slave
      controller looks almost like an ordinary SPI master controller. The only
      exception is that a transfer request will block on the remote SPI
      master, and may be cancelled using spi_slave_abort().
      Signed-off-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      6c364062
  25. 14 5月, 2017 2 次提交
  26. 22 4月, 2017 1 次提交
  27. 19 4月, 2017 1 次提交
    • H
      spi: double time out tolerance · 833bfade
      Hauke Mehrtens 提交于
      The generic SPI code calculates how long the issued transfer would take
      and adds 100ms in addition to the timeout as tolerance. On my 500 MHz
      Lantiq Mips SoC I am getting timeouts from the SPI like this when the
      system boots up:
      
      m25p80 spi32766.4: SPI transfer timed out
      blk_update_request: I/O error, dev mtdblock3, sector 2
      SQUASHFS error: squashfs_read_data failed to read block 0x6e
      
      After increasing the tolerance for the timeout to 200ms I haven't seen
      these SPI transfer time outs any more.
      The Lantiq SPI driver in use here has an extra work queue in between,
      which gets triggered when the controller send the last word and the
      hardware FIFOs used for reading and writing are only 8 words long.
      Signed-off-by: NHauke Mehrtens <hauke@hauke-m.de>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      833bfade
  28. 06 3月, 2017 2 次提交
  29. 02 3月, 2017 1 次提交
  30. 07 2月, 2017 1 次提交
  31. 01 2月, 2017 2 次提交
    • J
      spi: fix device-node leaks · 8324147f
      Johan Hovold 提交于
      Make sure to release the device-node reference taken in
      of_register_spi_device() on errors and when deregistering the device.
      
      Fixes: 284b0189 ("spi: Add OF binding support for SPI busses")
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      8324147f
    • D
      spi: When no dma_chan map buffers with spi_master's parent · 88b0aa54
      Daniel Kurtz 提交于
      Back before commit 1dccb598 ("arm64: simplify dma_get_ops"), for
      arm64, devices for which dma_ops were not explicitly set were automatically
      configured to use swiotlb_dma_ops, since this was hard-coded as the
      global "dma_ops" in arm64_dma_init().
      
      Now that global "dma_ops" has been removed, all devices much have their
      dma_ops explicitly set by a call to arch_setup_dma_ops(), otherwise the
      device is assigned dummy_dma_ops, and thus calls to map_sg for such a
      device will fail (return 0).
      
      Mediatek SPI uses DMA but does not use a dma channel.  Support for this
      was added by commit c37f45b5 ("spi: support spi without dma channel
      to use can_dma()"), which uses the master_spi dev to DMA map buffers.
      
      The master_spi device is not a platform device, rather it is created
      in spi_alloc_device(), and therefore its dma_ops are never set.
      
      Therefore, when the mediatek SPI driver when it does DMA (for large SPI
      transactions > 32 bytes), SPI will use spi_map_buf()->dma_map_sg() to
      map the buffer for use in DMA.  But dma_map_sg()->dma_map_sg_attrs() returns
      0, because ops->map_sg is dummy_dma_ops->__dummy_map_sg, and hence
      spi_map_buf() returns -ENOMEM (-12).
      
      Fix this by using the real spi_master's parent device which should be a
      real physical device with DMA properties.
      Signed-off-by: NDaniel Kurtz <djkurtz@chromium.org>
      Fixes: c37f45b5 ("spi: support spi without dma channel to use can_dma()")
      Cc: Leilk Liu <leilk.liu@mediatek.com>
      Signed-off-by: NMark Brown <broonie@kernel.org>
      88b0aa54
  32. 18 1月, 2017 1 次提交