ChangeSet 1.1587.12.49, 2004/04/30 14:47:34-07:00, eike-hotplug@sf-tec.de

[PATCH] PCI Express Hotplug: remove useless NULL checks

Remove useless NULL checks and magic numbers from PCI Express Hotplug, also
some minimal coding style fixes.


 drivers/pci/hotplug/pciehp.h      |   43 +---------------------
 drivers/pci/hotplug/pciehp_core.c |   72 +++++++++++---------------------------
 2 files changed, 23 insertions(+), 92 deletions(-)


diff -Nru a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
--- a/drivers/pci/hotplug/pciehp.h	Mon May 17 17:00:56 2004
+++ b/drivers/pci/hotplug/pciehp.h	Mon May 17 17:00:56 2004
@@ -68,9 +68,7 @@
 	struct pci_dev* pci_dev;
 };
 
-#define SLOT_MAGIC	0x67267321
 struct slot {
-	u32 magic;
 	struct slot *next;
 	u8 bus;
 	u8 device;
@@ -235,47 +233,10 @@
 
 /* Inline functions */
 
-
-/* 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 inline struct slot *pciehp_find_slot (struct controller *ctrl, u8 device)
+static inline struct slot *pciehp_find_slot(struct controller *ctrl, u8 device)
 {
 	struct slot *p_slot, *tmp_slot = NULL;
 
-	if (!ctrl)
-		return NULL;
-
 	p_slot = ctrl->slot;
 
 	dbg("p_slot = %p\n", p_slot);
@@ -293,7 +254,7 @@
 	return (p_slot);
 }
 
-static inline int wait_for_ctrl_irq (struct controller *ctrl)
+static inline int wait_for_ctrl_irq(struct controller *ctrl)
 {
 	int retval = 0;
 
diff -Nru a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
--- a/drivers/pci/hotplug/pciehp_core.c	Mon May 17 17:00:56 2004
+++ b/drivers/pci/hotplug/pciehp_core.c	Mon May 17 17:00:56 2004
@@ -229,13 +229,10 @@
 /*
  * set_attention_status - Turns the Amber LED for a slot on, off or blink
  */
-static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
+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;
 
-	if (slot == NULL)
-		return -ENODEV;
-	
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
 	hotplug_slot->info->attention_status = status;
@@ -245,12 +242,9 @@
 }
 
 
-static int enable_slot (struct hotplug_slot *hotplug_slot)
+static int enable_slot(struct hotplug_slot *hotplug_slot)
 {
-	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
-	
-	if (slot == NULL)
-		return -ENODEV;
+	struct slot *slot = hotplug_slot->private;
 
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
@@ -258,33 +252,25 @@
 }
 
 
-static int disable_slot (struct hotplug_slot *hotplug_slot)
+static int disable_slot(struct hotplug_slot *hotplug_slot)
 {
-	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
-	
-	if (slot == NULL)
-		return -ENODEV;
+	struct slot *slot = hotplug_slot->private;
 
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
 	return pciehp_disable_slot(slot);
 }
 
-
 static int hardware_test (struct hotplug_slot *hotplug_slot, u32 value)
 {
 	return 0;
 }
 
-
-static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
+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;
-	
-	if (slot == NULL)
-		return -ENODEV;
-	
+
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
 	retval = slot->hpc_ops->get_power_status(slot, value);
@@ -294,14 +280,11 @@
 	return 0;
 }
 
-static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
+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;
-	
-	if (slot == NULL)
-		return -ENODEV;
-	
+
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
 	retval = slot->hpc_ops->get_attention_status(slot, value);
@@ -311,14 +294,11 @@
 	return 0;
 }
 
-static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
+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;
-	
-	if (slot == NULL)
-		return -ENODEV;
-	
+
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
 	retval = slot->hpc_ops->get_latch_status(slot, value);
@@ -328,31 +308,24 @@
 	return 0;
 }
 
-static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
+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;
-	
-	if (slot == NULL)
-		return -ENODEV;
 
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 
 	retval = slot->hpc_ops->get_adapter_status(slot, value);
-
 	if (retval < 0)
 		*value = hotplug_slot->info->adapter_status;
 
 	return 0;
 }
 
-static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
+static int get_max_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
 {
-	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
+	struct slot *slot = hotplug_slot->private;
 	int retval;
-	
-	if (slot == NULL)
-		return -ENODEV;
 
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
 	
@@ -363,13 +336,10 @@
 	return 0;
 }
 
-static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
+static int get_cur_bus_speed(struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
 {
-	struct slot *slot = get_slot (hotplug_slot, __FUNCTION__);
+	struct slot *slot = hotplug_slot->private;
 	int retval;
-	
-	if (slot == NULL)
-		return -ENODEV;
 
 	dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);