All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Jean Delvare <jdelvare@suse.com>, Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 07/10] hwmon: (w83l786ng) Replace function macros with explicit code
Date: Tue, 27 Dec 2016 15:28:25 -0800	[thread overview]
Message-ID: <1482881308-13550-8-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1482881308-13550-1-git-send-email-linux@roeck-us.net>

Replace function macros with explicit code to to reduce code obfuscation
and to simplify auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} and
SENSOR_ATTR_{RO,RW}.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/w83l786ng.c | 158 ++++++++++++++++++++++++++++++----------------
 1 file changed, 105 insertions(+), 53 deletions(-)

diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
index 330299613d38..cc3845358544 100644
--- a/drivers/hwmon/w83l786ng.c
+++ b/drivers/hwmon/w83l786ng.c
@@ -231,43 +231,72 @@ static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
 	return data;
 }
 
-/* following are the sysfs callback functions */
-#define show_in_reg(reg) \
-static ssize_t \
-show_##reg(struct device *dev, struct device_attribute *attr, \
-	   char *buf) \
-{ \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	struct w83l786ng_data *data = w83l786ng_update_device(dev); \
-	return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
+static ssize_t
+show_in(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
+}
+
+static ssize_t
+show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
+}
+
+static ssize_t
+show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
 }
 
-show_in_reg(in)
-show_in_reg(in_min)
-show_in_reg(in_max)
-
-#define store_in_reg(REG, reg) \
-static ssize_t \
-store_in_##reg(struct device *dev, struct device_attribute *attr, \
-	       const char *buf, size_t count) \
-{ \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	struct w83l786ng_data *data = dev_get_drvdata(dev); \
-	struct i2c_client *client = data->client; \
-	unsigned long val; \
-	int err = kstrtoul(buf, 10, &val); \
-	if (err) \
-		return err; \
-	mutex_lock(&data->update_lock); \
-	data->in_##reg[nr] = IN_TO_REG(val); \
-	w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
-			      data->in_##reg[nr]); \
-	mutex_unlock(&data->update_lock); \
-	return count; \
+static ssize_t
+store_in_min(struct device *dev, struct device_attribute *attr, const char *buf,
+	     size_t count)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = dev_get_drvdata(dev);
+	struct i2c_client *client = data->client;
+	unsigned long val;
+	int err = kstrtoul(buf, 10, &val);
+
+	if (err)
+		return err;
+	mutex_lock(&data->update_lock);
+	data->in_min[nr] = IN_TO_REG(val);
+	w83l786ng_write_value(client, W83L786NG_REG_IN_MIN(nr),
+			      data->in_min[nr]);
+	mutex_unlock(&data->update_lock);
+	return count;
 }
 
-store_in_reg(MIN, min)
-store_in_reg(MAX, max)
+static ssize_t
+store_in_max(struct device *dev, struct device_attribute *attr, const char *buf,
+	     size_t count)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = dev_get_drvdata(dev);
+	struct i2c_client *client = data->client;
+	unsigned long val;
+	int err = kstrtoul(buf, 10, &val);
+
+	if (err)
+		return err;
+	mutex_lock(&data->update_lock);
+	data->in_max[nr] = IN_TO_REG(val);
+	w83l786ng_write_value(client, W83L786NG_REG_IN_MAX(nr),
+			      data->in_max[nr]);
+	mutex_unlock(&data->update_lock);
+	return count;
+}
 
 static struct sensor_device_attribute sda_in_input[] = {
 	SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
@@ -287,18 +316,27 @@ static struct sensor_device_attribute sda_in_max[] = {
 	SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
 };
 
-#define show_fan_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-			  char *buf) \
-{ \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	struct w83l786ng_data *data = w83l786ng_update_device(dev); \
-	return sprintf(buf, "%d\n", \
-		FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
+static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n",
+		       FAN_FROM_REG(data->fan[nr],
+				    DIV_FROM_REG(data->fan_div[nr])));
 }
 
-show_fan_reg(fan);
-show_fan_reg(fan_min);
+static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	int nr = to_sensor_dev_attr(attr)->index;
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+
+	return sprintf(buf, "%d\n",
+		       FAN_FROM_REG(data->fan_min[nr],
+				    DIV_FROM_REG(data->fan_div[nr])));
+}
 
 static ssize_t
 store_fan_min(struct device *dev, struct device_attribute *attr,
@@ -471,18 +509,32 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
 		      show_temp, store_temp, 1, 2),
 };
 
-#define show_pwm_reg(reg) \
-static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
-			  char *buf) \
-{ \
-	struct w83l786ng_data *data = w83l786ng_update_device(dev); \
-	int nr = to_sensor_dev_attr(attr)->index; \
-	return sprintf(buf, "%d\n", data->reg[nr]); \
+static ssize_t show_pwm_mode(struct device *dev, struct device_attribute *attr,
+			     char *buf)
+{
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+	int nr = to_sensor_dev_attr(attr)->index;
+
+	return sprintf(buf, "%d\n", data->pwm_mode[nr]);
 }
 
-show_pwm_reg(pwm_mode)
-show_pwm_reg(pwm_enable)
-show_pwm_reg(pwm)
+static ssize_t show_pwm_enable(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+	int nr = to_sensor_dev_attr(attr)->index;
+
+	return sprintf(buf, "%d\n", data->pwm_enable[nr]);
+}
+
+static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct w83l786ng_data *data = w83l786ng_update_device(dev);
+	int nr = to_sensor_dev_attr(attr)->index;
+
+	return sprintf(buf, "%d\n", data->pwm[nr]);
+}
 
 static ssize_t
 store_pwm_mode(struct device *dev, struct device_attribute *attr,
-- 
2.7.4

  parent reply	other threads:[~2016-12-27 23:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27 23:28 [PATCH 01/10] hwmon: Prepare for SENSOR_DEVICE_ATTR_{RO,RW,WO} conversion Guenter Roeck
2016-12-27 23:28 ` [PATCH 01/10] hwmon: Introduce SENSOR_DEVICE_ATTR_{RO,RW,WO} and variants Guenter Roeck
2016-12-27 23:28 ` [PATCH 02/10] hwmon: (wm831x-hwmon) Replace macros generating sensor attributes Guenter Roeck
2016-12-27 23:28 ` [PATCH 03/10] hwmon: (it87) Prepare for auto-conversion to SENSOR_DEVICE_ATTR_{RO,RW} Guenter Roeck
2016-12-27 23:28 ` [PATCH 04/10] hwmon: (max1668) " Guenter Roeck
2016-12-27 23:28 ` [PATCH 05/10] hwmon: (f75375s) Replace function macro with explicit code Guenter Roeck
2016-12-27 23:28 ` [PATCH 06/10] hwmon: (ultra45_env) Replace macros generating sensor attributes Guenter Roeck
2016-12-27 23:28 ` Guenter Roeck [this message]
2016-12-27 23:28 ` [PATCH 08/10] hwmon: (w83791d) Replace function macros with explicit code Guenter Roeck
2016-12-27 23:28 ` [PATCH 09/10] hwmon: (w83627ehf) " Guenter Roeck
2016-12-27 23:28 ` [PATCH 10/10] hwmon: (adt7411) Replace macro generating sensor attributes Guenter Roeck

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=1482881308-13550-8-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    /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 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.