Skip to content

Commit 9dc3370

Browse files
Thierry EscandeSamuel Ortiz
authored andcommitted
NFC: digital: Randomize poll cycles
This change adds some entropy to polling cycles, choosing the next polling rf technology randomly. This reflects the change done in the pn533 driver, avoiding possible infinite loop for devices that export 2 targets on 2 different modulations. If the first target is not readable, we will stay in an error loop for ever. Signed-off-by: Thierry Escande <thierry.escande@linux.intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 00e625d commit 9dc3370

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎net/nfc/digital_core.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ int digital_target_found(struct nfc_digital_dev *ddev,
386386

387387
void digital_poll_next_tech(struct nfc_digital_dev *ddev)
388388
{
389+
u8 rand_mod;
390+
389391
digital_switch_rf(ddev, 0);
390392

391393
mutex_lock(&ddev->poll_lock);
@@ -395,8 +397,8 @@ void digital_poll_next_tech(struct nfc_digital_dev *ddev)
395397
return;
396398
}
397399

398-
ddev->poll_tech_index = (ddev->poll_tech_index + 1) %
399-
ddev->poll_tech_count;
400+
get_random_bytes(&rand_mod, sizeof(rand_mod));
401+
ddev->poll_tech_index = rand_mod % ddev->poll_tech_count;
400402

401403
mutex_unlock(&ddev->poll_lock);
402404

0 commit comments

Comments
 (0)