public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Fries <David@Fries.net>
To: linux-kernel@vger.kernel.org
Cc: Evgeniy Polyakov <zbr@ioremap.net>, GregKH <greg@kroah.com>
Subject: [PATCH 13/15] w1: use family_data instead of rom in w1_slave
Date: Wed, 15 Jan 2014 22:29:24 -0600	[thread overview]
Message-ID: <1389846566-28862-14-git-send-email-David@Fries.net> (raw)
In-Reply-To: <1389846566-28862-1-git-send-email-David@Fries.net>

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>
---
 drivers/w1/slaves/w1_therm.c |   21 +++++++++++++++++++--
 drivers/w1/w1.h              |    1 -
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index 8b5ff33..1f11a20 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -27,6 +27,7 @@
 #include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/types.h>
+#include <linux/slab.h>
 #include <linux/delay.h>
 
 #include "../w1.h"
@@ -58,6 +59,19 @@ MODULE_ALIAS("w1-family-" __stringify(W1_THERM_DS28EA00));
 static int w1_strong_pullup = 1;
 module_param_named(strong_pullup, w1_strong_pullup, int, 0);
 
+static int w1_therm_add_slave(struct w1_slave *sl)
+{
+	sl->family_data = kzalloc(9, GFP_KERNEL);
+	if (!sl->family_data)
+		return -ENOMEM;
+	return 0;
+}
+
+static void w1_therm_remove_slave(struct w1_slave *sl)
+{
+	kfree(sl->family_data);
+	sl->family_data = NULL;
+}
 
 static ssize_t w1_slave_show(struct device *device,
 	struct device_attribute *attr, char *buf);
@@ -71,6 +85,8 @@ static struct attribute *w1_therm_attrs[] = {
 ATTRIBUTE_GROUPS(w1_therm);
 
 static struct w1_family_ops w1_therm_fops = {
+	.add_slave	= w1_therm_add_slave,
+	.remove_slave	= w1_therm_remove_slave,
 	.groups		= w1_therm_groups,
 };
 
@@ -253,12 +269,13 @@ static ssize_t w1_slave_show(struct device *device,
 	c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n",
 			   crc, (verdict) ? "YES" : "NO");
 	if (verdict)
-		memcpy(sl->rom, rom, sizeof(sl->rom));
+		memcpy(sl->family_data, rom, sizeof(rom));
 	else
 		dev_warn(device, "Read failed CRC check\n");
 
 	for (i = 0; i < 9; ++i)
-		c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]);
+		c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ",
+			      ((u8 *)sl->family_data)[i]);
 
 	c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n",
 		w1_convert_temp(rom, sl->family->fid));
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index 390a730..0eb5050 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -67,7 +67,6 @@ struct w1_slave
 	struct list_head	w1_slave_entry;
 	struct w1_reg_num	reg_num;
 	atomic_t		refcnt;
-	u8			rom[9];
 	int			ttl;
 	unsigned long		flags;
 
-- 
1.7.10.4


  parent reply	other threads:[~2014-01-16  4:34 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-16  4:29 [PATCH 00/14] w1: async netlink, search, fixes, and improvements David Fries
2014-01-16  4:29 ` [PATCH 01/15] w1: fix w1_send_slave dropping a slave id David Fries
2014-01-16  4:29 ` [PATCH 02/15] w1: fixup search to support abort from netlink David Fries
2014-01-16  4:29 ` [PATCH 03/15] w1: Only wake up the search process if it is going to be searching David Fries
2014-01-16  4:29 ` [PATCH 04/15] w1: increase w1_max_slave_count, allow write access David Fries
2014-01-16  4:29 ` [PATCH 05/15] w1: continue slave search where previous left off David Fries
2014-01-16  4:29 ` [PATCH 06/15] w1: new netlink commands, add/remove/list slaves David Fries
2014-01-16  4:29 ` [PATCH 07/15] w1: process w1 netlink commands in w1_process thread David Fries
2014-01-16  4:29 ` [PATCH 08/15] connector: add portid to unicast in addition to broadcasting David Fries
2014-01-16  4:29 ` [PATCH 09/15] w1: reply only to the requester portid David Fries
2014-01-16  4:29 ` [PATCH 10/15] w1: ds2490 reduce magic numbers David Fries
2014-01-16  4:29 ` [PATCH 11/15] w1: ds2490 USB setup fixes David Fries
2014-01-16  4:29 ` [PATCH 12/15] w1: ds2490 fix and enable hardware search David Fries
2014-01-16  4:29 ` David Fries [this message]
2014-01-16  4:29 ` [PATCH 14/15] w1: format for DocBook and fixes David Fries
2014-01-16  4:29 ` [PATCH 15/15] w1: hold bus_mutex in netlink and search David Fries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389846566-28862-14-git-send-email-David@Fries.net \
    --to=david@fries.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zbr@ioremap.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox