]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
w1: ds2413: fix state byte comparision
authorMariusz Bialonczyk <manio@skyboo.net>
Thu, 30 May 2019 07:51:25 +0000 (09:51 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 6 Jun 2019 14:15:21 +0000 (16:15 +0200)
This commit is fixing a smatch warning:
drivers/w1/slaves/w1_ds2413.c:61 state_read() warn: impossible condition '(*buf == 255) => ((-128)-127 == 255)'
by creating additional u8 variable for the bus reading and comparision

Reported-by: kbuild test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 3856032a0628 ("w1: ds2413: when the slave is not responding during read, select it again")
Signed-off-by: Mariusz Bialonczyk <manio@skyboo.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/w1/slaves/w1_ds2413.c

index 21f08ac8a4e09504a530c0b2778f3f0e5c491209..3364ad276b156748c31f16c4ce840adffd48f8d0 100644 (file)
@@ -33,6 +33,7 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
        struct w1_slave *sl = kobj_to_w1_slave(kobj);
        unsigned int retries = W1_F3A_RETRIES;
        ssize_t bytes_read = -EIO;
+       u8 state;
 
        dev_dbg(&sl->dev,
                "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p",
@@ -53,12 +54,13 @@ static ssize_t state_read(struct file *filp, struct kobject *kobj,
        while (retries--) {
                w1_write_8(sl->master, W1_F3A_FUNC_PIO_ACCESS_READ);
 
-               *buf = w1_read_8(sl->master);
-               if ((*buf & 0x0F) == ((~*buf >> 4) & 0x0F)) {
+               state = w1_read_8(sl->master);
+               if ((state & 0x0F) == ((~state >> 4) & 0x0F)) {
                        /* complement is correct */
+                       *buf = state;
                        bytes_read = 1;
                        goto out;
-               } else if (*buf == W1_F3A_INVALID_PIO_STATE) {
+               } else if (state == W1_F3A_INVALID_PIO_STATE) {
                        /* slave didn't respond, try to select it again */
                        dev_warn(&sl->dev, "slave device did not respond to PIO_ACCESS_READ, " \
                                            "reselecting, retries left: %d\n", retries);