diff options
author | Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com> | 2006-01-25 19:55:35 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-03-23 17:35:10 -0500 |
commit | 926030f6af856d5681af7940239da2b0269cd755 (patch) | |
tree | 3394c11c599dbdb853a10b0b82a28d29e2bf9e7d /drivers/pci/hotplug/shpchp_core.c | |
parent | 6aa4cdd07139ba4d5b89139b0070d795cc4dea88 (diff) |
[PATCH] shpchp - cleanup init_slots()
This patch cleanups init_slots() function of SHPCHP driver based on
pcihp_skelton.c. This patch has no functional change.
Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/pci/hotplug/shpchp_core.c')
-rw-r--r-- | drivers/pci/hotplug/shpchp_core.c | 120 |
1 files changed, 63 insertions, 57 deletions
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c index a2b3f0010cec..29261b8824c8 100644 --- a/drivers/pci/hotplug/shpchp_core.c +++ b/drivers/pci/hotplug/shpchp_core.c | |||
@@ -99,89 +99,95 @@ static void release_slot(struct hotplug_slot *hotplug_slot) | |||
99 | kfree(slot); | 99 | kfree(slot); |
100 | } | 100 | } |
101 | 101 | ||
102 | #define SLOT_NAME_SIZE 10 | ||
103 | static void make_slot_name(struct slot *slot) | ||
104 | { | ||
105 | snprintf(slot->hotplug_slot->name, SLOT_NAME_SIZE, "%04d_%04d", | ||
106 | slot->bus, slot->number); | ||
107 | } | ||
108 | |||
102 | static int init_slots(struct controller *ctrl) | 109 | static int init_slots(struct controller *ctrl) |
103 | { | 110 | { |
104 | struct slot *new_slot; | 111 | struct slot *slot; |
105 | u8 number_of_slots; | 112 | struct hotplug_slot *hotplug_slot; |
106 | u8 slot_device; | 113 | struct hotplug_slot_info *info; |
107 | u32 slot_number, sun; | 114 | char *name; |
108 | int result = -ENOMEM; | 115 | int retval = -ENOMEM; |
109 | 116 | int i; | |
110 | number_of_slots = ctrl->num_slots; | 117 | u32 sun; |
111 | slot_device = ctrl->slot_device_offset; | 118 | |
112 | slot_number = ctrl->first_slot; | 119 | for (i = 0; i < ctrl->num_slots; i++) { |
113 | 120 | slot = kmalloc(sizeof(struct slot), GFP_KERNEL); | |
114 | while (number_of_slots) { | 121 | if (!slot) |
115 | new_slot = (struct slot *) kmalloc(sizeof(struct slot), GFP_KERNEL); | ||
116 | if (!new_slot) | ||
117 | goto error; | 122 | goto error; |
123 | memset(slot, 0, sizeof(struct slot)); | ||
118 | 124 | ||
119 | memset(new_slot, 0, sizeof(struct slot)); | 125 | hotplug_slot = kmalloc(sizeof(struct hotplug_slot), |
120 | new_slot->hotplug_slot = kmalloc (sizeof (struct hotplug_slot), GFP_KERNEL); | 126 | GFP_KERNEL); |
121 | if (!new_slot->hotplug_slot) | 127 | if (!hotplug_slot) |
122 | goto error_slot; | 128 | goto error_slot; |
123 | memset(new_slot->hotplug_slot, 0, sizeof (struct hotplug_slot)); | 129 | memset(hotplug_slot, 0, sizeof(struct hotplug_slot)); |
130 | slot->hotplug_slot = hotplug_slot; | ||
124 | 131 | ||
125 | new_slot->hotplug_slot->info = kmalloc (sizeof (struct hotplug_slot_info), GFP_KERNEL); | 132 | info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); |
126 | if (!new_slot->hotplug_slot->info) | 133 | if (!info) |
127 | goto error_hpslot; | 134 | goto error_hpslot; |
128 | memset(new_slot->hotplug_slot->info, 0, sizeof (struct hotplug_slot_info)); | 135 | memset(info, 0, sizeof (struct hotplug_slot_info)); |
129 | new_slot->hotplug_slot->name = kmalloc (SLOT_NAME_SIZE, GFP_KERNEL); | 136 | hotplug_slot->info = info; |
130 | if (!new_slot->hotplug_slot->name) | 137 | |
138 | name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); | ||
139 | if (!name) | ||
131 | goto error_info; | 140 | goto error_info; |
141 | hotplug_slot->name = name; | ||
132 | 142 | ||
133 | new_slot->magic = SLOT_MAGIC; | 143 | slot->hp_slot = i; |
134 | new_slot->ctrl = ctrl; | 144 | slot->magic = SLOT_MAGIC; |
135 | new_slot->bus = ctrl->slot_bus; | 145 | slot->ctrl = ctrl; |
136 | new_slot->device = slot_device; | 146 | slot->bus = ctrl->slot_bus; |
137 | new_slot->hpc_ops = ctrl->hpc_ops; | 147 | slot->device = ctrl->slot_device_offset + i; |
148 | slot->hpc_ops = ctrl->hpc_ops; | ||
138 | 149 | ||
139 | if (shpchprm_get_physical_slot_number(ctrl, &sun, | 150 | if (shpchprm_get_physical_slot_number(ctrl, &sun, |
140 | new_slot->bus, new_slot->device)) | 151 | slot->bus, slot->device)) |
141 | goto error_name; | 152 | goto error_name; |
142 | 153 | ||
143 | new_slot->number = sun; | 154 | slot->number = sun; |
144 | new_slot->hp_slot = slot_device - ctrl->slot_device_offset; | ||
145 | 155 | ||
146 | /* register this slot with the hotplug pci core */ | 156 | /* register this slot with the hotplug pci core */ |
147 | new_slot->hotplug_slot->private = new_slot; | 157 | hotplug_slot->private = slot; |
148 | new_slot->hotplug_slot->release = &release_slot; | 158 | hotplug_slot->release = &release_slot; |
149 | make_slot_name(new_slot->hotplug_slot->name, SLOT_NAME_SIZE, new_slot); | 159 | make_slot_name(slot); |
150 | new_slot->hotplug_slot->ops = &shpchp_hotplug_slot_ops; | 160 | hotplug_slot->ops = &shpchp_hotplug_slot_ops; |
151 | 161 | ||
152 | new_slot->hpc_ops->get_power_status(new_slot, &(new_slot->hotplug_slot->info->power_status)); | 162 | get_power_status(hotplug_slot, &info->power_status); |
153 | new_slot->hpc_ops->get_attention_status(new_slot, &(new_slot->hotplug_slot->info->attention_status)); | 163 | get_attention_status(hotplug_slot, &info->attention_status); |
154 | new_slot->hpc_ops->get_latch_status(new_slot, &(new_slot->hotplug_slot->info->latch_status)); | 164 | get_latch_status(hotplug_slot, &info->latch_status); |
155 | new_slot->hpc_ops->get_adapter_status(new_slot, &(new_slot->hotplug_slot->info->adapter_status)); | 165 | get_adapter_status(hotplug_slot, &info->adapter_status); |
156 | 166 | ||
157 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x slot_device_offset=%x\n", new_slot->bus, | 167 | dbg("Registering bus=%x dev=%x hp_slot=%x sun=%x " |
158 | new_slot->device, new_slot->hp_slot, new_slot->number, ctrl->slot_device_offset); | 168 | "slot_device_offset=%x\n", slot->bus, slot->device, |
159 | result = pci_hp_register (new_slot->hotplug_slot); | 169 | slot->hp_slot, slot->number, ctrl->slot_device_offset); |
160 | if (result) { | 170 | retval = pci_hp_register(slot->hotplug_slot); |
161 | err ("pci_hp_register failed with error %d\n", result); | 171 | if (retval) { |
172 | err("pci_hp_register failed with error %d\n", retval); | ||
162 | goto error_name; | 173 | goto error_name; |
163 | } | 174 | } |
164 | 175 | ||
165 | new_slot->next = ctrl->slot; | 176 | slot->next = ctrl->slot; |
166 | ctrl->slot = new_slot; | 177 | ctrl->slot = slot; |
167 | |||
168 | number_of_slots--; | ||
169 | slot_device++; | ||
170 | slot_number += ctrl->slot_num_inc; | ||
171 | } | 178 | } |
172 | 179 | ||
173 | return 0; | 180 | return 0; |
174 | |||
175 | error_name: | 181 | error_name: |
176 | kfree(new_slot->hotplug_slot->name); | 182 | kfree(name); |
177 | error_info: | 183 | error_info: |
178 | kfree(new_slot->hotplug_slot->info); | 184 | kfree(info); |
179 | error_hpslot: | 185 | error_hpslot: |
180 | kfree(new_slot->hotplug_slot); | 186 | kfree(hotplug_slot); |
181 | error_slot: | 187 | error_slot: |
182 | kfree(new_slot); | 188 | kfree(slot); |
183 | error: | 189 | error: |
184 | return result; | 190 | return retval; |
185 | } | 191 | } |
186 | 192 | ||
187 | static void cleanup_slots(struct controller *ctrl) | 193 | static void cleanup_slots(struct controller *ctrl) |