lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <212a5f51-11d6-c1e7-fb98-fdb755efdf9d@sampaio.xyz>
Date:   Tue, 16 Mar 2021 20:32:28 -0300
From:   Luiz Sampaio <luiz@...paio.xyz>
To:     zbr@...emap.net
Cc:     linux-kernel@...r.kernel.org
Subject: [PATCH] w1: ds2438: fixing bug in get_page function

In the w1_ds2438_get_page function, there is an argument to change the page
number you want to read from the chip. But this was always getting the page
0, not the pageno page. Fixed it.

Also fixed coding style issue.

Signed-off-by: Luiz Sampaio <luiz@...paio.xyz>
---
 drivers/w1/slaves/w1_ds2438.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/w1/slaves/w1_ds2438.c b/drivers/w1/slaves/w1_ds2438.c
index 5cfb0ae23e91..0eb667f0cf6e 100644
--- a/drivers/w1/slaves/w1_ds2438.c
+++ b/drivers/w1/slaves/w1_ds2438.c
@@ -62,13 +62,13 @@ static int w1_ds2438_get_page(struct w1_slave *sl, int pageno, u8 *buf)
         if (w1_reset_select_slave(sl))
             continue;
         w1_buf[0] = W1_DS2438_RECALL_MEMORY;
-        w1_buf[1] = 0x00;
+        w1_buf[1] = pageno;
         w1_write_block(sl->master, w1_buf, 2);
 
         if (w1_reset_select_slave(sl))
             continue;
         w1_buf[0] = W1_DS2438_READ_SCRATCH;
-        w1_buf[1] = 0x00;
+        w1_buf[1] = pageno;
         w1_write_block(sl->master, w1_buf, 2);
 
         count = w1_read_block(sl->master, buf, DS2438_PAGE_SIZE + 1);
@@ -154,11 +154,10 @@ static int w1_ds2438_change_config_bit(struct w1_slave *sl, u8 mask, u8 value)
 
         if ((status & mask) == value)
             return 0;    /* already set as requested */
-        else {
-            /* changing bit */
-            status ^= mask;
-            perform_write = 1;
-        }
+
+        /* changing bit */
+        status ^= mask;
+        perform_write = 1;
         break;
     }
 
@@ -287,9 +286,9 @@ static ssize_t iad_read(struct file *filp, struct kobject *kobj,
     if (!buf)
         return -EINVAL;
 
-    if (w1_ds2438_get_current(sl, &voltage) == 0) {
+    if (w1_ds2438_get_current(sl, &voltage) == 0)
         ret = snprintf(buf, count, "%i\n", voltage);
-    } else
+    else
         ret = -EIO;
 
     return ret;
@@ -338,9 +337,9 @@ static ssize_t temperature_read(struct file *filp, struct kobject *kobj,
     if (!buf)
         return -EINVAL;
 
-    if (w1_ds2438_get_temperature(sl, &temp) == 0) {
+    if (w1_ds2438_get_temperature(sl, &temp) == 0)
         ret = snprintf(buf, count, "%i\n", temp);
-    } else
+    else
         ret = -EIO;
 
     return ret;
@@ -359,9 +358,9 @@ static ssize_t vad_read(struct file *filp, struct kobject *kobj,
     if (!buf)
         return -EINVAL;
 
-    if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VAD, &voltage) == 0) {
+    if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VAD, &voltage) == 0)
         ret = snprintf(buf, count, "%u\n", voltage);
-    } else
+    else
         ret = -EIO;
 
     return ret;
@@ -380,15 +379,15 @@ static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
     if (!buf)
         return -EINVAL;
 
-    if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VDD, &voltage) == 0) {
+    if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VDD, &voltage) == 0)
         ret = snprintf(buf, count, "%u\n", voltage);
-    } else
+    else
         ret = -EIO;
 
     return ret;
 }
 
-static BIN_ATTR(iad, S_IRUGO | S_IWUSR | S_IWGRP, iad_read, iad_write, 0);
+static BIN_ATTR(iad, 0664, iad_read, iad_write, 0);
 static BIN_ATTR_RO(page0, DS2438_PAGE_SIZE);
 static BIN_ATTR_RO(temperature, 0/* real length varies */);
 static BIN_ATTR_RO(vad, 0/* real length varies */);
-- 
2.30.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ