Remove unused .get_power() and .set_power()


Why this change should be doing

In the cpci_hotplug.h the struct called `cpci_hp_controller_ops` have two fields called get_power and set_power. This two fields are a pointer for a function.
This functions are a callback that handle the power state of PCI slots.

get_power
 
int (*get_power)(struct slot *slot)
	
This check the current state of slot PCI power. Return 0 for indicate that slot is power off and return 1 for indicate that slot is power on. The negative return indicate a error when trying the get slot state.
This usually was used for safety checking.

set_power
 
int (*set_power)(struct slot *slot, int value)
	
This change the state of PCI slot. The slot parameter in function is a pointer to slot that will be modified, and the value parameter, obviosly is the value of a new state power (usually 0 for off and 1 for on).
This function return 0 for success set state power and a negative value for indicate a error.


The "problem" with this functions is that this is never implement for any driver. This was will created but never used. How is suggested by Lukas Wunner and Bjorn Helgaas, in this TODO this functions never will be used and can be removed.
By removing this function, in addition on remove a die code and improve the readability, we reduce resource consume. The pointers, in modern systems, have 4 bytes for 32 bits systems and 8 bytes for 64bits systems. In kernel developments, any chunk of memory, no matter how small, is valuable.

My proposed solution

This two pointers can be removed, and in the cpci_hotplug_core.c we need remove the calls of set_power() and get_power().
The cpci_hotplug_core.c call the set_power() for set a state power, but the implementation of set_power is responsability of drivers. This means that the driver developer need create a function and send to set_power or get_power a address of this function. Like this:
int my_set_power(struct slot *slot, int value) 
{
	// .. any code		
}

cpci_hp_controller_ops chco {
	.set_power = my_set_power
}
	
This is almost pseudocode.
When the cpci_hotplug_core.c call the set_power (or get_power) the function that is called is the my_set_power(). But, how the any driver do not implement this, no function is called.
In addition on this, the cpci_hotplug_core.c was have a check, if the set_power (get_power) is implemented before call the function. How no driver implement this, the check is uneccessary, and we reduce more resource used (Remember that in the kernel development any resource is valuable).

The diff of my change is:
drivers/pci/hotplug/cpci_hotplug.h      |  2 --
drivers/pci/hotplug/cpci_hotplug_core.c | 17 ++---------------
2 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
index 03fa39ab0c88..a31d6b62f523 100644
--- a/drivers/pci/hotplug/cpci_hotplug.h
+++ b/drivers/pci/hotplug/cpci_hotplug.h
@@ -44,8 +44,6 @@ struct cpci_hp_controller_ops {
 	int (*enable_irq)(void);
 	int (*disable_irq)(void);
 	int (*check_irq)(void *dev_id);
-	u8  (*get_power)(struct slot *slot);
-	int (*set_power)(struct slot *slot, int value);
 };
 
 struct cpci_hp_controller {
diff --git a/drivers/pci/hotplug/cpci_hotplug_core.c b/drivers/pci/hotplug/cpci_hotplug_core.c
index d0559d2faf50..dd93e53ea7c2 100644
--- a/drivers/pci/hotplug/cpci_hotplug_core.c
+++ b/drivers/pci/hotplug/cpci_hotplug_core.c
@@ -71,13 +71,10 @@ static int
 enable_slot(struct hotplug_slot *hotplug_slot)
 {
 	struct slot *slot = to_slot(hotplug_slot);
-	int retval = 0;
 
 	dbg("%s - physical_slot = %s", __func__, slot_name(slot));
 
-	if (controller->ops->set_power)
-		retval = controller->ops->set_power(slot, 1);
-	return retval;
+	return 0;
 }
 
 static int
@@ -109,12 +106,6 @@ disable_slot(struct hotplug_slot *hotplug_slot)
 	}
 	cpci_led_on(slot);
 
-	if (controller->ops->set_power) {
-		retval = controller->ops->set_power(slot, 0);
-		if (retval)
-			goto disable_error;
-	}
-
 	slot->adapter_status = 0;
 
 	if (slot->extracting) {
@@ -129,11 +120,7 @@ disable_slot(struct hotplug_slot *hotplug_slot)
 static u8
 cpci_get_power_status(struct slot *slot)
 {
-	u8 power = 1;
-
-	if (controller->ops->get_power)
-		power = controller->ops->get_power(slot);
-	return power;
+	return 1;
 }
	
I removed the two functions and removed the calls of this functions in the hotplug core.

LINKS

github commit
mailing list