From 70f21fbddb239de9590c2fcca5b088d689c5de35 Mon Sep 17 00:00:00 2001 From: Jian Hu Date: Thu, 31 Aug 2017 10:18:22 +0800 Subject: [PATCH] i2c: clean up bad shift and return check PD#150077: driver defect clean up: #8 #9 #10 #11 #12 #13 #24 Change-Id: I6bc36d30b761588a06a27957820d3ebc6aa5bf13 Signed-off-by: Jian Hu --- drivers/amlogic/i2c/aml_master.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/amlogic/i2c/aml_master.c b/drivers/amlogic/i2c/aml_master.c index 9aa34f8..d4d2e82 100644 --- a/drivers/amlogic/i2c/aml_master.c +++ b/drivers/amlogic/i2c/aml_master.c @@ -223,8 +223,11 @@ static void aml_i2c_get_read_data(struct aml_i2c *i2c, unsigned char *buf, for (i = 0; i < min_t(size_t, len, AML_I2C_MAX_TOKENS>>1); i++) *buf++ = (rdata0 >> (i*8)) & 0xff; - for (; i < min_t(size_t, len, AML_I2C_MAX_TOKENS); i++) - *buf++ = (rdata1 >> ((i - (AML_I2C_MAX_TOKENS>>1))*8)) & 0xff; + if (len > 4) { + for (i = 4; i < min_t(size_t, len, AML_I2C_MAX_TOKENS); i++) + *buf++ = (rdata1 >> ((i - (AML_I2C_MAX_TOKENS>>1))*8)) + & 0xff; + } } static void aml_i2c_fill_data(struct aml_i2c *i2c, unsigned char *buf, @@ -237,8 +240,10 @@ static void aml_i2c_fill_data(struct aml_i2c *i2c, unsigned char *buf, for (i = 0; i < min_t(size_t, len, AML_I2C_MAX_TOKENS>>1); i++) wdata0 |= (*buf++) << (i*8); - for (; i < min_t(size_t, len, AML_I2C_MAX_TOKENS); i++) - wdata1 |= (*buf++) << ((i - (AML_I2C_MAX_TOKENS>>1))*8); + if (len > 4) { + for (i = 4; i < min_t(size_t, len, AML_I2C_MAX_TOKENS); i++) + wdata1 |= (*buf++) << ((i - (AML_I2C_MAX_TOKENS>>1))*8); + } i2c->master_regs->i2c_token_wdata_0 = wdata0; i2c->master_regs->i2c_token_wdata_1 = wdata1; @@ -277,6 +282,7 @@ static long aml_i2c_do_address(struct aml_i2c *i2c, unsigned int addr) static void aml_i2c_stop(struct aml_i2c *i2c) { struct aml_i2c_reg_ctrl *ctrl; + int ret; ctrl = (struct aml_i2c_reg_ctrl *)&(i2c->master_regs->i2c_ctrl); @@ -290,8 +296,11 @@ static void aml_i2c_stop(struct aml_i2c *i2c) aml_i2c_set_token_list(i2c); aml_i2c_start_token_xfer(i2c); if (get_meson_cpu_version(MESON_CPU_VERSION_LVL_MAJOR) - > MESON_CPU_MAJOR_ID_GXBB) - aml_i2c_wait_ack(i2c); + > MESON_CPU_MAJOR_ID_GXBB) { + ret = aml_i2c_wait_ack(i2c); + if (ret < 0) + return; + } else udelay(i2c->wait_xfer_interval); } -- 2.7.4