07 Jun, 2018

3 commits

  • Pull overflow updates from Kees Cook:
    "This adds the new overflow checking helpers and adds them to the
    2-factor argument allocators. And this adds the saturating size
    helpers and does a treewide replacement for the struct_size() usage.
    Additionally this adds the overflow testing modules to make sure
    everything works.

    I'm still working on the treewide replacements for allocators with
    "simple" multiplied arguments:

    *alloc(a * b, ...) -> *alloc_array(a, b, ...)

    and

    *zalloc(a * b, ...) -> *calloc(a, b, ...)

    as well as the more complex cases, but that's separable from this
    portion of the series. I expect to have the rest sent before -rc1
    closes; there are a lot of messy cases to clean up.

    Summary:

    - Introduce arithmetic overflow test helper functions (Rasmus)

    - Use overflow helpers in 2-factor allocators (Kees, Rasmus)

    - Introduce overflow test module (Rasmus, Kees)

    - Introduce saturating size helper functions (Matthew, Kees)

    - Treewide use of struct_size() for allocators (Kees)"

    * tag 'overflow-v4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
    treewide: Use struct_size() for devm_kmalloc() and friends
    treewide: Use struct_size() for vmalloc()-family
    treewide: Use struct_size() for kmalloc()-family
    device: Use overflow helpers for devm_kmalloc()
    mm: Use overflow helpers in kvmalloc()
    mm: Use overflow helpers in kmalloc_array*()
    test_overflow: Add memory allocation overflow tests
    overflow.h: Add allocation size calculation helpers
    test_overflow: Report test failures
    test_overflow: macrofy some more, do more tests for free
    lib: add runtime test of check_*_overflow functions
    compiler.h: enable builtin overflow checkers and add fallback code

    Linus Torvalds
     
  • Replaces open-coded struct size calculations with struct_size() for
    devm_*, f2fs_*, and sock_* allocations. Automatically generated (and
    manually adjusted) from the following Coccinelle script:

    // Direct reference to struct field.
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
    + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

    // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
    + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

    // Same pattern, but can't trivially locate the trailing element name,
    // or variable name.
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    expression SOMETHING, COUNT, ELEMENT;
    @@

    - alloc(HANDLE, sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
    + alloc(HANDLE, CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

    Signed-off-by: Kees Cook

    Kees Cook
     
  • One of the more common cases of allocation size calculations is finding
    the size of a structure that has a zero-sized array at the end, along
    with memory for some number of elements for that array. For example:

    struct foo {
    int stuff;
    void *entry[];
    };

    instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

    Instead of leaving these open-coded and prone to type mistakes, we can
    now use the new struct_size() helper:

    instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

    This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
    uses. It was done via automatic conversion with manual review for the
    "CHECKME" non-standard cases noted below, using the following Coccinelle
    script:

    // pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
    // sizeof *pkey_cache->table, GFP_KERNEL);
    @@
    identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
    + alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

    // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
    @@
    identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
    + alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

    // Same pattern, but can't trivially locate the trailing element name,
    // or variable name.
    @@
    identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
    expression GFP;
    expression SOMETHING, COUNT, ELEMENT;
    @@

    - alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
    + alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

    Signed-off-by: Kees Cook

    Kees Cook
     

30 Apr, 2018

1 commit

  • The PCIe-IDIO-24 features 8 bits of TTL GPIO which may be configured for
    output or input. This patch fixes an off-by-one error in the loop
    conditional for the get_multiple callback so that the TTL GPIO are
    handled.

    Fixes: ca37081595a2 ("gpio: pcie-idio-24: Implement get_multiple/set_multiple callbacks")
    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     

27 Apr, 2018

3 commits


26 Apr, 2018

2 commits

  • If the main loop in linehandle_create() encounters an error, it
    unwinds completely by freeing all previously requested GPIO
    descriptors. However, if the error occurs in the beginning of
    the loop before that GPIO is requested, then the exit code
    attempts to free a null descriptor. If extrachecks is enabled,
    gpiod_free() triggers a WARN_ON.

    Instead, keep a separate count of legitimate GPIOs so that only
    those are freed.

    Cc: stable@vger.kernel.org
    Fixes: d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")
    Reviewed-by: Bjorn Andersson
    Signed-off-by: Timur Tabi
    Signed-off-by: Linus Walleij

    Timur Tabi
     
  • The unmask function disables all interrupts in a bank when unmasking an
    interrupt. Only disable the given interrupt.

    Cc: stable@vger.kernel.org
    Signed-off-by: Govert Overgaauw
    Signed-off-by: Linus Walleij

    Govert Overgaauw
     

06 Apr, 2018

2 commits

  • Pull DeviceTree updates from Rob Herring:

    - Sync dtc to upstream version v1.4.6-9-gaadd0b65c987. This adds a
    bunch more warnings (hidden behind W=1).

    - Build dtc lexer and parser files instead of using shipped versions.

    - Rework overlay apply API to take an FDT as input and apply overlays
    in a single step.

    - Add a phandle lookup cache. This improves boot time by hundreds of
    msec on systems with large DT.

    - Add trivial mcp4017/18/19 potentiometers bindings.

    - Remove VLA stack usage in DT code.

    * tag 'devicetree-for-4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux: (26 commits)
    of: unittest: fix an error code in of_unittest_apply_overlay()
    of: unittest: move misplaced function declaration
    of: unittest: Remove VLA stack usage
    of: overlay: Fix forgotten reference to of_overlay_apply()
    of: Documentation: Fix forgotten reference to of_overlay_apply()
    of: unittest: local return value variable related cleanups
    of: unittest: remove unneeded local return value variables
    dt-bindings: trivial: add various mcp4017/18/19 potentiometers
    of: unittest: fix an error test in of_unittest_overlay_8()
    of: cache phandle nodes to reduce cost of of_find_node_by_phandle()
    dt-bindings: rockchip-dw-mshc: use consistent clock names
    MAINTAINERS: Add linux/of_*.h headers to appropriate subsystems
    scripts: turn off some new dtc warnings by default
    scripts/dtc: Update to upstream version v1.4.6-9-gaadd0b65c987
    scripts/dtc: generate lexer and parser during build instead of shipping
    powerpc: boot: add strrchr function
    of: overlay: do not include path in full_name of added nodes
    of: unittest: clean up changeset test
    arm64/efi: Make strrchr() available to the EFI namespace
    ARM: boot: add strrchr function
    ...

    Linus Torvalds
     
  • Pull GPIO updates from Linus Walleij:
    "This is the bulk of GPIO changes for the v4.17 kernel cycle:

    New drivers:

    - Nintendo Wii GameCube GPIO, known as "Hollywood"

    - Raspberry Pi mailbox service GPIO expander

    - Spreadtrum main SC9860 SoC and IEC GPIO controllers.

    Improvements:

    - Implemented .get_multiple() callback for most of the
    high-performance industrial GPIO cards for the ISA bus.

    - ISA GPIO drivers now select the ISA_BUS_API instead of depending on
    it. This is merged with the same pattern for all the ISA drivers
    and some other Kconfig cleanups related to this.

    Cleanup:

    - Delete the TZ1090 GPIO drivers following the deletion of this SoC
    from the ARM tree.

    - Move the documentation over to driver-api to conform with the rest
    of the kernel documentation build.

    - Continue to make the GPIO drivers include only
    and not the too broad that we
    want to get rid of.

    - Managed to remove VLA allocation from two drivers pending more
    fixes in this area for the next merge window.

    - Misc janitorial fixes"

    * tag 'gpio-v4.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (77 commits)
    gpio: Add Spreadtrum PMIC EIC driver support
    gpio: Add Spreadtrum EIC driver support
    dt-bindings: gpio: Add Spreadtrum EIC controller documentation
    gpio: ath79: Fix potential NULL dereference in ath79_gpio_probe()
    pinctrl: qcom: Don't allow protected pins to be requested
    gpiolib: Support 'gpio-reserved-ranges' property
    gpiolib: Change bitmap allocation to kmalloc_array
    gpiolib: Extract mask allocation into subroutine
    dt-bindings: gpio: Add a gpio-reserved-ranges property
    gpio: mockup: fix a potential crash when creating debugfs entries
    gpio: pca953x: add compatibility for pcal6524 and pcal9555a
    gpio: dwapb: Add support for a bus clock
    gpio: Remove VLA from xra1403 driver
    gpio: Remove VLA from MAX3191X driver
    gpio: ws16c48: Implement get_multiple callback
    gpio: gpio-mm: Implement get_multiple callback
    gpio: 104-idi-48: Implement get_multiple callback
    gpio: 104-dio-48e: Implement get_multiple callback
    gpio: pcie-idio-24: Implement get_multiple/set_multiple callbacks
    gpio: pci-idio-16: Implement get_multiple callback
    ...

    Linus Torvalds
     

03 Apr, 2018

1 commit

  • Pul removal of obsolete architecture ports from Arnd Bergmann:
    "This removes the entire architecture code for blackfin, cris, frv,
    m32r, metag, mn10300, score, and tile, including the associated device
    drivers.

    I have been working with the (former) maintainers for each one to
    ensure that my interpretation was right and the code is definitely
    unused in mainline kernels. Many had fond memories of working on the
    respective ports to start with and getting them included in upstream,
    but also saw no point in keeping the port alive without any users.

    In the end, it seems that while the eight architectures are extremely
    different, they all suffered the same fate: There was one company in
    charge of an SoC line, a CPU microarchitecture and a software
    ecosystem, which was more costly than licensing newer off-the-shelf
    CPU cores from a third party (typically ARM, MIPS, or RISC-V). It
    seems that all the SoC product lines are still around, but have not
    used the custom CPU architectures for several years at this point. In
    contrast, CPU instruction sets that remain popular and have actively
    maintained kernel ports tend to all be used across multiple licensees.

    [ See the new nds32 port merged in the previous commit for the next
    generation of "one company in charge of an SoC line, a CPU
    microarchitecture and a software ecosystem" - Linus ]

    The removal came out of a discussion that is now documented at
    https://lwn.net/Articles/748074/. Unlike the original plans, I'm not
    marking any ports as deprecated but remove them all at once after I
    made sure that they are all unused. Some architectures (notably tile,
    mn10300, and blackfin) are still being shipped in products with old
    kernels, but those products will never be updated to newer kernel
    releases.

    After this series, we still have a few architectures without mainline
    gcc support:

    - unicore32 and hexagon both have very outdated gcc releases, but the
    maintainers promised to work on providing something newer. At least
    in case of hexagon, this will only be llvm, not gcc.

    - openrisc, risc-v and nds32 are still in the process of finishing
    their support or getting it added to mainline gcc in the first
    place. They all have patched gcc-7.3 ports that work to some
    degree, but complete upstream support won't happen before gcc-8.1.
    Csky posted their first kernel patch set last week, their situation
    will be similar

    [ Palmer Dabbelt points out that RISC-V support is in mainline gcc
    since gcc-7, although gcc-7.3.0 is the recommended minimum - Linus ]"

    This really says it all:

    2498 files changed, 95 insertions(+), 467668 deletions(-)

    * tag 'arch-removal' of git://git.kernel.org/pub/scm/linux/kernel/git/arnd/asm-generic: (74 commits)
    MAINTAINERS: UNICORE32: Change email account
    staging: iio: remove iio-trig-bfin-timer driver
    tty: hvc: remove tile driver
    tty: remove bfin_jtag_comm and hvc_bfin_jtag drivers
    serial: remove tile uart driver
    serial: remove m32r_sio driver
    serial: remove blackfin drivers
    serial: remove cris/etrax uart drivers
    usb: Remove Blackfin references in USB support
    usb: isp1362: remove blackfin arch glue
    usb: musb: remove blackfin port
    usb: host: remove tilegx platform glue
    pwm: remove pwm-bfin driver
    i2c: remove bfin-twi driver
    spi: remove blackfin related host drivers
    watchdog: remove bfin_wdt driver
    can: remove bfin_can driver
    mmc: remove bfin_sdh driver
    input: misc: remove blackfin rotary driver
    input: keyboard: remove bf54x driver
    ...

    Linus Torvalds
     

27 Mar, 2018

12 commits

  • The Spreadtrum PMIC EIC controller contains only one bank of debounce EIC,
    and this bank contains 16 EICs. Each EIC can only be used as input mode,
    as well as supporting the debounce and the capability to trigger interrupts
    when detecting input signals.

    Signed-off-by: Baolin Wang
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Linus Walleij

    Baolin Wang
     
  • The Spreadtrum digital-chip EIC controller has 4 sub-modules: debounce EIC,
    latch EIC, async EIC and sync EIC, and each sub-module can has multiple
    banks and each bank contains 8 EICs.

    Each EIC can only be used as input mode, and has the capability to trigger
    interrupts when detecting input signals.

    Signed-off-by: Baolin Wang
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Linus Walleij

    Baolin Wang
     
  • platform_get_resource() may return NULL, add proper
    check to avoid potential NULL dereferencing.

    This is detected by Coccinelle semantic patch.

    @@
    expression pdev, res, n, t, e, e1, e2;
    @@

    res = platform_get_resource(pdev, t, n);
    + if (!res)
    + return -EINVAL;
    ... when != res == NULL
    e = devm_ioremap(e1, res->start, e2);

    Signed-off-by: Wei Yongjun
    [albeu@free.fr: Fixed patch to apply on current tree]
    Signed-off-by: Alban Bedel
    Signed-off-by: Linus Walleij

    Wei Yongjun
     
  • Linus Walleij
     
  • Some qcom platforms make some GPIOs or pins unavailable for use by
    non-secure operating systems, and thus reading or writing the registers
    for those pins will cause access control issues. Add support for a DT
    property to describe the set of GPIOs that are available for use so that
    higher level OSes are able to know what pins to avoid reading/writing.
    Non-DT platforms can add support by directly updating the
    chip->valid_mask.

    Signed-off-by: Stephen Boyd
    Signed-off-by: Stephen Boyd
    Tested-by: Timur Tabi
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Linus Walleij

    Stephen Boyd
     
  • We don't need to clear out these bits when we set them immediately
    after. Use kmalloc_array() to skip clearing the bits.

    Suggested-by: Andy Shevchenko
    Signed-off-by: Stephen Boyd
    Tested-by: Timur Tabi
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Linus Walleij

    Stephen Boyd
     
  • We're going to use similar code to allocate and set all the bits in a
    mask for valid gpios to use. Extract the code from the irqchip version
    so it can be reused.

    Signed-off-by: Stephen Boyd
    Tested-by: Timur Tabi
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Linus Walleij

    Stephen Boyd
     
  • If we failed to create the top debugfs directory, we must not try to
    create the child nodes. We currently only check if gpio_mockup_dbg_dir
    is not NULL, but it can also contain an errno if debugfs is disabled
    in build options. Use IS_ERR_OR_NULL() instead.

    Signed-off-by: Bartosz Golaszewski
    Signed-off-by: Linus Walleij

    Bartosz Golaszewski
     
  • The Pyra-Handheld originally used the tca6424 but recently we have
    replaced it by the pin and package compatible pcal6524. So let's
    add this to the bindings and the driver.

    And while we are at it, the pcal9555a does not have a compatible entry
    either but is already supported by the device id table.

    Signed-off-by: H. Nikolaus Schaller
    Reviewed-by: Rob Herring
    Signed-off-by: Linus Walleij

    H. Nikolaus Schaller
     
  • Enable an optional bus clock provided by DT.

    Signed-off-by: Phil Edworthy
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Linus Walleij

    Phil Edworthy
     
  • The new challenge is to remove VLAs from the kernel
    (see https://lkml.org/lkml/2018/3/7/621)

    This patch replaces a VLA with an appropriate call to kmalloc_array.

    Signed-off-by: Laura Abbott
    Reviewed-by: Nandor Han
    Signed-off-by: Linus Walleij

    Laura Abbott
     
  • The new challenge is to remove VLAs from the kernel
    (see https://lkml.org/lkml/2018/3/7/621)

    This patch replaces several a VLA with an appropriate call to
    kmalloc_array.

    Signed-off-by: Laura Abbott
    Reviewed-and-tested-by: Lukas Wunner
    Signed-off-by: Linus Walleij

    Laura Abbott
     

26 Mar, 2018

8 commits

  • The cris architecture is getting removed, so we no longer need the
    etraxfs driver.

    Signed-off-by: Arnd Bergmann

    Arnd Bergmann
     
  • The WinSystems WS16C48 device provides 48 lines of digital I/O accessed
    via six 8-bit ports. Since eight input lines are acquired on a single
    port input read, the WS16C48 GPIO driver may improve multiple input
    reads by utilizing a get_multiple callback. This patch implements the
    ws16c48_gpio_get_multiple function which serves as the respective
    get_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     
  • The Diamond Systems GPIO-MM series of devices contain two 82C55A
    devices, which each feature three 8-bit ports of I/O. Since eight input
    lines are acquired on a single port input read, the GPIO-MM GPIO driver
    may improve multiple input reads by utilizing a get_multiple callback.
    This patch implements the gpiomm_gpio_get_multiple function which serves
    as the respective get_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     
  • The ACCES I/O 104-IDI-48 series of devices provides 48
    optically-isolated inputs accessed via six 8-bit ports. Since eight
    input lines are acquired on a single port input read, the 104-IDI-48
    GPIO driver may improve multiple input reads by utilizing a get_multiple
    callback. This patch implements the idi_48_gpio_get_multiple function
    which serves as the respective get_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     
  • The ACCES I/O 104-DIO-48E series of devices contain two Programmable
    Peripheral Interface (PPI) chips of type 82C55, which each feature three
    8-bit ports of I/O. Since eight input lines are acquired on a single
    port input read, the 104-DIO-48E GPIO driver may improve multiple input
    reads by utilizing a get_multiple callback. This patch implements the
    dio48e_gpio_get_multiple function which serves as the respective
    get_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     
  • The ACCES I/O PCIe-IDIO-24 series of devices provides 24
    optically-isolated digital I/O accessed via six 8-bit ports. Since eight
    input lines are acquired on a single port input read -- and similarly
    eight output lines are set on a single port output write -- the
    PCIe-IDIO-24 GPIO driver may improve multiple I/O reads/writes by
    utilizing a get_multiple/set_multiple callbacks. This patch implements
    the idio_24_gpio_get_multiple function which serves as the respective
    get_multiple callback, and implements the idio_24_gpio_set_multiple
    function which serves as the respective set_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     
  • The ACCES I/O PCI-IDIO-16 series of devices provides 16
    optically-isolated digital inputs accessed via two 8-bit ports. Since
    eight input lines are acquired on a single port input read, the
    PCI-IDIO-16 GPIO driver may improve multiple input reads by utilizing a
    get_multiple callback. This patch implements the
    idio_16_gpio_get_multiple function which serves as the respective
    get_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     
  • The ACCES I/O 104-IDIO-16 series of devices provides 16
    optically-isolated digital inputs accessed via two 8-bit ports. Since
    eight input lines are acquired on a single port input read, the
    104-IDIO-16 GPIO driver may improve multiple input reads by utilizing a
    get_multiple callback. This patch implements the
    idio_16_gpio_get_multiple function which serves as the respective
    get_multiple callback.

    Signed-off-by: William Breathitt Gray
    Signed-off-by: Linus Walleij

    William Breathitt Gray
     

19 Mar, 2018

8 commits