NFC: digital: Randomize poll cycles
authorThierry Escande <thierry.escande@linux.intel.com>
Sat, 10 May 2014 11:06:02 +0000 (13:06 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Sun, 25 May 2014 22:42:02 +0000 (00:42 +0200)
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>
net/nfc/digital_core.c

index b105cfb00e76bafe4fa6a3f1af379bd25094a06d..a6ce3c627e4e40ff4a6fcdb0bb0a2704dd0872b0 100644 (file)
@@ -386,6 +386,8 @@ int digital_target_found(struct nfc_digital_dev *ddev,
 
 void digital_poll_next_tech(struct nfc_digital_dev *ddev)
 {
+       u8 rand_mod;
+
        digital_switch_rf(ddev, 0);
 
        mutex_lock(&ddev->poll_lock);
@@ -395,8 +397,8 @@ void digital_poll_next_tech(struct nfc_digital_dev *ddev)
                return;
        }
 
-       ddev->poll_tech_index = (ddev->poll_tech_index + 1) %
-                               ddev->poll_tech_count;
+       get_random_bytes(&rand_mod, sizeof(rand_mod));
+       ddev->poll_tech_index = rand_mod % ddev->poll_tech_count;
 
        mutex_unlock(&ddev->poll_lock);