From patchwork Mon Dec 10 22:08:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guenter Roeck X-Patchwork-Id: 10722661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5C1E6C5 for ; Mon, 10 Dec 2018 22:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A44D427968 for ; Mon, 10 Dec 2018 22:09:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98B542A755; Mon, 10 Dec 2018 22:09:30 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 CBB6C27968 for ; Mon, 10 Dec 2018 22:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729603AbeLJWJ3 (ORCPT ); Mon, 10 Dec 2018 17:09:29 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43218 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729387AbeLJWJ3 (ORCPT ); Mon, 10 Dec 2018 17:09:29 -0500 Received: by mail-pl1-f194.google.com with SMTP id gn14so5884525plb.10 for ; Mon, 10 Dec 2018 14:09:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=XAyvfOKPhKeHxxDfvBfXLn72QiWV/3arU/dqGN6YBoQ=; b=Fvif1SLcQ6uTzPKRffG0QLALTPoqBU41zyTeAYe0y8QbO52FF2CM0dLKgdY2X5pSJl LCO2tNgyTMY9ZxJvQRSN2U1GbN4nlYueNBfQjBYiw8uHHr+oi7jKxMyMGXeklh9PIgdR 8oqrJMy47Ap3fdsHqUd4hUojHTIvgg2XdY67TxuCJ+cLQ129GglAWD/x5XYVPYxctWU2 t5lz+EsgonrerAzEkDCzLoShnsC8WQvZNP0Ji931AXJMYEoNyeJZ67K1IDIi1FKowrL+ XZAwLMhjgK9bB8jd19fs7ECtH6XhMq4dPz3txgqAJads5i1VyeBlP0Cn4a5ShFdGeJ32 v0TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=XAyvfOKPhKeHxxDfvBfXLn72QiWV/3arU/dqGN6YBoQ=; b=oGC63RVka2z9/eVurdyJc4aORmLD41ZPoz/q4KmT+czQRi4h4LxNEzSkixRvmXTNop oPimdPFOWdaDsrLmPRsy174WqpCXSgPUY1MhRT5Xk1Xe613WNRZPi/+Sva4J4I5rZSpg 6lSBUGKqlFMVxboKemXHzDHJm9vubdW0l5jw3iyk0GddGxQV/m05rcV9cv6FNO0vpYzP McYoCa5xyxMIuZTVea5LO13PQ2lARMTnGZCPBC/lmzO26eQZJXitl/+zRKySSlY06B87 TALBknjWmT+qvPi0pNTfFaRli7bfIhNICiCuMMRXrGgV/3SzFMiE+I/RDlbs602qM+Dg ARdg== X-Gm-Message-State: AA+aEWZ6/uiugEvReSk1gkVkk9lbIp4IkF5wVav4MkucD/N3YyQbHVL0 /tzFuML18MTaz/zzrYDJlBs91/xc X-Google-Smtp-Source: AFSGD/VRTmF+hkJIq+498T8I+RtEinQMmdiTwoMDOa/qKUzB8hoyvEk0RQKaKmy0gLTOArfWzIWDhQ== X-Received: by 2002:a17:902:724a:: with SMTP id c10mr14053646pll.51.1544479768508; Mon, 10 Dec 2018 14:09:28 -0800 (PST) Received: from localhost ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id z13sm17499672pgf.84.2018.12.10.14.09.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 14:09:27 -0800 (PST) From: Guenter Roeck To: Hardware Monitoring Cc: Jean Delvare , Guenter Roeck Subject: [PATCH 26/30] hwmon: (emc1403) Use permission specific SENSOR[_DEVICE]_ATTR variants Date: Mon, 10 Dec 2018 14:08:44 -0800 Message-Id: <1544479728-30077-27-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544479728-30077-1-git-send-email-linux@roeck-us.net> References: <1544479728-30077-1-git-send-email-linux@roeck-us.net> 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 Use SENSOR[_DEVICE]_ATTR[_2]_{RO,RW,WO} to simplify the source code, to improve readbility, and to reduce the chance of inconsistencies. Also replace any remaining S_ in the driver with octal values. The conversion was done automatically with coccinelle. The semantic patches and the scripts used to generate this commit log are available at https://github.com/groeck/coccinelle-patches/hwmon/. This patch does not introduce functional changes. It was verified by compiling the old and new files and comparing text and data sizes. Signed-off-by: Guenter Roeck --- drivers/hwmon/emc1403.c | 164 ++++++++++++++++++++---------------------------- 1 file changed, 69 insertions(+), 95 deletions(-) diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c index aaebeb726d6a..bdab47ac9e9a 100644 --- a/drivers/hwmon/emc1403.c +++ b/drivers/hwmon/emc1403.c @@ -43,8 +43,8 @@ struct thermal_data { const struct attribute_group *groups[4]; }; -static ssize_t show_temp(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t temp_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct thermal_data *data = dev_get_drvdata(dev); @@ -57,8 +57,8 @@ static ssize_t show_temp(struct device *dev, return sprintf(buf, "%d000\n", val); } -static ssize_t show_bit(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t bit_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); struct thermal_data *data = dev_get_drvdata(dev); @@ -71,8 +71,8 @@ static ssize_t show_bit(struct device *dev, return sprintf(buf, "%d\n", !!(val & sda->index)); } -static ssize_t store_temp(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static ssize_t temp_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct thermal_data *data = dev_get_drvdata(dev); @@ -88,8 +88,8 @@ static ssize_t store_temp(struct device *dev, return count; } -static ssize_t store_bit(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static ssize_t bit_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr); struct thermal_data *data = dev_get_drvdata(dev); @@ -128,20 +128,20 @@ static ssize_t show_hyst_common(struct device *dev, return sprintf(buf, "%d000\n", is_min ? limit + hyst : limit - hyst); } -static ssize_t show_hyst(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t hyst_show(struct device *dev, struct device_attribute *attr, + char *buf) { return show_hyst_common(dev, attr, buf, false); } -static ssize_t show_min_hyst(struct device *dev, +static ssize_t min_hyst_show(struct device *dev, struct device_attribute *attr, char *buf) { return show_hyst_common(dev, attr, buf, true); } -static ssize_t store_hyst(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static ssize_t hyst_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct sensor_device_attribute *sda = to_sensor_dev_attr(attr); struct thermal_data *data = dev_get_drvdata(dev); @@ -173,80 +173,54 @@ static ssize_t store_hyst(struct device *dev, * Sensors. We pass the actual i2c register to the methods. */ -static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x06); -static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x05); -static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x20); -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0x00); -static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, - show_bit, NULL, 0x36, 0x01); -static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, - show_bit, NULL, 0x35, 0x01); -static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, - show_bit, NULL, 0x37, 0x01); -static SENSOR_DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x06); -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_hyst, NULL, 0x05); -static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO | S_IWUSR, - show_hyst, store_hyst, 0x20); - -static SENSOR_DEVICE_ATTR(temp2_min, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x08); -static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x07); -static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x19); -static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0x01); -static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x02); -static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, - show_bit, NULL, 0x36, 0x02); -static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, - show_bit, NULL, 0x35, 0x02); -static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, - show_bit, NULL, 0x37, 0x02); -static SENSOR_DEVICE_ATTR(temp2_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x08); -static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO, show_hyst, NULL, 0x07); -static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_hyst, NULL, 0x19); - -static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x16); -static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x15); -static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x1A); -static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 0x23); -static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x04); -static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, - show_bit, NULL, 0x36, 0x04); -static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, - show_bit, NULL, 0x35, 0x04); -static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, - show_bit, NULL, 0x37, 0x04); -static SENSOR_DEVICE_ATTR(temp3_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x16); -static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO, show_hyst, NULL, 0x15); -static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_hyst, NULL, 0x1A); - -static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x2D); -static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x2C); -static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO | S_IWUSR, - show_temp, store_temp, 0x30); -static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 0x2A); -static SENSOR_DEVICE_ATTR_2(temp4_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x08); -static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO, - show_bit, NULL, 0x36, 0x08); -static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO, - show_bit, NULL, 0x35, 0x08); -static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO, - show_bit, NULL, 0x37, 0x08); -static SENSOR_DEVICE_ATTR(temp4_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x2D); -static SENSOR_DEVICE_ATTR(temp4_max_hyst, S_IRUGO, show_hyst, NULL, 0x2C); -static SENSOR_DEVICE_ATTR(temp4_crit_hyst, S_IRUGO, show_hyst, NULL, 0x30); - -static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR, - show_bit, store_bit, 0x03, 0x40); +static SENSOR_DEVICE_ATTR_RW(temp1_min, temp, 0x06); +static SENSOR_DEVICE_ATTR_RW(temp1_max, temp, 0x05); +static SENSOR_DEVICE_ATTR_RW(temp1_crit, temp, 0x20); +static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0x00); +static SENSOR_DEVICE_ATTR_2_RO(temp1_min_alarm, bit, 0x36, 0x01); +static SENSOR_DEVICE_ATTR_2_RO(temp1_max_alarm, bit, 0x35, 0x01); +static SENSOR_DEVICE_ATTR_2_RO(temp1_crit_alarm, bit, 0x37, 0x01); +static SENSOR_DEVICE_ATTR_RO(temp1_min_hyst, min_hyst, 0x06); +static SENSOR_DEVICE_ATTR_RO(temp1_max_hyst, hyst, 0x05); +static SENSOR_DEVICE_ATTR_RW(temp1_crit_hyst, hyst, 0x20); + +static SENSOR_DEVICE_ATTR_RW(temp2_min, temp, 0x08); +static SENSOR_DEVICE_ATTR_RW(temp2_max, temp, 0x07); +static SENSOR_DEVICE_ATTR_RW(temp2_crit, temp, 0x19); +static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 0x01); +static SENSOR_DEVICE_ATTR_2_RO(temp2_fault, bit, 0x1b, 0x02); +static SENSOR_DEVICE_ATTR_2_RO(temp2_min_alarm, bit, 0x36, 0x02); +static SENSOR_DEVICE_ATTR_2_RO(temp2_max_alarm, bit, 0x35, 0x02); +static SENSOR_DEVICE_ATTR_2_RO(temp2_crit_alarm, bit, 0x37, 0x02); +static SENSOR_DEVICE_ATTR_RO(temp2_min_hyst, min_hyst, 0x08); +static SENSOR_DEVICE_ATTR_RO(temp2_max_hyst, hyst, 0x07); +static SENSOR_DEVICE_ATTR_RO(temp2_crit_hyst, hyst, 0x19); + +static SENSOR_DEVICE_ATTR_RW(temp3_min, temp, 0x16); +static SENSOR_DEVICE_ATTR_RW(temp3_max, temp, 0x15); +static SENSOR_DEVICE_ATTR_RW(temp3_crit, temp, 0x1A); +static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 0x23); +static SENSOR_DEVICE_ATTR_2_RO(temp3_fault, bit, 0x1b, 0x04); +static SENSOR_DEVICE_ATTR_2_RO(temp3_min_alarm, bit, 0x36, 0x04); +static SENSOR_DEVICE_ATTR_2_RO(temp3_max_alarm, bit, 0x35, 0x04); +static SENSOR_DEVICE_ATTR_2_RO(temp3_crit_alarm, bit, 0x37, 0x04); +static SENSOR_DEVICE_ATTR_RO(temp3_min_hyst, min_hyst, 0x16); +static SENSOR_DEVICE_ATTR_RO(temp3_max_hyst, hyst, 0x15); +static SENSOR_DEVICE_ATTR_RO(temp3_crit_hyst, hyst, 0x1A); + +static SENSOR_DEVICE_ATTR_RW(temp4_min, temp, 0x2D); +static SENSOR_DEVICE_ATTR_RW(temp4_max, temp, 0x2C); +static SENSOR_DEVICE_ATTR_RW(temp4_crit, temp, 0x30); +static SENSOR_DEVICE_ATTR_RO(temp4_input, temp, 0x2A); +static SENSOR_DEVICE_ATTR_2_RO(temp4_fault, bit, 0x1b, 0x08); +static SENSOR_DEVICE_ATTR_2_RO(temp4_min_alarm, bit, 0x36, 0x08); +static SENSOR_DEVICE_ATTR_2_RO(temp4_max_alarm, bit, 0x35, 0x08); +static SENSOR_DEVICE_ATTR_2_RO(temp4_crit_alarm, bit, 0x37, 0x08); +static SENSOR_DEVICE_ATTR_RO(temp4_min_hyst, min_hyst, 0x2D); +static SENSOR_DEVICE_ATTR_RO(temp4_max_hyst, hyst, 0x2C); +static SENSOR_DEVICE_ATTR_RO(temp4_crit_hyst, hyst, 0x30); + +static SENSOR_DEVICE_ATTR_2_RW(power_state, bit, 0x03, 0x40); static struct attribute *emc1402_attrs[] = { &sensor_dev_attr_temp1_min.dev_attr.attr, @@ -328,14 +302,14 @@ static const struct attribute_group emc1404_group = { * array. */ static struct sensor_device_attribute_2 emc1402_alarms[] = { - SENSOR_ATTR_2(temp1_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x20), - SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x40), - SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x01), - - SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x02, 0x04), - SENSOR_ATTR_2(temp2_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x08), - SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x10), - SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x02), + SENSOR_ATTR_2_RO(temp1_min_alarm, bit, 0x02, 0x20), + SENSOR_ATTR_2_RO(temp1_max_alarm, bit, 0x02, 0x40), + SENSOR_ATTR_2_RO(temp1_crit_alarm, bit, 0x02, 0x01), + + SENSOR_ATTR_2_RO(temp2_fault, bit, 0x02, 0x04), + SENSOR_ATTR_2_RO(temp2_min_alarm, bit, 0x02, 0x08), + SENSOR_ATTR_2_RO(temp2_max_alarm, bit, 0x02, 0x10), + SENSOR_ATTR_2_RO(temp2_crit_alarm, bit, 0x02, 0x02), }; static struct attribute *emc1402_alarm_attrs[] = {