14
14
* Scott Murray <[email protected] >
15
15
*/
16
16
17
- #include <linux/module.h> /* try_module_get & module_put */
17
+ #include <linux/module.h>
18
18
#include <linux/moduleparam.h>
19
19
#include <linux/kernel.h>
20
20
#include <linux/types.h>
21
- #include <linux/list.h>
22
21
#include <linux/kobject.h>
23
22
#include <linux/sysfs.h>
24
23
#include <linux/pagemap.h>
25
24
#include <linux/init.h>
26
25
#include <linux/mount.h>
27
26
#include <linux/namei.h>
28
- #include <linux/mutex.h>
29
27
#include <linux/pci.h>
30
28
#include <linux/pci_hotplug.h>
31
29
#include <linux/uaccess.h>
42
40
/* local variables */
43
41
static bool debug ;
44
42
45
- static LIST_HEAD (pci_hotplug_slot_list );
46
- static DEFINE_MUTEX (pci_hp_mutex );
47
-
48
43
/* Weee, fun with macros... */
49
44
#define GET_STATUS (name , type ) \
50
45
static int get_##name(struct hotplug_slot *slot, type *value) \
51
46
{ \
52
47
const struct hotplug_slot_ops *ops = slot->ops; \
53
48
int retval = 0; \
54
- if (!try_module_get(slot->owner)) \
55
- return -ENODEV; \
56
49
if (ops->get_##name) \
57
50
retval = ops->get_##name(slot, value); \
58
- module_put(slot->owner); \
59
51
return retval; \
60
52
}
61
53
@@ -88,10 +80,6 @@ static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
88
80
power = (u8 )(lpower & 0xff );
89
81
dbg ("power = %d\n" , power );
90
82
91
- if (!try_module_get (slot -> owner )) {
92
- retval = - ENODEV ;
93
- goto exit ;
94
- }
95
83
switch (power ) {
96
84
case 0 :
97
85
if (slot -> ops -> disable_slot )
@@ -107,9 +95,7 @@ static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
107
95
err ("Illegal value specified for power\n" );
108
96
retval = - EINVAL ;
109
97
}
110
- module_put (slot -> owner );
111
98
112
- exit :
113
99
if (retval )
114
100
return retval ;
115
101
return count ;
@@ -146,15 +132,9 @@ static ssize_t attention_write_file(struct pci_slot *pci_slot, const char *buf,
146
132
attention = (u8 )(lattention & 0xff );
147
133
dbg (" - attention = %d\n" , attention );
148
134
149
- if (!try_module_get (slot -> owner )) {
150
- retval = - ENODEV ;
151
- goto exit ;
152
- }
153
135
if (ops -> set_attention_status )
154
136
retval = ops -> set_attention_status (slot , attention );
155
- module_put (slot -> owner );
156
137
157
- exit :
158
138
if (retval )
159
139
return retval ;
160
140
return count ;
@@ -212,15 +192,9 @@ static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf,
212
192
test = (u32 )(ltest & 0xffffffff );
213
193
dbg ("test = %d\n" , test );
214
194
215
- if (!try_module_get (slot -> owner )) {
216
- retval = - ENODEV ;
217
- goto exit ;
218
- }
219
195
if (slot -> ops -> hardware_test )
220
196
retval = slot -> ops -> hardware_test (slot , test );
221
- module_put (slot -> owner );
222
197
223
- exit :
224
198
if (retval )
225
199
return retval ;
226
200
return count ;
@@ -231,100 +205,88 @@ static struct pci_slot_attribute hotplug_slot_attr_test = {
231
205
.store = test_write_file
232
206
};
233
207
234
- static bool has_power_file (struct pci_slot * pci_slot )
208
+ static bool has_power_file (struct hotplug_slot * slot )
235
209
{
236
- struct hotplug_slot * slot = pci_slot -> hotplug ;
237
-
238
- if ((!slot ) || (!slot -> ops ))
239
- return false;
240
210
if ((slot -> ops -> enable_slot ) ||
241
211
(slot -> ops -> disable_slot ) ||
242
212
(slot -> ops -> get_power_status ))
243
213
return true;
244
214
return false;
245
215
}
246
216
247
- static bool has_attention_file (struct pci_slot * pci_slot )
217
+ static bool has_attention_file (struct hotplug_slot * slot )
248
218
{
249
- struct hotplug_slot * slot = pci_slot -> hotplug ;
250
-
251
- if ((!slot ) || (!slot -> ops ))
252
- return false;
253
219
if ((slot -> ops -> set_attention_status ) ||
254
220
(slot -> ops -> get_attention_status ))
255
221
return true;
256
222
return false;
257
223
}
258
224
259
- static bool has_latch_file (struct pci_slot * pci_slot )
225
+ static bool has_latch_file (struct hotplug_slot * slot )
260
226
{
261
- struct hotplug_slot * slot = pci_slot -> hotplug ;
262
-
263
- if ((!slot ) || (!slot -> ops ))
264
- return false;
265
227
if (slot -> ops -> get_latch_status )
266
228
return true;
267
229
return false;
268
230
}
269
231
270
- static bool has_adapter_file (struct pci_slot * pci_slot )
232
+ static bool has_adapter_file (struct hotplug_slot * slot )
271
233
{
272
- struct hotplug_slot * slot = pci_slot -> hotplug ;
273
-
274
- if ((!slot ) || (!slot -> ops ))
275
- return false;
276
234
if (slot -> ops -> get_adapter_status )
277
235
return true;
278
236
return false;
279
237
}
280
238
281
- static bool has_test_file (struct pci_slot * pci_slot )
239
+ static bool has_test_file (struct hotplug_slot * slot )
282
240
{
283
- struct hotplug_slot * slot = pci_slot -> hotplug ;
284
-
285
- if ((!slot ) || (!slot -> ops ))
286
- return false;
287
241
if (slot -> ops -> hardware_test )
288
242
return true;
289
243
return false;
290
244
}
291
245
292
- static int fs_add_slot (struct pci_slot * pci_slot )
246
+ static int fs_add_slot (struct hotplug_slot * slot , struct pci_slot * pci_slot )
293
247
{
248
+ struct kobject * kobj ;
294
249
int retval = 0 ;
295
250
296
251
/* Create symbolic link to the hotplug driver module */
297
- pci_hp_create_module_link (pci_slot );
252
+ kobj = kset_find_obj (module_kset , slot -> mod_name );
253
+ if (kobj ) {
254
+ retval = sysfs_create_link (& pci_slot -> kobj , kobj , "module" );
255
+ if (retval )
256
+ dev_err (& pci_slot -> bus -> dev ,
257
+ "Error creating sysfs link (%d)\n" , retval );
258
+ kobject_put (kobj );
259
+ }
298
260
299
- if (has_power_file (pci_slot )) {
261
+ if (has_power_file (slot )) {
300
262
retval = sysfs_create_file (& pci_slot -> kobj ,
301
263
& hotplug_slot_attr_power .attr );
302
264
if (retval )
303
265
goto exit_power ;
304
266
}
305
267
306
- if (has_attention_file (pci_slot )) {
268
+ if (has_attention_file (slot )) {
307
269
retval = sysfs_create_file (& pci_slot -> kobj ,
308
270
& hotplug_slot_attr_attention .attr );
309
271
if (retval )
310
272
goto exit_attention ;
311
273
}
312
274
313
- if (has_latch_file (pci_slot )) {
275
+ if (has_latch_file (slot )) {
314
276
retval = sysfs_create_file (& pci_slot -> kobj ,
315
277
& hotplug_slot_attr_latch .attr );
316
278
if (retval )
317
279
goto exit_latch ;
318
280
}
319
281
320
- if (has_adapter_file (pci_slot )) {
282
+ if (has_adapter_file (slot )) {
321
283
retval = sysfs_create_file (& pci_slot -> kobj ,
322
284
& hotplug_slot_attr_presence .attr );
323
285
if (retval )
324
286
goto exit_adapter ;
325
287
}
326
288
327
- if (has_test_file (pci_slot )) {
289
+ if (has_test_file (slot )) {
328
290
retval = sysfs_create_file (& pci_slot -> kobj ,
329
291
& hotplug_slot_attr_test .attr );
330
292
if (retval )
@@ -334,56 +296,45 @@ static int fs_add_slot(struct pci_slot *pci_slot)
334
296
goto exit ;
335
297
336
298
exit_test :
337
- if (has_adapter_file (pci_slot ))
299
+ if (has_adapter_file (slot ))
338
300
sysfs_remove_file (& pci_slot -> kobj ,
339
301
& hotplug_slot_attr_presence .attr );
340
302
exit_adapter :
341
- if (has_latch_file (pci_slot ))
303
+ if (has_latch_file (slot ))
342
304
sysfs_remove_file (& pci_slot -> kobj , & hotplug_slot_attr_latch .attr );
343
305
exit_latch :
344
- if (has_attention_file (pci_slot ))
306
+ if (has_attention_file (slot ))
345
307
sysfs_remove_file (& pci_slot -> kobj ,
346
308
& hotplug_slot_attr_attention .attr );
347
309
exit_attention :
348
- if (has_power_file (pci_slot ))
310
+ if (has_power_file (slot ))
349
311
sysfs_remove_file (& pci_slot -> kobj , & hotplug_slot_attr_power .attr );
350
312
exit_power :
351
- pci_hp_remove_module_link ( pci_slot );
313
+ sysfs_remove_link ( & pci_slot -> kobj , "module" );
352
314
exit :
353
315
return retval ;
354
316
}
355
317
356
- static void fs_remove_slot (struct pci_slot * pci_slot )
318
+ static void fs_remove_slot (struct hotplug_slot * slot , struct pci_slot * pci_slot )
357
319
{
358
- if (has_power_file (pci_slot ))
320
+ if (has_power_file (slot ))
359
321
sysfs_remove_file (& pci_slot -> kobj , & hotplug_slot_attr_power .attr );
360
322
361
- if (has_attention_file (pci_slot ))
323
+ if (has_attention_file (slot ))
362
324
sysfs_remove_file (& pci_slot -> kobj ,
363
325
& hotplug_slot_attr_attention .attr );
364
326
365
- if (has_latch_file (pci_slot ))
327
+ if (has_latch_file (slot ))
366
328
sysfs_remove_file (& pci_slot -> kobj , & hotplug_slot_attr_latch .attr );
367
329
368
- if (has_adapter_file (pci_slot ))
330
+ if (has_adapter_file (slot ))
369
331
sysfs_remove_file (& pci_slot -> kobj ,
370
332
& hotplug_slot_attr_presence .attr );
371
333
372
- if (has_test_file (pci_slot ))
334
+ if (has_test_file (slot ))
373
335
sysfs_remove_file (& pci_slot -> kobj , & hotplug_slot_attr_test .attr );
374
336
375
- pci_hp_remove_module_link (pci_slot );
376
- }
377
-
378
- static struct hotplug_slot * get_slot_from_name (const char * name )
379
- {
380
- struct hotplug_slot * slot ;
381
-
382
- list_for_each_entry (slot , & pci_hotplug_slot_list , slot_list ) {
383
- if (strcmp (hotplug_slot_name (slot ), name ) == 0 )
384
- return slot ;
385
- }
386
- return NULL ;
337
+ sysfs_remove_link (& pci_slot -> kobj , "module" );
387
338
}
388
339
389
340
/**
@@ -476,18 +427,19 @@ EXPORT_SYMBOL_GPL(__pci_hp_initialize);
476
427
*/
477
428
int pci_hp_add (struct hotplug_slot * slot )
478
429
{
479
- struct pci_slot * pci_slot = slot -> pci_slot ;
430
+ struct pci_slot * pci_slot ;
480
431
int result ;
481
432
482
- result = fs_add_slot (pci_slot );
433
+ if (WARN_ON (!slot ))
434
+ return - EINVAL ;
435
+
436
+ pci_slot = slot -> pci_slot ;
437
+
438
+ result = fs_add_slot (slot , pci_slot );
483
439
if (result )
484
440
return result ;
485
441
486
442
kobject_uevent (& pci_slot -> kobj , KOBJ_ADD );
487
- mutex_lock (& pci_hp_mutex );
488
- list_add (& slot -> slot_list , & pci_hotplug_slot_list );
489
- mutex_unlock (& pci_hp_mutex );
490
- dbg ("Added slot %s to the list\n" , hotplug_slot_name (slot ));
491
443
return 0 ;
492
444
}
493
445
EXPORT_SYMBOL_GPL (pci_hp_add );
@@ -514,22 +466,10 @@ EXPORT_SYMBOL_GPL(pci_hp_deregister);
514
466
*/
515
467
void pci_hp_del (struct hotplug_slot * slot )
516
468
{
517
- struct hotplug_slot * temp ;
518
-
519
469
if (WARN_ON (!slot ))
520
470
return ;
521
471
522
- mutex_lock (& pci_hp_mutex );
523
- temp = get_slot_from_name (hotplug_slot_name (slot ));
524
- if (WARN_ON (temp != slot )) {
525
- mutex_unlock (& pci_hp_mutex );
526
- return ;
527
- }
528
-
529
- list_del (& slot -> slot_list );
530
- mutex_unlock (& pci_hp_mutex );
531
- dbg ("Removed slot %s from the list\n" , hotplug_slot_name (slot ));
532
- fs_remove_slot (slot -> pci_slot );
472
+ fs_remove_slot (slot , slot -> pci_slot );
533
473
}
534
474
EXPORT_SYMBOL_GPL (pci_hp_del );
535
475
0 commit comments