From patchwork Tue Dec 27 23:28:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9489925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 267F9602A7 for ; Tue, 27 Dec 2016 23:28:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0992E1FF1D for ; Tue, 27 Dec 2016 23:28:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F29BB2094F; Tue, 27 Dec 2016 23:28:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 722711FF1D for ; Tue, 27 Dec 2016 23:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932849AbcL0X2m (ORCPT ); Tue, 27 Dec 2016 18:28:42 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:55763 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932719AbcL0X2l (ORCPT ); Tue, 27 Dec 2016 18:28:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=References:In-Reply-To:Message-Id:Date:Subject: Cc:To:From; bh=MvpF5Ot4PNXdRV1izg1FUNMlYjXJUPgL69NQiesLh04=; b=hfcfjHd0WEBX2u 1Vj+yGGvv6lFd3kLpLA+GTZ2HgQ85ODMRjUYsc6jdC2obH/92BceI5w7QSxeWdBdpfrQBn/pdAUYm 8PwvnWi7RgBPtJS9NjDBGiZnlvzOciDVQq4FLpxoq9lJDGbDOX+o/9920VIFNiduxuNHdvxuMaLCm XTFaDp6ot5iO3p54gzhlQn9A++sAS+Rtks+KlZcykAwQGvEjUGlFnHG0/x6S+nANnvDIgQJPuoc6j v2wprsD/xE2jbx7U3E2kr2S9AHkqAf5vgLk/BbljZKBqYqhDEBX3SI8tqRrw/gScRhI0T1bg5qLOI 4AmmTIODTMXRfB6GeJ6g==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:51580 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cM1Ae-0044Cq-4C; Tue, 27 Dec 2016 23:28:40 +0000 From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 07/10] hwmon: (w83l786ng) Replace function macros with explicit code Date: Tue, 27 Dec 2016 15:28:25 -0800 Message-Id: <1482881308-13550-8-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482881308-13550-1-git-send-email-linux@roeck-us.net> References: <1482881308-13550-1-git-send-email-linux@roeck-us.net> X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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,