Commit bbf967b2 authored by Alex Williams's avatar Alex Williams Committed by Wolfram Sang

i2c: cadence: Handle transfer_size rollover

Under certain conditions, Cadence's I2C controller's transfer_size
register will roll over and generate invalid read transactions. Before
this change, the ISR relied solely on the RXDV bit to determine when to
write more data to the user's buffer. The invalid read data would cause
overruns, smashing stacks and worse.

This change stops the buffer writes to the requested boundary and
reports the error. The controller will be reset so normal transactions
may resume.
Signed-off-by: default avatarAlex Williams <alex.williams@ni.com>
Reviewed-by: default avatarShubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Reviewed-by: Michal Simek <michal.simek@xilinx.com> # in a seperate mail
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent f53938d2
...@@ -208,6 +208,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) ...@@ -208,6 +208,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET); isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET); cdns_i2c_writereg(isr_status, CDNS_I2C_ISR_OFFSET);
id->err_status = 0;
/* Handling nack and arbitration lost interrupt */ /* Handling nack and arbitration lost interrupt */
if (isr_status & (CDNS_I2C_IXR_NACK | CDNS_I2C_IXR_ARB_LOST)) { if (isr_status & (CDNS_I2C_IXR_NACK | CDNS_I2C_IXR_ARB_LOST)) {
...@@ -241,10 +242,17 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) ...@@ -241,10 +242,17 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
!id->bus_hold_flag) !id->bus_hold_flag)
cdns_i2c_clear_bus_hold(id); cdns_i2c_clear_bus_hold(id);
*(id->p_recv_buf)++ = if (id->recv_count > 0) {
cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET); *(id->p_recv_buf)++ =
id->recv_count--; cdns_i2c_readreg(CDNS_I2C_DATA_OFFSET);
id->curr_recv_count--; id->recv_count--;
id->curr_recv_count--;
} else {
dev_err(id->adap.dev.parent,
"xfer_size reg rollover. xfer aborted!\n");
id->err_status |= CDNS_I2C_IXR_TO;
break;
}
if (cdns_is_holdquirk(id, hold_quirk)) if (cdns_is_holdquirk(id, hold_quirk))
break; break;
...@@ -342,7 +350,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr) ...@@ -342,7 +350,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
} }
/* Update the status for errors */ /* Update the status for errors */
id->err_status = isr_status & CDNS_I2C_IXR_ERR_INTR_MASK; id->err_status |= isr_status & CDNS_I2C_IXR_ERR_INTR_MASK;
if (id->err_status) if (id->err_status)
status = IRQ_HANDLED; status = IRQ_HANDLED;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment