Skip to content

Commit 655ea93

Browse files
committed
Merge branch 'pci/hotplug'
- Drop shpchp module init/exit logging (Ilpo Järvinen) - Replace shpchp dbg() with ctrl_dbg() and remove unused dbg(), err(), info(), warn() wrappers (Ilpo Järvinen) - Drop 'shpchp_debug' module parameter in favor of standard dynamic debugging (Ilpo Järvinen) - Drop unused .get_power(), .set_power() function pointers (Guilherme Giacomo Simoes) - Drop superfluous pci_hotplug_slot_list (Lukas Wunner) - Drop superfluous try_module_get() calls (Lukas Wunner) - Drop superfluous NULL pointer checks (Lukas Wunner) - Pass struct hotplug_slot pointers directly to avoid backpointer dereferencing in has_*_file() (Lukas Wunner) - Inline pci_hp_{create,remove}_module_link() to reduce exported symbols (Lukas Wunner) - Disable hotplug interrupts in portdrv only when pciehp is not enabled to prevent issuing two hotplug commands too close together (Feng Tang) - Skip pciehp 'device replaced' check if the device has been removed to address a common deadlock when resuming after a device was removed during system sleep (Lukas Wunner) - Don't enable pciehp hotplug interupt when resuming in poll mode (Ilpo Järvinen) * pci/hotplug: PCI: pciehp: Don't enable HPIE when resuming in poll mode PCI: pciehp: Avoid unnecessary device replacement check PCI/portdrv: Only disable pciehp interrupts early when needed PCI: hotplug: Inline pci_hp_{create,remove}_module_link() PCI: hotplug: Avoid backpointer dereferencing in has_*_file() PCI: hotplug: Drop superfluous NULL pointer checks in has_*_file() PCI: hotplug: Drop superfluous try_module_get() calls PCI: hotplug: Drop superfluous pci_hotplug_slot_list PCI: cpcihp: Remove unused .get_power() and .set_power() PCI: shpchp: Remove 'shpchp_debug' module parameter PCI: shpchp: Remove unused logging wrappers PCI: shpchp: Change dbg() -> ctrl_dbg() PCI: shpchp: Remove logging from module init/exit functions
2 parents e9e224d + 527664f commit 655ea93

File tree

12 files changed

+58
-204
lines changed

12 files changed

+58
-204
lines changed

drivers/pci/hotplug/cpci_hotplug.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ struct cpci_hp_controller_ops {
4444
int (*enable_irq)(void);
4545
int (*disable_irq)(void);
4646
int (*check_irq)(void *dev_id);
47-
u8 (*get_power)(struct slot *slot);
48-
int (*set_power)(struct slot *slot, int value);
4947
};
5048

5149
struct cpci_hp_controller {

drivers/pci/hotplug/cpci_hotplug_core.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,10 @@ static int
7171
enable_slot(struct hotplug_slot *hotplug_slot)
7272
{
7373
struct slot *slot = to_slot(hotplug_slot);
74-
int retval = 0;
7574

7675
dbg("%s - physical_slot = %s", __func__, slot_name(slot));
7776

78-
if (controller->ops->set_power)
79-
retval = controller->ops->set_power(slot, 1);
80-
return retval;
77+
return 0;
8178
}
8279

8380
static int
@@ -109,12 +106,6 @@ disable_slot(struct hotplug_slot *hotplug_slot)
109106
}
110107
cpci_led_on(slot);
111108

112-
if (controller->ops->set_power) {
113-
retval = controller->ops->set_power(slot, 0);
114-
if (retval)
115-
goto disable_error;
116-
}
117-
118109
slot->adapter_status = 0;
119110

120111
if (slot->extracting) {
@@ -129,11 +120,7 @@ disable_slot(struct hotplug_slot *hotplug_slot)
129120
static u8
130121
cpci_get_power_status(struct slot *slot)
131122
{
132-
u8 power = 1;
133-
134-
if (controller->ops->get_power)
135-
power = controller->ops->get_power(slot);
136-
return power;
123+
return 1;
137124
}
138125

139126
static int

drivers/pci/hotplug/pci_hotplug_core.c

Lines changed: 41 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
* Scott Murray <[email protected]>
1515
*/
1616

17-
#include <linux/module.h> /* try_module_get & module_put */
17+
#include <linux/module.h>
1818
#include <linux/moduleparam.h>
1919
#include <linux/kernel.h>
2020
#include <linux/types.h>
21-
#include <linux/list.h>
2221
#include <linux/kobject.h>
2322
#include <linux/sysfs.h>
2423
#include <linux/pagemap.h>
2524
#include <linux/init.h>
2625
#include <linux/mount.h>
2726
#include <linux/namei.h>
28-
#include <linux/mutex.h>
2927
#include <linux/pci.h>
3028
#include <linux/pci_hotplug.h>
3129
#include <linux/uaccess.h>
@@ -42,20 +40,14 @@
4240
/* local variables */
4341
static bool debug;
4442

45-
static LIST_HEAD(pci_hotplug_slot_list);
46-
static DEFINE_MUTEX(pci_hp_mutex);
47-
4843
/* Weee, fun with macros... */
4944
#define GET_STATUS(name, type) \
5045
static int get_##name(struct hotplug_slot *slot, type *value) \
5146
{ \
5247
const struct hotplug_slot_ops *ops = slot->ops; \
5348
int retval = 0; \
54-
if (!try_module_get(slot->owner)) \
55-
return -ENODEV; \
5649
if (ops->get_##name) \
5750
retval = ops->get_##name(slot, value); \
58-
module_put(slot->owner); \
5951
return retval; \
6052
}
6153

@@ -88,10 +80,6 @@ static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
8880
power = (u8)(lpower & 0xff);
8981
dbg("power = %d\n", power);
9082

91-
if (!try_module_get(slot->owner)) {
92-
retval = -ENODEV;
93-
goto exit;
94-
}
9583
switch (power) {
9684
case 0:
9785
if (slot->ops->disable_slot)
@@ -107,9 +95,7 @@ static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
10795
err("Illegal value specified for power\n");
10896
retval = -EINVAL;
10997
}
110-
module_put(slot->owner);
11198

112-
exit:
11399
if (retval)
114100
return retval;
115101
return count;
@@ -146,15 +132,9 @@ static ssize_t attention_write_file(struct pci_slot *pci_slot, const char *buf,
146132
attention = (u8)(lattention & 0xff);
147133
dbg(" - attention = %d\n", attention);
148134

149-
if (!try_module_get(slot->owner)) {
150-
retval = -ENODEV;
151-
goto exit;
152-
}
153135
if (ops->set_attention_status)
154136
retval = ops->set_attention_status(slot, attention);
155-
module_put(slot->owner);
156137

157-
exit:
158138
if (retval)
159139
return retval;
160140
return count;
@@ -212,15 +192,9 @@ static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf,
212192
test = (u32)(ltest & 0xffffffff);
213193
dbg("test = %d\n", test);
214194

215-
if (!try_module_get(slot->owner)) {
216-
retval = -ENODEV;
217-
goto exit;
218-
}
219195
if (slot->ops->hardware_test)
220196
retval = slot->ops->hardware_test(slot, test);
221-
module_put(slot->owner);
222197

223-
exit:
224198
if (retval)
225199
return retval;
226200
return count;
@@ -231,100 +205,88 @@ static struct pci_slot_attribute hotplug_slot_attr_test = {
231205
.store = test_write_file
232206
};
233207

234-
static bool has_power_file(struct pci_slot *pci_slot)
208+
static bool has_power_file(struct hotplug_slot *slot)
235209
{
236-
struct hotplug_slot *slot = pci_slot->hotplug;
237-
238-
if ((!slot) || (!slot->ops))
239-
return false;
240210
if ((slot->ops->enable_slot) ||
241211
(slot->ops->disable_slot) ||
242212
(slot->ops->get_power_status))
243213
return true;
244214
return false;
245215
}
246216

247-
static bool has_attention_file(struct pci_slot *pci_slot)
217+
static bool has_attention_file(struct hotplug_slot *slot)
248218
{
249-
struct hotplug_slot *slot = pci_slot->hotplug;
250-
251-
if ((!slot) || (!slot->ops))
252-
return false;
253219
if ((slot->ops->set_attention_status) ||
254220
(slot->ops->get_attention_status))
255221
return true;
256222
return false;
257223
}
258224

259-
static bool has_latch_file(struct pci_slot *pci_slot)
225+
static bool has_latch_file(struct hotplug_slot *slot)
260226
{
261-
struct hotplug_slot *slot = pci_slot->hotplug;
262-
263-
if ((!slot) || (!slot->ops))
264-
return false;
265227
if (slot->ops->get_latch_status)
266228
return true;
267229
return false;
268230
}
269231

270-
static bool has_adapter_file(struct pci_slot *pci_slot)
232+
static bool has_adapter_file(struct hotplug_slot *slot)
271233
{
272-
struct hotplug_slot *slot = pci_slot->hotplug;
273-
274-
if ((!slot) || (!slot->ops))
275-
return false;
276234
if (slot->ops->get_adapter_status)
277235
return true;
278236
return false;
279237
}
280238

281-
static bool has_test_file(struct pci_slot *pci_slot)
239+
static bool has_test_file(struct hotplug_slot *slot)
282240
{
283-
struct hotplug_slot *slot = pci_slot->hotplug;
284-
285-
if ((!slot) || (!slot->ops))
286-
return false;
287241
if (slot->ops->hardware_test)
288242
return true;
289243
return false;
290244
}
291245

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)
293247
{
248+
struct kobject *kobj;
294249
int retval = 0;
295250

296251
/* 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+
}
298260

299-
if (has_power_file(pci_slot)) {
261+
if (has_power_file(slot)) {
300262
retval = sysfs_create_file(&pci_slot->kobj,
301263
&hotplug_slot_attr_power.attr);
302264
if (retval)
303265
goto exit_power;
304266
}
305267

306-
if (has_attention_file(pci_slot)) {
268+
if (has_attention_file(slot)) {
307269
retval = sysfs_create_file(&pci_slot->kobj,
308270
&hotplug_slot_attr_attention.attr);
309271
if (retval)
310272
goto exit_attention;
311273
}
312274

313-
if (has_latch_file(pci_slot)) {
275+
if (has_latch_file(slot)) {
314276
retval = sysfs_create_file(&pci_slot->kobj,
315277
&hotplug_slot_attr_latch.attr);
316278
if (retval)
317279
goto exit_latch;
318280
}
319281

320-
if (has_adapter_file(pci_slot)) {
282+
if (has_adapter_file(slot)) {
321283
retval = sysfs_create_file(&pci_slot->kobj,
322284
&hotplug_slot_attr_presence.attr);
323285
if (retval)
324286
goto exit_adapter;
325287
}
326288

327-
if (has_test_file(pci_slot)) {
289+
if (has_test_file(slot)) {
328290
retval = sysfs_create_file(&pci_slot->kobj,
329291
&hotplug_slot_attr_test.attr);
330292
if (retval)
@@ -334,56 +296,45 @@ static int fs_add_slot(struct pci_slot *pci_slot)
334296
goto exit;
335297

336298
exit_test:
337-
if (has_adapter_file(pci_slot))
299+
if (has_adapter_file(slot))
338300
sysfs_remove_file(&pci_slot->kobj,
339301
&hotplug_slot_attr_presence.attr);
340302
exit_adapter:
341-
if (has_latch_file(pci_slot))
303+
if (has_latch_file(slot))
342304
sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_latch.attr);
343305
exit_latch:
344-
if (has_attention_file(pci_slot))
306+
if (has_attention_file(slot))
345307
sysfs_remove_file(&pci_slot->kobj,
346308
&hotplug_slot_attr_attention.attr);
347309
exit_attention:
348-
if (has_power_file(pci_slot))
310+
if (has_power_file(slot))
349311
sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_power.attr);
350312
exit_power:
351-
pci_hp_remove_module_link(pci_slot);
313+
sysfs_remove_link(&pci_slot->kobj, "module");
352314
exit:
353315
return retval;
354316
}
355317

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)
357319
{
358-
if (has_power_file(pci_slot))
320+
if (has_power_file(slot))
359321
sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_power.attr);
360322

361-
if (has_attention_file(pci_slot))
323+
if (has_attention_file(slot))
362324
sysfs_remove_file(&pci_slot->kobj,
363325
&hotplug_slot_attr_attention.attr);
364326

365-
if (has_latch_file(pci_slot))
327+
if (has_latch_file(slot))
366328
sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_latch.attr);
367329

368-
if (has_adapter_file(pci_slot))
330+
if (has_adapter_file(slot))
369331
sysfs_remove_file(&pci_slot->kobj,
370332
&hotplug_slot_attr_presence.attr);
371333

372-
if (has_test_file(pci_slot))
334+
if (has_test_file(slot))
373335
sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_test.attr);
374336

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");
387338
}
388339

389340
/**
@@ -476,18 +427,19 @@ EXPORT_SYMBOL_GPL(__pci_hp_initialize);
476427
*/
477428
int pci_hp_add(struct hotplug_slot *slot)
478429
{
479-
struct pci_slot *pci_slot = slot->pci_slot;
430+
struct pci_slot *pci_slot;
480431
int result;
481432

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);
483439
if (result)
484440
return result;
485441

486442
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));
491443
return 0;
492444
}
493445
EXPORT_SYMBOL_GPL(pci_hp_add);
@@ -514,22 +466,10 @@ EXPORT_SYMBOL_GPL(pci_hp_deregister);
514466
*/
515467
void pci_hp_del(struct hotplug_slot *slot)
516468
{
517-
struct hotplug_slot *temp;
518-
519469
if (WARN_ON(!slot))
520470
return;
521471

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);
533473
}
534474
EXPORT_SYMBOL_GPL(pci_hp_del);
535475

drivers/pci/hotplug/pciehp_core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,12 @@ static int pciehp_suspend(struct pcie_device *dev)
286286

287287
static bool pciehp_device_replaced(struct controller *ctrl)
288288
{
289-
struct pci_dev *pdev __free(pci_dev_put);
289+
struct pci_dev *pdev __free(pci_dev_put) = NULL;
290290
u32 reg;
291291

292+
if (pci_dev_is_disconnected(ctrl->pcie->port))
293+
return false;
294+
292295
pdev = pci_get_slot(ctrl->pcie->port->subordinate, PCI_DEVFN(0, 0));
293296
if (!pdev)
294297
return true;

0 commit comments

Comments
 (0)