diff options
author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2016-07-17 14:40:06 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2016-07-18 14:07:54 -0400 |
commit | 24da3cc0e25f48e12656226e5ed313573a3b443f (patch) | |
tree | 5ad5a9441d18e625b54678481c3ad80740c9d7d2 | |
parent | 0b813658c11532be90cbf5f579a8ba45a8cc9dbf (diff) |
eeprom: at24: tweak the loop_until_timeout() macro
loop_until_timeout() replaced a do {} while loop in the at24 driver
with a for loop which, under certain circumstances (such as heavy load
or low value of the write_timeout argument), can lead to the code in
the loop never being executed.
Make sure that at least one iteration of the code enclosed within
loop_until_timeout() is always executed.
Suggested-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r-- | drivers/misc/eeprom/at24.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 04e91e331fc5..3cdf8e1ca0ad 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c | |||
@@ -116,7 +116,8 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); | |||
116 | /* | 116 | /* |
117 | * Both reads and writes fail if the previous write didn't complete yet. This | 117 | * Both reads and writes fail if the previous write didn't complete yet. This |
118 | * macro loops a few times waiting at least long enough for one entire page | 118 | * macro loops a few times waiting at least long enough for one entire page |
119 | * write to work. | 119 | * write to work while making sure that at least one iteration is run before |
120 | * checking the break condition. | ||
120 | * | 121 | * |
121 | * It takes two parameters: a variable in which the future timeout in jiffies | 122 | * It takes two parameters: a variable in which the future timeout in jiffies |
122 | * will be stored and a temporary variable holding the time of the last | 123 | * will be stored and a temporary variable holding the time of the last |
@@ -124,9 +125,8 @@ MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); | |||
124 | * holding at least 32 bits. | 125 | * holding at least 32 bits. |
125 | */ | 126 | */ |
126 | #define loop_until_timeout(tout, op_time) \ | 127 | #define loop_until_timeout(tout, op_time) \ |
127 | for (tout = jiffies + msecs_to_jiffies(write_timeout), \ | 128 | for (tout = jiffies + msecs_to_jiffies(write_timeout), op_time = 0; \ |
128 | op_time = jiffies; \ | 129 | op_time ? time_before(op_time, tout) : true; \ |
129 | time_before(op_time, tout); \ | ||
130 | usleep_range(1000, 1500), op_time = jiffies) | 130 | usleep_range(1000, 1500), op_time = jiffies) |
131 | 131 | ||
132 | static const struct i2c_device_id at24_ids[] = { | 132 | static const struct i2c_device_id at24_ids[] = { |