Commit 287588b3 authored by Kenji Kaneshige's avatar Kenji Kaneshige Committed by Greg Kroah-Hartman

[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: default avatarKenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ef3be547
...@@ -37,10 +37,12 @@ ...@@ -37,10 +37,12 @@
#include <linux/init.h> #include <linux/init.h>
#include "pci_hotplug.h" #include "pci_hotplug.h"
#define SLOT_NAME_SIZE 10
struct slot { struct slot {
u8 number; u8 number;
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct list_head slot_list; struct list_head slot_list;
char name[SLOT_NAME_SIZE];
}; };
static LIST_HEAD(slot_list); static LIST_HEAD(slot_list);
...@@ -233,12 +235,10 @@ static void release_slot(struct hotplug_slot *hotplug_slot) ...@@ -233,12 +235,10 @@ static void release_slot(struct hotplug_slot *hotplug_slot)
dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
kfree(slot->hotplug_slot->info); kfree(slot->hotplug_slot->info);
kfree(slot->hotplug_slot->name);
kfree(slot->hotplug_slot); kfree(slot->hotplug_slot);
kfree(slot); kfree(slot);
} }
#define SLOT_NAME_SIZE 10
static void make_slot_name(struct slot *slot) static void make_slot_name(struct slot *slot)
{ {
/* /*
...@@ -257,7 +257,6 @@ static int __init init_slots(void) ...@@ -257,7 +257,6 @@ static int __init init_slots(void)
struct slot *slot; struct slot *slot;
struct hotplug_slot *hotplug_slot; struct hotplug_slot *hotplug_slot;
struct hotplug_slot_info *info; struct hotplug_slot_info *info;
char *name;
int retval = -ENOMEM; int retval = -ENOMEM;
int i; int i;
...@@ -266,31 +265,23 @@ static int __init init_slots(void) ...@@ -266,31 +265,23 @@ static int __init init_slots(void)
* with the pci_hotplug subsystem. * with the pci_hotplug subsystem.
*/ */
for (i = 0; i < num_slots; ++i) { for (i = 0; i < num_slots; ++i) {
slot = kmalloc(sizeof(struct slot), GFP_KERNEL); slot = kzalloc(sizeof(*slot), GFP_KERNEL);
if (!slot) if (!slot)
goto error; goto error;
memset(slot, 0, sizeof(struct slot));
hotplug_slot = kmalloc(sizeof(struct hotplug_slot), hotplug_slot = kzalloc(sizeof(*hotplug_slot), GFP_KERNEL);
GFP_KERNEL);
if (!hotplug_slot) if (!hotplug_slot)
goto error_slot; goto error_slot;
memset(hotplug_slot, 0, sizeof (struct hotplug_slot));
slot->hotplug_slot = hotplug_slot; slot->hotplug_slot = hotplug_slot;
info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info) if (!info)
goto error_hpslot; goto error_hpslot;
memset(info, 0, sizeof (struct hotplug_slot_info));
hotplug_slot->info = info; hotplug_slot->info = info;
name = kmalloc(SLOT_NAME_SIZE, GFP_KERNEL);
if (!name)
goto error_info;
hotplug_slot->name = name;
slot->number = i; slot->number = i;
hotplug_slot->name = slot->name;
hotplug_slot->private = slot; hotplug_slot->private = slot;
hotplug_slot->release = &release_slot; hotplug_slot->release = &release_slot;
make_slot_name(slot); make_slot_name(slot);
...@@ -300,16 +291,16 @@ static int __init init_slots(void) ...@@ -300,16 +291,16 @@ static int __init init_slots(void)
* Initialize the slot info structure with some known * Initialize the slot info structure with some known
* good values. * good values.
*/ */
info->power_status = get_power_status(slot); get_power_status(hotplug_slot, &info->power_status);
info->attention_status = get_attention_status(slot); get_attention_status(hotplug_slot, &info->attention_status);
info->latch_status = get_latch_status(slot); get_latch_status(hotplug_slot, &info->latch_status);
info->adapter_status = get_adapter_status(slot); get_adapter_status(hotplug_slot, &info->adapter_status);
dbg("registering slot %d\n", i); dbg("registering slot %d\n", i);
retval = pci_hp_register(slot->hotplug_slot); retval = pci_hp_register(slot->hotplug_slot);
if (retval) { if (retval) {
err("pci_hp_register failed with error %d\n", retval); err("pci_hp_register failed with error %d\n", retval);
goto error_name; goto error_info;
} }
/* add slot to our internal list */ /* add slot to our internal list */
...@@ -317,8 +308,6 @@ static int __init init_slots(void) ...@@ -317,8 +308,6 @@ static int __init init_slots(void)
} }
return 0; return 0;
error_name:
kfree(name);
error_info: error_info:
kfree(info); kfree(info);
error_hpslot: error_hpslot:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment