Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] pcihp_skeleton.c cleanup

This patch cleans up pcihp_skelton.c as follows.

o Move slot name area into struct slot.
o Replace kmalloc with kzalloc and clean up the arg of sizeof()
o Fix the wrong use of get_*_status() functions.

Signed-off-by: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Kenji Kaneshige and committed by
Greg Kroah-Hartman
287588b3 ef3be547

+11 -22
+11 -22
drivers/pci/hotplug/pcihp_skeleton.c
··· 37 37 #include <linux/init.h> 38 38 #include "pci_hotplug.h" 39 39 40 + #define SLOT_NAME_SIZE 10 40 41 struct slot { 41 42 u8 number; 42 43 struct hotplug_slot *hotplug_slot; 43 44 struct list_head slot_list; 45 + char name[SLOT_NAME_SIZE]; 44 46 }; 45 47 46 48 static LIST_HEAD(slot_list); ··· 235 233 236 234 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 237 235 kfree(slot->hotplug_slot->info); 238 - kfree(slot->hotplug_slot->name); 239 236 kfree(slot->hotplug_slot); 240 237 kfree(slot); 241 238 } 242 239 243 - #define SLOT_NAME_SIZE 10 244 240 static void make_slot_name(struct slot *slot) 245 241 { 246 242 /* ··· 257 257 struct slot *slot; 258 258 struct hotplug_slot *hotplug_slot; 259 259 struct hotplug_slot_info *info; 260 - char *name; 261 260 int retval = -ENOMEM; 262 261 int i; 263 262 ··· 265 266 * with the pci_hotplug subsystem. 266 267 */ 267 268 for (i = 0; i < num_slots; ++i) { 268 - slot = kmalloc(sizeof(struct slot), GFP_KERNEL); 269 + slot = kzalloc(sizeof(*slot), GFP_KERNEL); 269 270 if (!slot) 270 271 goto error; 271 - memset(slot, 0, sizeof(struct slot)); 272 272 273 - hotplug_slot = kmalloc(sizeof(struct hotplug_slot), 274 - GFP_KERNEL); 273 + hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL); 275 274 if (!hotplug_slot) 276 275 goto error_slot; 277 - memset(hotplug_slot, 0, sizeof (struct hotplug_slot)); 278 276 slot->hotplug_slot = hotplug_slot; 279 277 280 - info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); 278 + info = kzalloc(sizeof(*info), GFP_KERNEL); 281 279 if (!info) 282 280 goto error_hpslot; 283 - memset(info, 0, sizeof (struct hotplug_slot_info)); 284 281 hotplug_slot->info = info; 285 - 286 - name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL); 287 - if (!name) 288 - goto error_info; 289 - hotplug_slot->name = name; 290 282 291 283 slot->number = i; 292 284 285 + hotplug_slot->name = slot->name; 293 286 hotplug_slot->private = slot; 294 287 hotplug_slot->release = &release_slot; 295 288 make_slot_name(slot); ··· 291 300 * Initialize the slot info structure with some known 292 301 * good values. 293 302 */ 294 - info->power_status = get_power_status(slot); 295 - info->attention_status = get_attention_status(slot); 296 - info->latch_status = get_latch_status(slot); 297 - info->adapter_status = get_adapter_status(slot); 303 + get_power_status(hotplug_slot, &info->power_status); 304 + get_attention_status(hotplug_slot, &info->attention_status); 305 + get_latch_status(hotplug_slot, &info->latch_status); 306 + get_adapter_status(hotplug_slot, &info->adapter_status); 298 307 299 308 dbg("registering slot %d\n", i); 300 309 retval = pci_hp_register(slot->hotplug_slot); 301 310 if (retval) { 302 311 err("pci_hp_register failed with error %d\n", retval); 303 - goto error_name; 312 + goto error_info; 304 313 } 305 314 306 315 /* add slot to our internal list */ ··· 308 317 } 309 318 310 319 return 0; 311 - error_name: 312 - kfree(name); 313 320 error_info: 314 321 kfree(info); 315 322 error_hpslot: