Created
January 17, 2015 00:18
-
-
Save vivien/72734ba0673ad0b79a6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 87d6bfd5fe53c64ab2f3bb860484d741dc9b5572 Mon Sep 17 00:00:00 2001 | |
From: Vivien Didelot <[email protected]> | |
Date: Wed, 14 Jan 2015 18:55:45 -0500 | |
Subject: [PATCH] net: dsa: review hwmon attributes visibility | |
Instead of setting a minimal mode for the temp_max sysfs attribute and | |
adding write permission in the is_visible function, use the | |
DEVICE_ATTR_RW macro to reduce boiler plate and remove write permission | |
if the set_temp_limit function is missing. | |
Also allow write-only access if the later is provided but not | |
get_temp_limit. | |
Finally, register the attributes if any of the corresponding function is | |
provided. | |
Signed-off-by: Vivien Didelot <[email protected]> | |
--- | |
net/dsa/dsa.c | 22 ++++++++++++++-------- | |
1 file changed, 14 insertions(+), 8 deletions(-) | |
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c | |
index 363102a..3d64400 100644 | |
--- a/net/dsa/dsa.c | |
+++ b/net/dsa/dsa.c | |
@@ -123,7 +123,7 @@ static ssize_t temp1_max_store(struct device *dev, | |
return count; | |
} | |
-static DEVICE_ATTR(temp1_max, S_IRUGO, temp1_max_show, temp1_max_store); | |
+static DEVICE_ATTR_RW(temp1_max); | |
static ssize_t temp1_max_alarm_show(struct device *dev, | |
struct device_attribute *attr, char *buf) | |
@@ -155,14 +155,19 @@ static umode_t dsa_hwmon_attrs_visible(struct kobject *kobj, | |
struct dsa_switch_driver *drv = ds->drv; | |
umode_t mode = attr->mode; | |
- if (index == 1) { | |
+ if (index == 0) { | |
+ if (!drv->get_temp) | |
+ mode &= ~S_IRUGO; | |
+ } else if (index == 1) { | |
if (!drv->get_temp_limit) | |
- mode = 0; | |
- else if (drv->set_temp_limit) | |
- mode |= S_IWUSR; | |
- } else if (index == 2 && !drv->get_temp_alarm) { | |
- mode = 0; | |
+ mode &= ~S_IRUGO; | |
+ if (!drv->set_temp_limit) | |
+ mode &= ~S_IWUSR; | |
+ } else if (index == 2) { | |
+ if (!drv->get_temp_alarm) | |
+ mode &= ~S_IRUGO; | |
} | |
+ | |
return mode; | |
} | |
@@ -334,7 +339,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, | |
* register with hardware monitoring subsystem. | |
* Treat registration error as non-fatal and ignore it. | |
*/ | |
- if (drv->get_temp) { | |
+ if (drv->get_temp || drv->get_temp_limit || drv->set_temp_limit || | |
+ drv->get_temp_alarm) { | |
const char *netname = netdev_name(dst->master_netdev); | |
char hname[IFNAMSIZ + 1]; | |
int i, j; | |
-- | |
2.2.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment