From patchwork Tue Dec 27 23:28:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 9489927 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 E7B24602A7 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 CAEDE1FF1D for ; Tue, 27 Dec 2016 23:28:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF9C92094F; Tue, 27 Dec 2016 23:28:43 +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 510161FF1D for ; Tue, 27 Dec 2016 23:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932859AbcL0X2n (ORCPT ); Tue, 27 Dec 2016 18:28:43 -0500 Received: from bh-25.webhostbox.net ([208.91.199.152]:55776 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932719AbcL0X2m (ORCPT ); Tue, 27 Dec 2016 18:28:42 -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=VFO1Xv+J7mbk62FBSY4l9AHAfDF6i2jGZi2UcouHVWE=; b=HeR4KHKbTHOyeN S4Med+5U7isrGNNraHeqO9x6Sx4J0THXCO+kw99moEn30RubPfz+E8mbh0LBIqsq4gmoRRPlVnhrC M5sgqY9M1GRbslhp7I6p+2NNm5Z14khtgV1Hce6klEmVugx1AruGTG0SZqrLNWD2NRaCYNAbs5sF3 1tvfa21XVAybRq2uf0gtqsDmlgfwvBSoxTwOVUKbRSyxhbt36zpMllvYHvW14LVIIF8q+OUD5yDzN /Rf7EojKmt7XrjLEpsSVakP1ynHP0UBnXMbNx+tYRPhtnJVchmgE0yuHTkomU6gYMoDh36oW0n7rI DG+8aeh+t5xED6mYFlaQ==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:51582 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.86_1) (envelope-from ) id 1cM1Af-0044HC-Hv; Tue, 27 Dec 2016 23:28:42 +0000 From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 08/10] hwmon: (w83791d) Replace function macros with explicit code Date: Tue, 27 Dec 2016 15:28:26 -0800 Message-Id: <1482881308-13550-9-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/w83791d.c | 140 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 47 deletions(-) diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c index 8af6081b4ab4..9a9d89697672 100644 --- a/drivers/hwmon/w83791d.c +++ b/drivers/hwmon/w83791d.c @@ -363,44 +363,82 @@ static struct i2c_driver w83791d_driver = { }; /* 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) \ -{ \ - struct sensor_device_attribute *sensor_attr = \ - to_sensor_dev_attr(attr); \ - struct w83791d_data *data = w83791d_update_device(dev); \ - int nr = sensor_attr->index; \ - 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) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct w83791d_data *data = w83791d_update_device(dev); + int nr = sensor_attr->index; + + 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) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct w83791d_data *data = w83791d_update_device(dev); + int nr = sensor_attr->index; + + 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) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct w83791d_data *data = w83791d_update_device(dev); + int nr = sensor_attr->index; + + return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); +} + +static ssize_t store_in_min(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = + to_sensor_dev_attr(attr); + struct i2c_client *client = to_i2c_client(dev); + struct w83791d_data *data = i2c_get_clientdata(client); + int nr = sensor_attr->index; + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; + mutex_lock(&data->update_lock); + data->in_min[nr] = IN_TO_REG(val); + w83791d_write(client, W83791D_REG_IN_MIN[nr], data->in_min[nr]); + mutex_unlock(&data->update_lock); + + return count; } -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) \ -{ \ - struct sensor_device_attribute *sensor_attr = \ - to_sensor_dev_attr(attr); \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83791d_data *data = i2c_get_clientdata(client); \ - int nr = sensor_attr->index; \ - 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); \ - w83791d_write(client, W83791D_REG_IN_##REG[nr], data->in_##reg[nr]); \ - mutex_unlock(&data->update_lock); \ - \ - return count; \ +static ssize_t store_in_max(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct sensor_device_attribute *sensor_attr = + to_sensor_dev_attr(attr); + struct i2c_client *client = to_i2c_client(dev); + struct w83791d_data *data = i2c_get_clientdata(client); + int nr = sensor_attr->index; + unsigned long val; + int err; + + err = kstrtoul(buf, 10, &val); + if (err) + return err; + mutex_lock(&data->update_lock); + data->in_max[nr] = IN_TO_REG(val); + w83791d_write(client, W83791D_REG_IN_MAX[nr], data->in_max[nr]); + mutex_unlock(&data->update_lock); + + return count; } -store_in_reg(MIN, min); -store_in_reg(MAX, max); static struct sensor_device_attribute sda_in_input[] = { SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0), @@ -529,20 +567,28 @@ static struct sensor_device_attribute sda_in_alarm[] = { SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 14), }; -#define show_fan_reg(reg) \ -static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ - char *buf) \ -{ \ - struct sensor_device_attribute *sensor_attr = \ - to_sensor_dev_attr(attr); \ - struct w83791d_data *data = w83791d_update_device(dev); \ - int nr = sensor_attr->index; \ - 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) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct w83791d_data *data = w83791d_update_device(dev); + int nr = sensor_attr->index; + + 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) +{ + struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); + struct w83791d_data *data = w83791d_update_device(dev); + int nr = sensor_attr->index; + + 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, const char *buf, size_t count)