[PATCH 11/35] W1: recode w1_slave_found logic

From: David Fries
Date: Fri Mar 28 2008 - 09:01:01 EST


w1.c 1.14
Rewrote the confusion logic in w1_slave_found. The function is called
for each device detected by a bus search. If the slave was found a
flag is set to show that it is still active. If it wasn't found it
will be attached.

It would previously search through the slave list marking the slave
active if it was found. It used a counter to determine if it exited
the loop early. If it searched through all slaves in the list the crc
value was verified and then attached the device if it did.

Now it uses the new w1_attach_slave_device function to find the slave
device and mark the device active if it was found. If the slave
wasn't found it will add the device if the crc is correct. Much more
understandable.

Signed-off-by: David Fries <david@xxxxxxxxx>
---
drivers/w1/w1.c | 24 ++++++------------------
1 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 3ca1f4d..b18eedb 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -814,24 +814,12 @@ static void w1_slave_found(struct w1_master *dev, u64 rn)

tmp = (struct w1_reg_num *) &rn;

- slave_count = 0;
- list_for_each(ent, &dev->slist) {
-
- sl = list_entry(ent, struct w1_slave, w1_slave_entry);
-
- if (sl->reg_num.family == tmp->family &&
- sl->reg_num.id == tmp->id &&
- sl->reg_num.crc == tmp->crc) {
- set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags);
- break;
- }
-
- slave_count++;
- }
-
- if (slave_count == dev->slave_count &&
- rn && ((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn_le, 7)) {
- w1_attach_slave_device(dev, tmp);
+ sl = w1_slave_search_device(dev, tmp);
+ if(sl) {
+ set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags);
+ } else {
+ if(rn && tmp->crc == w1_calc_crc8((u8 *)&rn_le, 7))
+ w1_attach_slave_device(dev, tmp);
}

atomic_dec(&dev->refcnt);
--
1.4.4.4

Attachment: pgp00000.pgp
Description: PGP signature