Skip to content

Commit e71084a

Browse files
cladischStefan Richter
authored andcommitted
firewire: core: fix card->reset_jiffies overflow
On a 32-bit machine with, e.g., HZ=1000, jiffies will overflow after about 50 days, so if there are between 25 and 50 days between bus resets, the card->reset_jiffies comparisons can get wrong results. To fix this, ensure that this timestamp always uses 64 bits. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: "Stefan Richter" <stefanr@s5r6.in-berlin.de>
1 parent dbc9880 commit e71084a

5 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎drivers/firewire/core-card.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static void br_work(struct work_struct *work)
233233

234234
/* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
235235
if (card->reset_jiffies != 0 &&
236-
time_is_after_jiffies(card->reset_jiffies + 2 * HZ)) {
236+
time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) {
237237
if (!schedule_delayed_work(&card->br_work, 2 * HZ))
238238
fw_card_put(card);
239239
return;
@@ -316,7 +316,8 @@ static void bm_work(struct work_struct *work)
316316
irm_id = card->irm_node->node_id;
317317
local_id = card->local_node->node_id;
318318

319-
grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 8));
319+
grace = time_after64(get_jiffies_64(),
320+
card->reset_jiffies + DIV_ROUND_UP(HZ, 8));
320321

321322
if ((is_next_generation(generation, card->bm_generation) &&
322323
!card->bm_abdicate) ||

‎drivers/firewire/core-cdev.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,8 @@ static void iso_resource_work(struct work_struct *work)
12051205
todo = r->todo;
12061206
/* Allow 1000ms grace period for other reallocations. */
12071207
if (todo == ISO_RES_ALLOC &&
1208-
time_is_after_jiffies(client->device->card->reset_jiffies + HZ)) {
1208+
time_before64(get_jiffies_64(),
1209+
client->device->card->reset_jiffies + HZ)) {
12091210
schedule_iso_resource(r, DIV_ROUND_UP(HZ, 3));
12101211
skip = true;
12111212
} else {

‎drivers/firewire/core-device.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ static void fw_device_shutdown(struct work_struct *work)
747747
container_of(work, struct fw_device, work.work);
748748
int minor = MINOR(device->device.devt);
749749

750-
if (time_is_after_jiffies(device->card->reset_jiffies + SHUTDOWN_DELAY)
750+
if (time_before64(get_jiffies_64(),
751+
device->card->reset_jiffies + SHUTDOWN_DELAY)
751752
&& !list_empty(&device->card->link)) {
752753
schedule_delayed_work(&device->work, SHUTDOWN_DELAY);
753754
return;

‎drivers/firewire/core-topology.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation,
545545
*/
546546
smp_wmb();
547547
card->generation = generation;
548-
card->reset_jiffies = jiffies;
548+
card->reset_jiffies = get_jiffies_64();
549549
card->bm_node_id = 0xffff;
550550
card->bm_abdicate = bm_abdicate;
551551
fw_schedule_bm_work(card, 0);

‎include/linux/firewire.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ struct fw_card {
8989
int current_tlabel;
9090
u64 tlabel_mask;
9191
struct list_head transaction_list;
92-
unsigned long reset_jiffies;
92+
u64 reset_jiffies;
9393

9494
u32 split_timeout_hi;
9595
u32 split_timeout_lo;

0 commit comments

Comments
 (0)