mbox series

[v2,0/6] i2c: mpc: Refactor to improve responsiveness

Message ID 20210329015206.17437-1-chris.packham@alliedtelesis.co.nz
Headers show
Series i2c: mpc: Refactor to improve responsiveness | expand

Message

Chris Packham March 29, 2021, 1:52 a.m. UTC
The "meat" of this series is in the last patch which is the change that
actually starts making use of the interrupts to drive a state machine.
The dt-bindings patches can probably go in at any time, the rest of the
series isn't dependent on them.

I've tested on T2081 and P2041 based systems with a number of i2c and smbus
devices.

Chris Packham (6):
  dt-bindings: i2c-mpc: Document interrupt property as required
  dt-bindings: i2c: convert i2c-mpc to json-schema
  i2c: mpc: Make use of i2c_recover_bus()
  i2c: mpc: make interrupt mandatory and remove polling code
  i2c: mpc: use device managed APIs
  i2c: mpc: Interrupt driven transfer

 .../devicetree/bindings/i2c/i2c-mpc.txt       |  62 ---
 .../devicetree/bindings/i2c/i2c-mpc.yaml      |  91 +++
 drivers/i2c/busses/i2c-mpc.c                  | 517 ++++++++++--------
 3 files changed, 369 insertions(+), 301 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/i2c/i2c-mpc.txt
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mpc.yaml

Comments

Rob Herring (Arm) March 30, 2021, 3:13 p.m. UTC | #1
On Mon, 29 Mar 2021 14:52:01 +1300, Chris Packham wrote:
> All of the in-tree device-trees that use the one of the compatible
> strings from i2c-mpc.c supply an interrupts property. Make this property
> mandatory to aid refactoring the driver.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>  Documentation/devicetree/bindings/i2c/i2c-mpc.txt | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 

Reviewed-by: Rob Herring <robh@kernel.org>
Rob Herring (Arm) March 30, 2021, 3:18 p.m. UTC | #2
On Mon, 29 Mar 2021 14:52:02 +1300, Chris Packham wrote:
> Convert i2c-mpc to YAML.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> 
> Notes:
>     Changes in v2:
>     - Rework compatible validation
>     - Remove irrelevant i2ccontrol from example
> 
>  .../devicetree/bindings/i2c/i2c-mpc.txt       | 62 -------------
>  .../devicetree/bindings/i2c/i2c-mpc.yaml      | 91 +++++++++++++++++++
>  2 files changed, 91 insertions(+), 62 deletions(-)
>  delete mode 100644 Documentation/devicetree/bindings/i2c/i2c-mpc.txt
>  create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mpc.yaml
> 

Reviewed-by: Rob Herring <robh@kernel.org>
Wolfram Sang April 10, 2021, 8:16 p.m. UTC | #3
On Mon, Mar 29, 2021 at 02:52:04PM +1300, Chris Packham wrote:
> All the in-tree dts files that use one of the compatible strings from

> i2c-mpc.c provide an interrupt property. By making this mandatory we

> can simplify the code.

> 

> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>


After I applied this patch, cppcheck reports:

    CPPCHECK
drivers/i2c/busses/i2c-mpc.c:401:47: warning: Either the condition 'div?(int)div->fdr:-EINVAL' is redundant or there is possible null pointer dereference: div. [nullPointerRedundantCheck]
 *real_clk = fsl_get_sys_freq() / prescaler / div->divider;
                                              ^
drivers/i2c/busses/i2c-mpc.c:402:13: note: Assuming that condition 'div?(int)div->fdr:-EINVAL' is not redundant
 return div ? (int)div->fdr : -EINVAL;
            ^
drivers/i2c/busses/i2c-mpc.c:401:47: note: Null pointer dereference
 *real_clk = fsl_get_sys_freq() / prescaler / div->divider;
                                              ^
Can you check this? I'd think we can fix it incrementally...
Chris Packham April 11, 2021, 11:57 p.m. UTC | #4
On 11/04/21 8:16 am, Wolfram Sang wrote:
> On Mon, Mar 29, 2021 at 02:52:04PM +1300, Chris Packham wrote:
>> All the in-tree dts files that use one of the compatible strings from
>> i2c-mpc.c provide an interrupt property. By making this mandatory we
>> can simplify the code.
>>
>> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> After I applied this patch, cppcheck reports:
>
>      CPPCHECK
> drivers/i2c/busses/i2c-mpc.c:401:47: warning: Either the condition 'div?(int)div->fdr:-EINVAL' is redundant or there is possible null pointer dereference: div. [nullPointerRedundantCheck]
>   *real_clk = fsl_get_sys_freq() / prescaler / div->divider;
>                                                ^
> drivers/i2c/busses/i2c-mpc.c:402:13: note: Assuming that condition 'div?(int)div->fdr:-EINVAL' is not redundant
>   return div ? (int)div->fdr : -EINVAL;
>              ^
> drivers/i2c/busses/i2c-mpc.c:401:47: note: Null pointer dereference
>   *real_clk = fsl_get_sys_freq() / prescaler / div->divider;
>                                                ^
> Can you check this? I'd think we can fix it incrementally...
>
What are the arguments passed to cppcheck? I've tried two versions I 
have easy access to (1.82 and 1.86) neither report problems when invoked 
as `cppcheck drivers/i2c/busses/i2c-mpc.c` nor do they complain about 
this with `--enable=all`.

Looking at the code I can see what it's complaining about, div should 
have a value since mpc_i2c_dividers_8xxx does not have a sentinel value 
so I think the div check is unnecessary.