ChangeSet 1.1587.12.22, 2004/04/29 16:02:12-07:00, eike-hotplug@sf-tec.de [PATCH] PCI Hotplug skeleton: remove useless NULL checks This one removes all the useless NULL checks including slot_paranoia_check, get_slot and the magic number from the PCI hotplug skeleton driver. Also some lines containing only a single tab are fixed. drivers/pci/hotplug/pcihp_skeleton.c | 99 ++++++----------------------------- 1 files changed, 17 insertions(+), 82 deletions(-) diff -Nru a/drivers/pci/hotplug/pcihp_skeleton.c b/drivers/pci/hotplug/pcihp_skeleton.c --- a/drivers/pci/hotplug/pcihp_skeleton.c Mon May 17 17:04:48 2004 +++ b/drivers/pci/hotplug/pcihp_skeleton.c Mon May 17 17:04:48 2004 @@ -38,9 +38,7 @@ #include "pci_hotplug.h" -#define SLOT_MAGIC 0x67267322 struct slot { - u32 magic; u8 number; struct hotplug_slot *hotplug_slot; struct list_head slot_list; @@ -97,49 +95,11 @@ .get_adapter_status = get_adapter_status, }; - -/* Inline functions to check the sanity of a pointer that is passed to us */ -static inline int slot_paranoia_check (struct slot *slot, const char *function) -{ - if (!slot) { - dbg("%s - slot == NULL", function); - return -1; - } - if (slot->magic != SLOT_MAGIC) { - dbg("%s - bad magic number for slot", function); - return -1; - } - if (!slot->hotplug_slot) { - dbg("%s - slot->hotplug_slot == NULL!", function); - return -1; - } - return 0; -} - -static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function) -{ - struct slot *slot; - - if (!hotplug_slot) { - dbg("%s - hotplug_slot == NULL\n", function); - return NULL; - } - - slot = (struct slot *)hotplug_slot->private; - if (slot_paranoia_check (slot, function)) - return NULL; - return slot; -} - - static int enable_slot (struct hotplug_slot *hotplug_slot) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg ("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); /* @@ -152,12 +112,9 @@ static int disable_slot (struct hotplug_slot *hotplug_slot) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg ("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); /* @@ -169,12 +126,9 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg ("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); switch (status) { @@ -197,12 +151,9 @@ static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg ("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); err ("No hardware tests are defined for this driver"); @@ -215,12 +166,9 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); /* @@ -233,12 +181,9 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); /* @@ -251,12 +196,9 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); /* @@ -269,12 +211,9 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) { - struct slot *slot = get_slot (hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - - if (slot == NULL) - return -ENODEV; - + dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); /* @@ -287,12 +226,9 @@ static void release_slots(struct hotplug_slot *hotplug_slot) { - struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); + struct slot *slot = hotplug_slot->private; int retval = 0; - if (slot == NULL) - return -ENODEV; - dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); kfree(slot->hotplug_slot->info); kfree(slot->hotplug_slot->name); @@ -355,7 +291,6 @@ } hotplug_slot->name = name; - slot->magic = SLOT_MAGIC; slot->number = i; hotplug_slot->private = slot;