05 Oct, 2020

3 commits

  • With the recent addition of the F3A support, we can now accept
    bootloader v8, which will help support recent Thinkpads.

    Acked-by: Lyude Paul
    Signed-off-by: Jason A. Donenfeld
    Link: https://lore.kernel.org/r/20200930225046.173190-2-Jason@zx2c4.com
    Signed-off-by: Dmitry Torokhov

    Jason A. Donenfeld
     
  • RMI4 F3A supports the touchpad GPIO function, it's designed to
    support more GPIOs and used on newer touchpads. This patch adds
    support of the touchpad buttons.

    Signed-off-by: Vincent Huang
    Reviewed-by: Hans de Goede
    Tested-by: Hans de Goede
    Reviewed-by: Andrew Duggan
    Link: https://lore.kernel.org/r/20200930094147.635556-3-vincent.huang@tw.synaptics.com
    Signed-off-by: Dmitry Torokhov

    Vincent Huang
     
  • f30_data in rmi_device_platform_data could be also referenced by RMI
    function 3A, so rename it and the structure name to avoid confusion.

    Signed-off-by: Vincent Huang
    Reviewed-by: Hans de Goede
    Tested-by: Hans de Goede
    Reviewed-by: Andrew Duggan
    Link: https://lore.kernel.org/r/20200930094147.635556-2-vincent.huang@tw.synaptics.com
    Signed-off-by: Dmitry Torokhov

    Vincent Huang
     

29 Apr, 2020

1 commit


28 Apr, 2020

1 commit

  • Fix a use-after-free noticed by running with KASAN enabled. If
    rmi_irq_fn() is run twice in a row, then rmi_f11_attention() (among
    others) will end up reading from drvdata->attn_data.data, which was
    freed and left dangling in rmi_irq_fn().

    Commit 55edde9fff1a ("Input: synaptics-rmi4 - prevent UAF reported by
    KASAN") correctly identified and analyzed this bug. However the attempted
    fix only NULLed out a local variable, missing the fact that
    drvdata->attn_data is a struct, not a pointer.

    NULL out the correct pointer in the driver data to prevent the attention
    functions from copying from it.

    Fixes: 55edde9fff1a ("Input: synaptics-rmi4 - prevent UAF reported by KASAN")
    Fixes: b908d3cd812a ("Input: synaptics-rmi4 - allow to add attention data")
    Signed-off-by: Evan Green
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200427145537.1.Ic8f898e0147beeee2c005ee7b20f1aebdef1e7eb@changeid
    Signed-off-by: Dmitry Torokhov

    Evan Green
     

25 Mar, 2020

1 commit

  • The previous patch "c5ccf2ad3d33 (Input: synaptics-rmi4 - switch to
    reduced reporting mode)" enabled reduced reporting mode unintentionally
    on some devices, if the firmware was configured with default Delta X/Y
    threshold values. The result unintentionally degrade the performance of
    some touchpads.

    This patch checks to see that the driver is modifying the delta X/Y
    thresholds before modifying the reporting mode.

    Signed-off-by: Andrew Duggan
    Fixes: c5ccf2ad3d33 ("Input: synaptics-rmi4 - switch to reduced reporting mode")
    Link: https://lore.kernel.org/r/20200312005549.29922-1-aduggan@synaptics.com
    Signed-off-by: Dmitry Torokhov

    Andrew Duggan
     

01 Feb, 2020

2 commits


17 Jan, 2020

2 commits

  • The F54 Report Data is apparently read through a fifo and for
    the smbus protocol that means that between reading a block of 32
    bytes the rmiaddr shouldn't be incremented. However, changing
    that causes other non-fifo reads to fail and so that change was
    reverted.

    This patch changes just the F54 function and it now reads 32 bytes
    at a time from the fifo, using the F54_FIFO_OFFSET to update the
    start address that is used when reading from the fifo.

    This has only been tested with smbus, not with i2c or spi. But I
    suspect that the same is needed there since I think similar
    problems will occur there when reading more than 256 bytes.

    Signed-off-by: Hans Verkuil
    Tested-by: Hans Verkuil
    Reported-by: Timo Kaufmann
    Link: https://lore.kernel.org/r/20200115124819.3191024-3-hverkuil-cisco@xs4all.nl
    Signed-off-by: Dmitry Torokhov

    Hans Verkuil
     
  • This reverts commit a284e11c371e446371675668d8c8120a27227339.

    This causes problems (drifting cursor) with at least the F11 function that
    reads more than 32 bytes.

    The real issue is in the F54 driver, and so this should be fixed there, and
    not in rmi_smbus.c.

    So first revert this bad commit, then fix the real problem in F54 in another
    patch.

    Signed-off-by: Hans Verkuil
    Reported-by: Timo Kaufmann
    Fixes: a284e11c371e ("Input: synaptics-rmi4 - don't increment rmiaddr for SMBus transfers")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20200115124819.3191024-2-hverkuil-cisco@xs4all.nl
    Signed-off-by: Dmitry Torokhov

    Hans Verkuil
     

07 Dec, 2019

1 commit


05 Dec, 2019

2 commits

  • This increment of rmi_smbus in rmi_smb_read/write_block() causes
    garbage to be read/written.

    The first read of SMB_MAX_COUNT bytes is fine, but after that
    it is nonsense. Trial-and-error showed that by dropping the
    increment of rmiaddr everything is fine and the F54 function
    properly works.

    I tried a hack with rmi_smb_write_block() as well (writing to the
    same F54 touchpad data area, then reading it back), and that
    suggests that there too the rmiaddr increment has to be dropped.
    It makes sense that if it has to be dropped for read, then it has
    to be dropped for write as well.

    It looks like the initial work with F54 was done using i2c, not smbus,
    and it seems nobody ever tested F54 with smbus. The other functions
    all read/write less than SMB_MAX_COUNT as far as I can tell, so this
    issue was never noticed with non-F54 functions.

    With this change I can read out the touchpad data correctly on my
    Lenovo X1 Carbon 6th Gen laptop.

    Signed-off-by: Hans Verkuil
    Link: https://lore.kernel.org/r/8dd22e21-4933-8e9c-a696-d281872c8de7@xs4all.nl
    Cc: stable@vger.kernel.org
    Signed-off-by: Dmitry Torokhov

    Hans Verkuil
     
  • F34 is a bit special as it reinitializes the device and related driver
    structs during the firmware update. This clears the fn_irq_mask which
    will then prevent F34 from receiving further interrupts, leading to
    timeouts during the firmware update. Make sure to reinitialize the
    IRQ enables at the appropriate times.

    The issue is in F34 code, but the commit in the fixes tag exposed the
    issue, as before this commit things would work by accident.

    Fixes: 363c53875aef (Input: synaptics-rmi4 - avoid processing unknown IRQs)
    Signed-off-by: Lucas Stach
    Link: https://lore.kernel.org/r/20191129133514.23224-1-l.stach@pengutronix.de
    Cc: stable@vger.kernel.org
    Signed-off-by: Dmitry Torokhov

    Lucas Stach
     

26 Nov, 2019

1 commit


23 Nov, 2019

1 commit

  • The v4l2-compliance utility reported several V4L2 API compliance
    issues:

    - the sequence counter wasn't filled in
    - the sequence counter wasn't reset to 0 at the start of streaming
    - the returned field value wasn't set to V4L2_FIELD_NONE
    - the timestamp wasn't set
    - the payload size was undefined if an error was returned
    - min_buffers_needed doesn't need to be initialized

    Fix these issues.

    Signed-off-by: Hans Verkuil
    Reviewed-by: Lucas Stach

    Hans Verkuil
     

16 Nov, 2019

1 commit

  • The driver forgets to destroy workqueue in remove() similarly to what is
    done when probe() fails. Add a call to destroy_workqueue() to fix it.

    Since unregistration will wait for the work to finish, we do not need to
    cancel/flush the work instance in remove().

    Signed-off-by: Chuhong Yuan
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20191114023405.31477-1-hslester96@gmail.com
    Signed-off-by: Dmitry Torokhov

    Chuhong Yuan
     

13 Nov, 2019

1 commit

  • The driver for F54 just polls the status and doesn't even have a IRQ
    handler registered. Make sure to disable all F54 IRQs, so we don't crash
    the kernel on a nonexistent handler.

    Signed-off-by: Lucas Stach
    Link: https://lore.kernel.org/r/20191105114402.6009-1-l.stach@pengutronix.de
    Cc: stable@vger.kernel.org
    Signed-off-by: Dmitry Torokhov

    Lucas Stach
     

05 Nov, 2019

5 commits

  • The body of the for loop is only ever run once as the second standard_report
    element is never changed from its initial zero init, so the loop condition is
    never satisfies after the first run. Equally the start member of the first
    element is never changed from 0, so the index offset is always a constant 0.

    Remove this needless obfuscation of the code and write it in a straight
    forward manner.

    Signed-off-by: Lucas Stach
    Link: https://lore.kernel.org/r/20191104114454.10500-3-l.stach@pengutronix.de
    Signed-off-by: Dmitry Torokhov

    Lucas Stach
     
  • The result_bits mask is no longer used by the driver and should be
    removed.

    Signed-off-by: Andrew Duggan
    Link: https://lore.kernel.org/r/20191025002527.3189-4-aduggan@synaptics.com
    Signed-off-by: Dmitry Torokhov

    Andrew Duggan
     
  • Currently, rmi_f11_attention() and rmi_f12_attention() functions update
    the attn_data data pointer and size based on the size of the expected
    size of the attention data. However, if the actual valid data in the
    attn buffer is less then the expected value then the updated data
    pointer will point to memory beyond the end of the attn buffer. Using
    the calculated valid_bytes instead will prevent this from happening.

    Signed-off-by: Andrew Duggan
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20191025002527.3189-3-aduggan@synaptics.com
    Signed-off-by: Dmitry Torokhov

    Andrew Duggan
     
  • This patch fixes an issue seen on HID touchpads which report finger
    positions using RMI4 Function 12. The issue manifests itself as
    spurious button presses as described in:
    https://www.spinics.net/lists/linux-input/msg58618.html

    Commit 24d28e4f1271 ("Input: synaptics-rmi4 - convert irq distribution
    to irq_domain") switched the RMI4 driver to using an irq_domain to handle
    RMI4 function interrupts. Functions with more then one interrupt now have
    each interrupt mapped to their own IRQ and IRQ handler. The result of
    this change is that the F12 IRQ handler was now getting called twice. Once
    for the absolute data interrupt and once for the relative data interrupt.
    For HID devices, calling rmi_f12_attention() a second time causes the
    attn_data data pointer and size to be set incorrectly. When the touchpad
    button is pressed, F30 will generate an interrupt and attempt to read the
    F30 data from the invalid attn_data data pointer and report incorrect
    button events.

    This patch disables the F12 relative interrupt which prevents
    rmi_f12_attention() from being called twice.

    Signed-off-by: Andrew Duggan
    Reported-by: Simon Wood
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20191025002527.3189-2-aduggan@synaptics.com
    Signed-off-by: Dmitry Torokhov

    Andrew Duggan
     
  • The video buffer used by the queue is a vb2_v4l2_buffer, not a plain
    vb2_buffer. Using the wrong type causes the allocation of the buffer
    storage to be too small, causing a out of bounds write when
    __init_vb2_v4l2_buffer initializes the buffer.

    Signed-off-by: Lucas Stach
    Fixes: 3a762dbd5347 ("[media] Input: synaptics-rmi4 - add support for F54 diagnostics")
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20191104114454.10500-1-l.stach@pengutronix.de
    Signed-off-by: Dmitry Torokhov

    Lucas Stach
     

12 Oct, 2019

1 commit

  • rmi_process_interrupt_requests() calls handle_nested_irq() for
    each interrupt status bit it finds. If the irq domain mapping for
    this bit had not yet been set up, then it ends up calling
    handle_nested_irq(0), which causes a NULL pointer dereference.

    There's already code that masks the irq_status bits coming out of the
    hardware with current_irq_mask, presumably to avoid this situation.
    However current_irq_mask seems to more reflect the actual mask set
    in the hardware rather than the IRQs software has set up and registered
    for. For example, in rmi_driver_reset_handler(), the current_irq_mask
    is initialized based on what is read from the hardware. If the reset
    value of this mask enables IRQs that Linux has not set up yet, then
    we end up in this situation.

    There appears to be a third unused bitmask that used to serve this
    purpose, fn_irq_bits. Use that bitmask instead of current_irq_mask
    to avoid calling handle_nested_irq() on IRQs that have not yet been
    set up.

    Signed-off-by: Evan Green
    Reviewed-by: Andrew Duggan
    Link: https://lore.kernel.org/r/20191008223657.163366-1-evgreen@chromium.org
    Cc: stable@vger.kernel.org
    Signed-off-by: Dmitry Torokhov

    Evan Green
     

24 Jul, 2019

1 commit


16 Jul, 2019

1 commit


19 Jun, 2019

1 commit

  • Based on 2 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license version 2 as
    published by the free software foundation #

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 4122 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Enrico Weigelt
    Reviewed-by: Kate Stewart
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

28 May, 2019

1 commit

  • Fixes gcc '-Wunused-but-set-variable' warning:

    drivers/input/rmi4/rmi_f12.c: In function rmi_f12_read_sensor_tuning:
    drivers/input/rmi4/rmi_f12.c:76:6: warning: variable sensor_flags set but not used [-Wunused-but-set-variable]

    It's not used since introduction in
    commit b43d2c1e9353 ("Input: synaptics-rmi4 - add support for F12")

    Signed-off-by: YueHaibing
    Signed-off-by: Dmitry Torokhov

    YueHaibing
     

21 May, 2019

1 commit


11 May, 2019

2 commits


27 Apr, 2019

3 commits

  • Currently any changed config register values don't take effect, as the
    function to write them back is called with the wrong register offset.

    Fixes: ff8f83708b3e (Input: synaptics-rmi4 - add support for 2D
    sensors and F11)
    Signed-off-by: Lucas Stach
    Reviewed-by: Philipp Zabel
    Cc: stable@vger.kernel.org
    Signed-off-by: Dmitry Torokhov

    Lucas Stach
     
  • Do not enumerate all formats, some of which the device may not even
    support. Instead, only report the one fixed format of the currently
    selected input that will survive try_fmt/s_fmt.

    Signed-off-by: Philipp Zabel
    Signed-off-by: Dmitry Torokhov

    Philipp Zabel
     
  • The driver doesn't set an initial video format until s_input is called:

    $ v4l2-ctl -d /dev/v4l-touch0 --get-input
    Video input : 0 (Normalized 16-Bit Image: ok)
    $ v4l2-ctl -d /dev/v4l-touch0 --get-fmt-video
    Width/Height : 0/0
    Pixel Format : ''
    [...]
    $ v4l2-ctl -d /dev/v4l-touch0 --set-input 0
    Video input set to 0 (Normalized 16-Bit Image: Touch, ok)
    $ v4l2-ctl -d /dev/v4l-touch0 --get-fmt-video
    Width/Height : 71/40
    Pixel Format : 'TD16'
    [...]

    To fix this, initialize the video format to input 0 during probe.

    Signed-off-by: Philipp Zabel
    Signed-off-by: Dmitry Torokhov

    Philipp Zabel
     

25 Apr, 2019

1 commit


28 Jun, 2018

1 commit

  • Pull input updates from Dmitry Torokhov:

    - the main change is a fix for my brain-dead patch to PS/2 button
    reporting for some protocols that made it in 4.17

    - there is a new driver for Spreadtum vibrator that I intended to send
    during merge window but ended up not sending the 2nd pull request.
    Given that this is a brand new driver we should not see regressions
    here

    - a fixup to Elantech PS/2 driver to avoid decoding errors on Thinkpad
    P52

    - addition of few more ACPI IDs for Silead and Elan drivers

    - RMI4 is switched to using IRQ domain code instead of rolling its own
    implementation

    * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input:
    Input: psmouse - fix button reporting for basic protocols
    Input: xpad - fix GPD Win 2 controller name
    Input: elan_i2c_smbus - fix more potential stack buffer overflows
    Input: elan_i2c - add ELAN0618 (Lenovo v330 15IKB) ACPI ID
    Input: elantech - fix V4 report decoding for module with middle key
    Input: elantech - enable middle button of touchpads on ThinkPad P52
    Input: do not assign new tracking ID when changing tool type
    Input: make input_report_slot_state() return boolean
    Input: synaptics-rmi4 - fix axis-swap behavior
    Input: synaptics-rmi4 - fix the error return code in rmi_probe_interrupts()
    Input: synaptics-rmi4 - convert irq distribution to irq_domain
    Input: silead - add MSSL0002 ACPI HID
    Input: goldfish_events - fix checkpatch warnings
    Input: add Spreadtrum vibrator driver

    Linus Torvalds
     

13 Jun, 2018

1 commit

  • 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: Kees Cook

    Kees Cook
     

12 Jun, 2018

2 commits


06 Jun, 2018

1 commit


07 Apr, 2018

1 commit