This patch marks baytrail_i2c_acquire() that it might sleep. Also it chages while-loop to do-while and, though it is matter of taste, gives a chance to check one more time before report a timeout.
Unified · Split
| @@ -68,6 +68,8 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · 67 unmodified lines | ||
| 68 | 68 | int ret; |
| 69 | 69 | unsigned long start, end; |
| 70 | 70 | |
| 71 | + might_sleep(); | |
| 72 | + | |
| 71 | 73 | if (!dev || !dev->dev) |
| 72 | 74 | return -ENODEV; |
| 73 | 75 | |
| @@ -85,7 +87,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · 11 unmodified lines | ||
| 85 | 87 | /* host driver waits for bit 0 to be set in semaphore register */ |
| 86 | 88 | start = jiffies; |
| 87 | 89 | end = start + msecs_to_jiffies(SEMAPHORE_TIMEOUT); |
| 88 | − while (!time_after(jiffies, end)) { | |
| 90 | + do { | |
| 89 | 91 | ret = get_sem(dev->dev, &sem); |
| 90 | 92 | if (!ret && sem) { |
| 91 | 93 | acquired = jiffies; |
| @@ -95,7 +97,7 @@ static int baytrail_i2c_acquire(struct dw_i2c_dev *dev) · 3 unmodified lines | ||
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | usleep_range(1000, 2000); |
| 98 | − } | |
| 100 | + } while (time_before(jiffies, end)); | |
| 99 | 101 | |
| 100 | 102 | dev_err(dev->dev, "punit semaphore timed out, resetting\n"); |
| 101 | 103 | reset_semaphore(dev->dev); |