aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-11-26 02:15:28 -0500
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2013-12-18 01:43:05 -0500
commit03b77d8180378632e76f1157d9a685ca4c79d0cf (patch)
treefe28c2b16a8c61531a5f3c5b6a25024868c17263 /drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c
parent220fe050dac5711453d5ba3605dec2f2eb55f234 (diff)
ixgbe: Convert to use devm_hwmon_device_register_with_groups
Simplify the code. Attach hwmon sysfs attributes to hwmon device instead of pci device. Avoid race conditions caused by attributes being created after hwmon device registration. Implicitly (through hwmon API) add mandatory 'name' sysfs attribute. Other cleanup: Instead of allocating memory for hwmon attributes, move attributes and all other hwmon related data into struct hwmon_buff and allocate the entire structure using devm_kzalloc. Check return value from calls to igb_add_hwmon_attr() one by one instead of logically combining them all together. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Phil Schmitt <phillip.j.schmitt@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c')
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c76
1 files changed, 31 insertions, 45 deletions
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c
index d118def16f35..3081974030cb 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sysfs.c
@@ -111,8 +111,8 @@ static int ixgbe_add_hwmon_attr(struct ixgbe_adapter *adapter,
111 unsigned int n_attr; 111 unsigned int n_attr;
112 struct hwmon_attr *ixgbe_attr; 112 struct hwmon_attr *ixgbe_attr;
113 113
114 n_attr = adapter->ixgbe_hwmon_buff.n_hwmon; 114 n_attr = adapter->ixgbe_hwmon_buff->n_hwmon;
115 ixgbe_attr = &adapter->ixgbe_hwmon_buff.hwmon_list[n_attr]; 115 ixgbe_attr = &adapter->ixgbe_hwmon_buff->hwmon_list[n_attr];
116 116
117 switch (type) { 117 switch (type) {
118 case IXGBE_HWMON_TYPE_LOC: 118 case IXGBE_HWMON_TYPE_LOC:
@@ -147,32 +147,17 @@ static int ixgbe_add_hwmon_attr(struct ixgbe_adapter *adapter,
147 ixgbe_attr->dev_attr.store = NULL; 147 ixgbe_attr->dev_attr.store = NULL;
148 ixgbe_attr->dev_attr.attr.mode = S_IRUGO; 148 ixgbe_attr->dev_attr.attr.mode = S_IRUGO;
149 ixgbe_attr->dev_attr.attr.name = ixgbe_attr->name; 149 ixgbe_attr->dev_attr.attr.name = ixgbe_attr->name;
150 sysfs_attr_init(&ixgbe_attr->dev_attr.attr);
150 151
151 rc = device_create_file(&adapter->pdev->dev, 152 adapter->ixgbe_hwmon_buff->attrs[n_attr] = &ixgbe_attr->dev_attr.attr;
152 &ixgbe_attr->dev_attr);
153 153
154 if (rc == 0) 154 ++adapter->ixgbe_hwmon_buff->n_hwmon;
155 ++adapter->ixgbe_hwmon_buff.n_hwmon;
156 155
157 return rc; 156 return 0;
158} 157}
159 158
160static void ixgbe_sysfs_del_adapter(struct ixgbe_adapter *adapter) 159static void ixgbe_sysfs_del_adapter(struct ixgbe_adapter *adapter)
161{ 160{
162 int i;
163
164 if (adapter == NULL)
165 return;
166
167 for (i = 0; i < adapter->ixgbe_hwmon_buff.n_hwmon; i++) {
168 device_remove_file(&adapter->pdev->dev,
169 &adapter->ixgbe_hwmon_buff.hwmon_list[i].dev_attr);
170 }
171
172 kfree(adapter->ixgbe_hwmon_buff.hwmon_list);
173
174 if (adapter->ixgbe_hwmon_buff.device)
175 hwmon_device_unregister(adapter->ixgbe_hwmon_buff.device);
176} 161}
177 162
178/* called from ixgbe_main.c */ 163/* called from ixgbe_main.c */
@@ -184,9 +169,9 @@ void ixgbe_sysfs_exit(struct ixgbe_adapter *adapter)
184/* called from ixgbe_main.c */ 169/* called from ixgbe_main.c */
185int ixgbe_sysfs_init(struct ixgbe_adapter *adapter) 170int ixgbe_sysfs_init(struct ixgbe_adapter *adapter)
186{ 171{
187 struct hwmon_buff *ixgbe_hwmon = &adapter->ixgbe_hwmon_buff; 172 struct hwmon_buff *ixgbe_hwmon;
173 struct device *hwmon_dev;
188 unsigned int i; 174 unsigned int i;
189 int n_attrs;
190 int rc = 0; 175 int rc = 0;
191 176
192 /* If this method isn't defined we don't support thermals */ 177 /* If this method isn't defined we don't support thermals */
@@ -198,23 +183,13 @@ int ixgbe_sysfs_init(struct ixgbe_adapter *adapter)
198 if (adapter->hw.mac.ops.init_thermal_sensor_thresh(&adapter->hw)) 183 if (adapter->hw.mac.ops.init_thermal_sensor_thresh(&adapter->hw))
199 goto exit; 184 goto exit;
200 185
201 /* 186 ixgbe_hwmon = devm_kzalloc(&adapter->pdev->dev, sizeof(*ixgbe_hwmon),
202 * Allocation space for max attributs 187 GFP_KERNEL);
203 * max num sensors * values (loc, temp, max, caution) 188 if (ixgbe_hwmon == NULL) {
204 */
205 n_attrs = IXGBE_MAX_SENSORS * 4;
206 ixgbe_hwmon->hwmon_list = kcalloc(n_attrs, sizeof(struct hwmon_attr),
207 GFP_KERNEL);
208 if (!ixgbe_hwmon->hwmon_list) {
209 rc = -ENOMEM; 189 rc = -ENOMEM;
210 goto err; 190 goto exit;
211 }
212
213 ixgbe_hwmon->device = hwmon_device_register(&adapter->pdev->dev);
214 if (IS_ERR(ixgbe_hwmon->device)) {
215 rc = PTR_ERR(ixgbe_hwmon->device);
216 goto err;
217 } 191 }
192 adapter->ixgbe_hwmon_buff = ixgbe_hwmon;
218 193
219 for (i = 0; i < IXGBE_MAX_SENSORS; i++) { 194 for (i = 0; i < IXGBE_MAX_SENSORS; i++) {
220 /* 195 /*
@@ -226,17 +201,28 @@ int ixgbe_sysfs_init(struct ixgbe_adapter *adapter)
226 201
227 /* Bail if any hwmon attr struct fails to initialize */ 202 /* Bail if any hwmon attr struct fails to initialize */
228 rc = ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_CAUTION); 203 rc = ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_CAUTION);
229 rc |= ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_LOC);
230 rc |= ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_TEMP);
231 rc |= ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_MAX);
232 if (rc) 204 if (rc)
233 goto err; 205 goto exit;
206 rc = ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_LOC);
207 if (rc)
208 goto exit;
209 rc = ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_TEMP);
210 if (rc)
211 goto exit;
212 rc = ixgbe_add_hwmon_attr(adapter, i, IXGBE_HWMON_TYPE_MAX);
213 if (rc)
214 goto exit;
234 } 215 }
235 216
236 goto exit; 217 ixgbe_hwmon->groups[0] = &ixgbe_hwmon->group;
218 ixgbe_hwmon->group.attrs = ixgbe_hwmon->attrs;
237 219
238err: 220 hwmon_dev = devm_hwmon_device_register_with_groups(&adapter->pdev->dev,
239 ixgbe_sysfs_del_adapter(adapter); 221 "ixgbe",
222 ixgbe_hwmon,
223 ixgbe_hwmon->groups);
224 if (IS_ERR(hwmon_dev))
225 rc = PTR_ERR(hwmon_dev);
240exit: 226exit:
241 return rc; 227 return rc;
242} 228}