Skip to content

Commit eb2c0da

Browse files
dfriesgregkh
authored andcommitted
w1: use family_data instead of rom in w1_slave
The first line printed from w1_slave gives the context of the w1 device. So does the second line, but if the CRC check failed, the second line contains the last successful result. It is confusing when it prints the temperature next to the line that might be a previous conversion and has nothing to do with that printed temperature value. Modify the code to store the last good conversion in family_data, which is designed for custom data structures. Signed-off-by: David Fries <David@Fries.net> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d53f0a2 commit eb2c0da

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

‎drivers/w1/slaves/w1_therm.c‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/sched.h>
2828
#include <linux/device.h>
2929
#include <linux/types.h>
30+
#include <linux/slab.h>
3031
#include <linux/delay.h>
3132

3233
#include "../w1.h"
@@ -58,6 +59,19 @@ MODULE_ALIAS("w1-family-" __stringify(W1_THERM_DS28EA00));
5859
static int w1_strong_pullup = 1;
5960
module_param_named(strong_pullup, w1_strong_pullup, int, 0);
6061

62+
static int w1_therm_add_slave(struct w1_slave *sl)
63+
{
64+
sl->family_data = kzalloc(9, GFP_KERNEL);
65+
if (!sl->family_data)
66+
return -ENOMEM;
67+
return 0;
68+
}
69+
70+
static void w1_therm_remove_slave(struct w1_slave *sl)
71+
{
72+
kfree(sl->family_data);
73+
sl->family_data = NULL;
74+
}
6175

6276
static ssize_t w1_slave_show(struct device *device,
6377
struct device_attribute *attr, char *buf);
@@ -71,6 +85,8 @@ static struct attribute *w1_therm_attrs[] = {
7185
ATTRIBUTE_GROUPS(w1_therm);
7286

7387
static struct w1_family_ops w1_therm_fops = {
88+
.add_slave = w1_therm_add_slave,
89+
.remove_slave = w1_therm_remove_slave,
7490
.groups = w1_therm_groups,
7591
};
7692

@@ -253,12 +269,13 @@ static ssize_t w1_slave_show(struct device *device,
253269
c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n",
254270
crc, (verdict) ? "YES" : "NO");
255271
if (verdict)
256-
memcpy(sl->rom, rom, sizeof(sl->rom));
272+
memcpy(sl->family_data, rom, sizeof(rom));
257273
else
258274
dev_warn(device, "Read failed CRC check\n");
259275

260276
for (i = 0; i < 9; ++i)
261-
c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]);
277+
c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ",
278+
((u8 *)sl->family_data)[i]);
262279

263280
c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n",
264281
w1_convert_temp(rom, sl->family->fid));

‎drivers/w1/w1.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ struct w1_slave
6767
struct list_head w1_slave_entry;
6868
struct w1_reg_num reg_num;
6969
atomic_t refcnt;
70-
u8 rom[9];
7170
int ttl;
7271
unsigned long flags;
7372

0 commit comments

Comments
 (0)