Skip to content

Commit 586f1d6

Browse files
kkaneshigejbarnes993
authored andcommitted
PCI: pciehp: create files only for existing capabilities
Current pciehp driver creates 'attention' and 'latch' files even if the controller doesn't support them. In this case, the contents of those files are meaningless and unpredictable. Those files should be created only if the controller has the corresponding capabilities. Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 3c3a1b1 commit 586f1d6

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

‎drivers/pci/hotplug/pciehp_core.c‎

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ static int get_adapter_status (struct hotplug_slot *slot, u8 *value);
7272
static int get_max_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
7373
static int get_cur_bus_speed (struct hotplug_slot *slot, enum pci_bus_speed *value);
7474

75-
static struct hotplug_slot_ops pciehp_hotplug_slot_ops = {
76-
.set_attention_status = set_attention_status,
77-
.enable_slot = enable_slot,
78-
.disable_slot = disable_slot,
79-
.get_power_status = get_power_status,
80-
.get_attention_status = get_attention_status,
81-
.get_latch_status = get_latch_status,
82-
.get_adapter_status = get_adapter_status,
83-
.get_max_bus_speed = get_max_bus_speed,
84-
.get_cur_bus_speed = get_cur_bus_speed,
85-
};
86-
8775
/**
8876
* release_slot - free up the memory used by a slot
8977
* @hotplug_slot: slot to free
@@ -95,6 +83,7 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
9583
ctrl_dbg(slot->ctrl, "%s: physical_slot = %s\n",
9684
__func__, hotplug_slot_name(hotplug_slot));
9785

86+
kfree(hotplug_slot->ops);
9887
kfree(hotplug_slot->info);
9988
kfree(hotplug_slot);
10089
}
@@ -104,6 +93,7 @@ static int init_slot(struct controller *ctrl)
10493
struct slot *slot = ctrl->slot;
10594
struct hotplug_slot *hotplug = NULL;
10695
struct hotplug_slot_info *info = NULL;
96+
struct hotplug_slot_ops *ops = NULL;
10797
char name[SLOT_NAME_SIZE];
10898
int retval = -ENOMEM;
10999

@@ -115,11 +105,28 @@ static int init_slot(struct controller *ctrl)
115105
if (!info)
116106
goto out;
117107

108+
/* Setup hotplug slot ops */
109+
ops = kzalloc(sizeof(*ops), GFP_KERNEL);
110+
if (!ops)
111+
goto out;
112+
ops->enable_slot = enable_slot;
113+
ops->disable_slot = disable_slot;
114+
ops->get_power_status = get_power_status;
115+
ops->get_adapter_status = get_adapter_status;
116+
ops->get_max_bus_speed = get_max_bus_speed;
117+
ops->get_cur_bus_speed = get_cur_bus_speed;
118+
if (MRL_SENS(ctrl))
119+
ops->get_latch_status = get_latch_status;
120+
if (ATTN_LED(ctrl)) {
121+
ops->get_attention_status = get_attention_status;
122+
ops->set_attention_status = set_attention_status;
123+
}
124+
118125
/* register this slot with the hotplug pci core */
119126
hotplug->info = info;
120127
hotplug->private = slot;
121128
hotplug->release = &release_slot;
122-
hotplug->ops = &pciehp_hotplug_slot_ops;
129+
hotplug->ops = ops;
123130
slot->hotplug_slot = hotplug;
124131
snprintf(name, SLOT_NAME_SIZE, "%u", PSN(ctrl));
125132

@@ -139,6 +146,7 @@ static int init_slot(struct controller *ctrl)
139146
get_adapter_status(hotplug, &info->adapter_status);
140147
out:
141148
if (retval) {
149+
kfree(ops);
142150
kfree(info);
143151
kfree(hotplug);
144152
}
@@ -161,9 +169,7 @@ static int set_attention_status(struct hotplug_slot *hotplug_slot, u8 status)
161169
__func__, slot_name(slot));
162170

163171
hotplug_slot->info->attention_status = status;
164-
165-
if (ATTN_LED(slot->ctrl))
166-
pciehp_set_attention_status(slot, status);
172+
pciehp_set_attention_status(slot, status);
167173

168174
return 0;
169175
}

0 commit comments

Comments
 (0)