Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: designware: Remove code duplication

Simplify code by moving common part to one function.

Signed-off-by: Jan Dabros <jsd@semihalf.com>
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>

authored by

Jan Dabros and committed by
Wolfram Sang
3364c0ef 8b6d8d00

+15 -20
+15 -20
drivers/i2c/busses/i2c-designware-amdpsp.c
··· 214 214 PSP_I2C_REQ_RETRY_DELAY_US, 215 215 PSP_I2C_REQ_RETRY_CNT * PSP_I2C_REQ_RETRY_DELAY_US, 216 216 0, req); 217 - if (ret) 217 + if (ret) { 218 + dev_err(psp_i2c_dev, "Timed out waiting for PSP to %s I2C bus\n", 219 + (i2c_req_type == PSP_I2C_REQ_ACQUIRE) ? 220 + "release" : "acquire"); 218 221 goto cleanup; 222 + } 219 223 220 224 ret = status; 221 - if (ret) 225 + if (ret) { 226 + dev_err(psp_i2c_dev, "PSP communication error\n"); 222 227 goto cleanup; 228 + } 223 229 224 230 dev_dbg(psp_i2c_dev, "Request accepted by PSP after %ums\n", 225 231 jiffies_to_msecs(jiffies - start)); 226 232 227 233 cleanup: 234 + if (ret) { 235 + dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); 236 + psp_i2c_mbox_fail = true; 237 + } 238 + 228 239 kfree(req); 229 240 return ret; 230 241 } ··· 260 249 } 261 250 262 251 status = psp_send_i2c_req(PSP_I2C_REQ_ACQUIRE); 263 - if (status) { 264 - if (status == -ETIMEDOUT) 265 - dev_err(psp_i2c_dev, "Timed out waiting for PSP to release I2C bus\n"); 266 - else 267 - dev_err(psp_i2c_dev, "PSP communication error\n"); 268 - 269 - dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); 270 - psp_i2c_mbox_fail = true; 252 + if (status) 271 253 goto cleanup; 272 - } 273 254 274 255 psp_i2c_sem_acquired = jiffies; 275 256 psp_i2c_access_count++; ··· 297 294 298 295 /* Send a release command to PSP */ 299 296 status = psp_send_i2c_req(PSP_I2C_REQ_RELEASE); 300 - if (status) { 301 - if (status == -ETIMEDOUT) 302 - dev_err(psp_i2c_dev, "Timed out waiting for PSP to acquire I2C bus\n"); 303 - else 304 - dev_err(psp_i2c_dev, "PSP communication error\n"); 305 - 306 - dev_err(psp_i2c_dev, "Assume i2c bus is for exclusive host usage\n"); 307 - psp_i2c_mbox_fail = true; 297 + if (status) 308 298 goto cleanup; 309 - } 310 299 311 300 dev_dbg(psp_i2c_dev, "PSP semaphore held for %ums\n", 312 301 jiffies_to_msecs(jiffies - psp_i2c_sem_acquired));