Re: [PATCH V4] drivers: i2c: tegra: fix checkpatch defects
From: Dmitry Osipenko
Date: Thu Jun 06 2019 - 11:38:37 EST
06.06.2019 17:02, Bitan Biswas ÐÐÑÐÑ:
>
>
> On 6/6/19 4:39 AM, Dmitry Osipenko wrote:
>> 06.06.2019 10:35, Bitan Biswas ÐÐÑÐÑ:
>>> Fix checkpatch.pl warning(s)/error(s)/check(s) in i2c-tegra.c
>>>
>>> Remove redundant BUG_ON calls or replace with WARN_ON_ONCE
>>> as needed. Replace BUG() with error handling code.
>>> Define I2C_ERR_UNEXPECTED_STATUS for error handling.
>>>
>>> Signed-off-by: Bitan Biswas <bbiswas@xxxxxxxxxx>
>>> ---
>>> Â drivers/i2c/busses/i2c-tegra.c | 67
>>> +++++++++++++++++++++++-------------------
>>> Â 1 file changed, 37 insertions(+), 30 deletions(-)
>>>
>>> diff --git a/drivers/i2c/busses/i2c-tegra.c
>>> b/drivers/i2c/busses/i2c-tegra.c
>>> index 76b7926..55a5d87 100644
>>> --- a/drivers/i2c/busses/i2c-tegra.c
>>> +++ b/drivers/i2c/busses/i2c-tegra.c
>>> @@ -78,6 +78,7 @@
>>> Â #define I2C_ERR_NO_ACKÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x01
>>> Â #define I2C_ERR_ARBITRATION_LOSTÂÂÂÂÂÂÂ 0x02
>>> Â #define I2C_ERR_UNKNOWN_INTERRUPTÂÂÂÂÂÂÂ 0x04
>>> +#define I2C_ERR_UNEXPECTED_STATUSÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0x08
>>> Â Â #define PACKET_HEADER0_HEADER_SIZE_SHIFTÂÂÂ 28
>>> Â #define PACKET_HEADER0_PACKET_ID_SHIFTÂÂÂÂÂÂÂ 16
>>> @@ -112,7 +113,7 @@
>>> Â #define I2C_CLKEN_OVERRIDEÂÂÂÂÂÂÂÂÂÂÂ 0x090
>>> Â #define I2C_MST_CORE_CLKEN_OVRÂÂÂÂÂÂÂÂÂÂÂ BIT(0)
>>> Â -#define I2C_CONFIG_LOAD_TIMEOUTÂÂÂÂÂÂÂÂÂÂÂ 1000000
>>> +#define I2C_CONFIG_LOAD_TMOUTÂÂÂÂÂÂÂÂÂÂÂ 1000000
>>> Â Â #define I2C_MST_FIFO_CONTROLÂÂÂÂÂÂÂÂÂÂÂ 0x0b4
>>> Â #define I2C_MST_FIFO_CONTROL_RX_FLUSHÂÂÂÂÂÂÂ BIT(0)
>>> @@ -280,6 +281,7 @@ struct tegra_i2c_dev {
>>> ÂÂÂÂÂ u32 bus_clk_rate;
>>> ÂÂÂÂÂ u16 clk_divisor_non_hs_mode;
>>> ÂÂÂÂÂ bool is_multimaster_mode;
>>> +ÂÂÂ /* xfer_lock: lock to serialize transfer submission and
>>> processing */
>>> ÂÂÂÂÂ spinlock_t xfer_lock;
>>> ÂÂÂÂÂ struct dma_chan *tx_dma_chan;
>>> ÂÂÂÂÂ struct dma_chan *rx_dma_chan;
>>> @@ -306,7 +308,7 @@ static u32 dvc_readl(struct tegra_i2c_dev
>>> *i2c_dev, unsigned long reg)
>>> ÂÂ * to the I2C block inside the DVC block
>>> ÂÂ */
>>> Â static unsigned long tegra_i2c_reg_addr(struct tegra_i2c_dev *i2c_dev,
>>> -ÂÂÂ unsigned long reg)
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned long reg)
>>> Â {
>>> ÂÂÂÂÂ if (i2c_dev->is_dvc)
>>> ÂÂÂÂÂÂÂÂÂ reg += (reg >= I2C_TX_FIFO) ? 0x10 : 0x40;
>>> @@ -314,7 +316,7 @@ static unsigned long tegra_i2c_reg_addr(struct
>>> tegra_i2c_dev *i2c_dev,
>>> Â }
>>> Â Â static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
>>> -ÂÂÂ unsigned long reg)
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned long reg)
>>> Â {
>>> ÂÂÂÂÂ writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
>>> Â @@ -329,13 +331,13 @@ static u32 i2c_readl(struct tegra_i2c_dev
>>> *i2c_dev, unsigned long reg)
>>> Â }
>>> Â Â static void i2c_writesl(struct tegra_i2c_dev *i2c_dev, void *data,
>>> -ÂÂÂ unsigned long reg, int len)
>>> +ÂÂÂÂÂÂÂÂÂÂÂ unsigned long reg, int len)
>>> Â {
>>> ÂÂÂÂÂ writesl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data,
>>> len);
>>> Â }
>>> Â Â static void i2c_readsl(struct tegra_i2c_dev *i2c_dev, void *data,
>>> -ÂÂÂ unsigned long reg, int len)
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ unsigned long reg, int len)
>>> Â {
>>> ÂÂÂÂÂ readsl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg), data,
>>> len);
>>> Â }
>>> @@ -486,7 +488,7 @@ static int tegra_i2c_flush_fifos(struct
>>> tegra_i2c_dev *i2c_dev)
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_warn(i2c_dev->dev, "timeout waiting for fifo
>>> flush\n");
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ return -ETIMEDOUT;
>>> ÂÂÂÂÂÂÂÂÂ }
>>> -ÂÂÂÂÂÂÂ msleep(1);
>>> +ÂÂÂÂÂÂÂ usleep_range(1000, 2000);
>>> ÂÂÂÂÂ }
>>> ÂÂÂÂÂ return 0;
>>> Â }
>>> @@ -525,7 +527,6 @@ static int tegra_i2c_empty_rx_fifo(struct
>>> tegra_i2c_dev *i2c_dev)
>>> ÂÂÂÂÂÂ * prevent overwriting past the end of buf
>>> ÂÂÂÂÂÂ */
>>> ÂÂÂÂÂ if (rx_fifo_avail > 0 && buf_remaining > 0) {
>>> -ÂÂÂÂÂÂÂ BUG_ON(buf_remaining > 3);
>>> ÂÂÂÂÂÂÂÂÂ val = i2c_readl(i2c_dev, I2C_RX_FIFO);
>>> ÂÂÂÂÂÂÂÂÂ val = cpu_to_le32(val);
>>> ÂÂÂÂÂÂÂÂÂ memcpy(buf, &val, buf_remaining);
>>> @@ -533,7 +534,6 @@ static int tegra_i2c_empty_rx_fifo(struct
>>> tegra_i2c_dev *i2c_dev)
>>> ÂÂÂÂÂÂÂÂÂ rx_fifo_avail--;
>>> ÂÂÂÂÂ }
>>> Â -ÂÂÂ BUG_ON(rx_fifo_avail > 0 && buf_remaining > 0);
>>> ÂÂÂÂÂ i2c_dev->msg_buf_remaining = buf_remaining;
>>> ÂÂÂÂÂ i2c_dev->msg_buf = buf;
>>> Â @@ -591,7 +591,6 @@ static int tegra_i2c_fill_tx_fifo(struct
>>> tegra_i2c_dev *i2c_dev)
>>> ÂÂÂÂÂÂ * boundary and fault.
>>> ÂÂÂÂÂÂ */
>>> ÂÂÂÂÂ if (tx_fifo_avail > 0 && buf_remaining > 0) {
>>> -ÂÂÂÂÂÂÂ BUG_ON(buf_remaining > 3);
>>> ÂÂÂÂÂÂÂÂÂ memcpy(&val, buf, buf_remaining);
>>> ÂÂÂÂÂÂÂÂÂ val = le32_to_cpu(val);
>>> Â @@ -680,10 +679,11 @@ static int
>>> tegra_i2c_wait_for_config_load(struct tegra_i2c_dev *i2c_dev)
>>> ÂÂÂÂÂÂÂÂÂ i2c_writel(i2c_dev, I2C_MSTR_CONFIG_LOAD, I2C_CONFIG_LOAD);
>>> ÂÂÂÂÂÂÂÂÂ if (in_interrupt())
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ err = readl_poll_timeout_atomic(addr, val, val == 0,
>>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 1000, I2C_CONFIG_LOAD_TIMEOUT);
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 1000,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ I2C_CONFIG_LOAD_TMOUT);
>>> ÂÂÂÂÂÂÂÂÂ else
>>> -ÂÂÂÂÂÂÂÂÂÂÂ err = readl_poll_timeout(addr, val, val == 0,
>>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 1000, I2C_CONFIG_LOAD_TIMEOUT);
>>> +ÂÂÂÂÂÂÂÂÂÂÂ err = readl_poll_timeout(addr, val, val == 0, 1000,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ I2C_CONFIG_LOAD_TMOUT);
>>> Â ÂÂÂÂÂÂÂÂÂ if (err) {
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_warn(i2c_dev->dev,
>>> @@ -858,16 +858,21 @@ static irqreturn_t tegra_i2c_isr(int irq, void
>>> *dev_id)
>>> ÂÂÂÂÂÂÂÂÂ if (i2c_dev->msg_read && (status &
>>> I2C_INT_RX_FIFO_DATA_REQ)) {
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ if (i2c_dev->msg_buf_remaining)
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ tegra_i2c_empty_rx_fifo(i2c_dev);
>>> -ÂÂÂÂÂÂÂÂÂÂÂ else
>>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ BUG();
>>> +ÂÂÂÂÂÂÂÂÂÂÂ else {
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(i2c_dev->dev, "unexpected rx data request\n");
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ i2c_dev->msg_err |= I2C_ERR_UNEXPECTED_STATUS;
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto err;
>>> +ÂÂÂÂÂÂÂÂÂÂÂ }
>>> ÂÂÂÂÂÂÂÂÂ }
>>> Â ÂÂÂÂÂÂÂÂÂ if (!i2c_dev->msg_read && (status &
>>> I2C_INT_TX_FIFO_DATA_REQ)) {
>>> -ÂÂÂÂÂÂÂÂÂÂÂ if (i2c_dev->msg_buf_remaining)
>>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ tegra_i2c_fill_tx_fifo(i2c_dev);
>>> -ÂÂÂÂÂÂÂÂÂÂÂ else
>>> +ÂÂÂÂÂÂÂÂÂÂÂ if (i2c_dev->msg_buf_remaining) {
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (tegra_i2c_fill_tx_fifo(i2c_dev))
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto err;
>>> +ÂÂÂÂÂÂÂÂÂÂÂ } else {
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ tegra_i2c_mask_irq(i2c_dev,
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ I2C_INT_TX_FIFO_DATA_REQ);
>>> +ÂÂÂÂÂÂÂÂÂÂÂ }
>>> ÂÂÂÂÂÂÂÂÂ }
>>> ÂÂÂÂÂ }
>>> Â @@ -885,7 +890,7 @@ static irqreturn_t tegra_i2c_isr(int irq, void
>>> *dev_id)
>>> ÂÂÂÂÂ if (status & I2C_INT_PACKET_XFER_COMPLETE) {
>>> ÂÂÂÂÂÂÂÂÂ if (i2c_dev->is_curr_dma_xfer)
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ i2c_dev->msg_buf_remaining = 0;
>>> -ÂÂÂÂÂÂÂ BUG_ON(i2c_dev->msg_buf_remaining);
>>> +ÂÂÂÂÂÂÂ WARN_ON_ONCE(i2c_dev->msg_buf_remaining);
>>> ÂÂÂÂÂÂÂÂÂ complete(&i2c_dev->msg_complete);
>>> ÂÂÂÂÂ }
>>> ÂÂÂÂÂ goto done;
>>> @@ -1024,7 +1029,7 @@ static int tegra_i2c_issue_bus_clear(struct
>>> i2c_adapter *adap)
>>> Â }
>>> Â Â static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
>>> -ÂÂÂ struct i2c_msg *msg, enum msg_end_type end_state)
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct i2c_msg *msg, enum msg_end_type end_state)
>>> Â {
>>> ÂÂÂÂÂ u32 packet_header;
>>> ÂÂÂÂÂ u32 int_mask;
>>> @@ -1034,7 +1039,7 @@ static int tegra_i2c_xfer_msg(struct
>>> tegra_i2c_dev *i2c_dev,
>>> ÂÂÂÂÂ u32 *buffer = NULL;
>>> ÂÂÂÂÂ int err = 0;
>>> ÂÂÂÂÂ bool dma;
>>> -ÂÂÂ u16 xfer_time = 100;
>>> +ÂÂÂ u16 xfer_tm = 100;
>>
>> Why xfer_time is renamed? It is much more important to keep code
>> readable rather than to satisfy checkpatch. You should *not* follow
>> checkpatch recommendations where they do not make much sense. The
>> xfer_tm is a less intuitive naming and hence it harms readability of the
>> code. Hence it is better to have "lines over 80 chars" in this
>> particular case.
> Agreed. I shall share updated patch.
Yes, please.
>>
>> Also, please don't skip review comments. I already pointed out the above
>> in the answer to previous version of the patch.
>>
> I apologize for the oversight. I shall be more careful in future.
No problems ;)