hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/drivers/i2c/busses/i2c-ocores.c
....@@ -343,18 +343,18 @@
343343 * ocores_isr(), we just add our polling code around it.
344344 *
345345 * It can run in atomic context
346
+ *
347
+ * Return: 0 on success, -ETIMEDOUT on timeout
346348 */
347
-static void ocores_process_polling(struct ocores_i2c *i2c)
349
+static int ocores_process_polling(struct ocores_i2c *i2c)
348350 {
349
- while (1) {
350
- irqreturn_t ret;
351
- int err;
351
+ irqreturn_t ret;
352
+ int err = 0;
352353
354
+ while (1) {
353355 err = ocores_poll_wait(i2c);
354
- if (err) {
355
- i2c->state = STATE_ERROR;
356
+ if (err)
356357 break; /* timeout */
357
- }
358358
359359 ret = ocores_isr(-1, i2c);
360360 if (ret == IRQ_NONE)
....@@ -365,13 +365,15 @@
365365 break;
366366 }
367367 }
368
+
369
+ return err;
368370 }
369371
370372 static int ocores_xfer_core(struct ocores_i2c *i2c,
371373 struct i2c_msg *msgs, int num,
372374 bool polling)
373375 {
374
- int ret;
376
+ int ret = 0;
375377 u8 ctrl;
376378
377379 ctrl = oc_getreg(i2c, OCI2C_CONTROL);
....@@ -389,15 +391,16 @@
389391 oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
390392
391393 if (polling) {
392
- ocores_process_polling(i2c);
394
+ ret = ocores_process_polling(i2c);
393395 } else {
394
- ret = wait_event_timeout(i2c->wait,
395
- (i2c->state == STATE_ERROR) ||
396
- (i2c->state == STATE_DONE), HZ);
397
- if (ret == 0) {
398
- ocores_process_timeout(i2c);
399
- return -ETIMEDOUT;
400
- }
396
+ if (wait_event_timeout(i2c->wait,
397
+ (i2c->state == STATE_ERROR) ||
398
+ (i2c->state == STATE_DONE), HZ) == 0)
399
+ ret = -ETIMEDOUT;
400
+ }
401
+ if (ret) {
402
+ ocores_process_timeout(i2c);
403
+ return ret;
401404 }
402405
403406 return (i2c->state == STATE_DONE) ? num : -EIO;