All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] w1: ds2438: fixing bug in get_page function
@ 2021-03-16 23:32 Luiz Sampaio
  0 siblings, 0 replies; only message in thread
From: Luiz Sampaio @ 2021-03-16 23:32 UTC (permalink / raw)
  To: zbr; +Cc: linux-kernel

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@sampaio.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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-16 23:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16 23:32 [PATCH] w1: ds2438: fixing bug in get_page function Luiz Sampaio

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.