[PATCH 19/22] portdrv: introduce get_port_err_handler

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Cleanup ugly nested if-blocks.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
---
 drivers/pci/pcie/portdrv_pci.c |  108 +++++++++++++++++++---------------------
 1 files changed, 51 insertions(+), 57 deletions(-)

diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index 13c8972..e8c621f 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -97,31 +97,36 @@ static void pcie_portdrv_remove(struct pci_dev *dev)
 	pci_disable_device(dev);
 }
 
+static struct pci_error_handlers *get_port_err_handler(struct device *device)
+{
+	struct pcie_port_service_driver *driver;
+
+	if (device->bus == &pcie_port_bus_type && device->driver) {
+		driver = to_service_driver(device->driver);
+		if (driver)
+			return driver->err_handler;
+	}
+	return NULL;
+}
+
 static int error_detected_iter(struct device *device, void *data)
 {
 	struct pcie_device *pcie_device;
-	struct pcie_port_service_driver *driver;
+	struct pci_error_handlers *handler;
 	struct aer_broadcast_data *result_data;
 	pci_ers_result_t status;
 
 	result_data = (struct aer_broadcast_data *) data;
 
-	if (device->bus == &pcie_port_bus_type && device->driver) {
-		driver = to_service_driver(device->driver);
-		if (!driver ||
-			!driver->err_handler ||
-			!driver->err_handler->error_detected)
-			return 0;
-
-		pcie_device = to_pcie_device(device);
-
-		/* Forward error detected message to service drivers */
-		status = driver->err_handler->error_detected(
-			pcie_device->port,
-			result_data->state);
-		result_data->result =
-			merge_result(result_data->result, status);
-	}
+	handler = get_port_err_handler(device);
+	if (!handler || !handler->error_detected)
+		return 0;
+
+	pcie_device = to_pcie_device(device);
+
+	/* Forward error detected message to service drivers */
+	status = handler->error_detected(pcie_device->port, result_data->state);
+	result_data->result = merge_result(result_data->result, status);
 
 	return 0;
 }
@@ -141,24 +146,20 @@ static pci_ers_result_t pcie_portdrv_error_detected(struct pci_dev *dev,
 static int mmio_enabled_iter(struct device *device, void *data)
 {
 	struct pcie_device *pcie_device;
-	struct pcie_port_service_driver *driver;
+	struct pci_error_handlers *handler;
 	pci_ers_result_t status, *result;
 
 	result = (pci_ers_result_t *) data;
 
-	if (device->bus == &pcie_port_bus_type && device->driver) {
-		driver = to_service_driver(device->driver);
-		if (driver &&
-			driver->err_handler &&
-			driver->err_handler->mmio_enabled) {
-			pcie_device = to_pcie_device(device);
-
-			/* Forward error message to service drivers */
-			status = driver->err_handler->mmio_enabled(
-					pcie_device->port);
-			*result = merge_result(*result, status);
-		}
-	}
+	handler = get_port_err_handler(device);
+	if (!handler || !handler->mmio_enabled)
+		return 0;
+
+	pcie_device = to_pcie_device(device);
+
+	/* Forward error message to service drivers */
+	status = handler->mmio_enabled(pcie_device->port);
+	*result = merge_result(*result, status);
 
 	return 0;
 }
@@ -176,24 +177,20 @@ static pci_ers_result_t pcie_portdrv_mmio_enabled(struct pci_dev *dev)
 static int slot_reset_iter(struct device *device, void *data)
 {
 	struct pcie_device *pcie_device;
-	struct pcie_port_service_driver *driver;
+	struct pci_error_handlers *handler;
 	pci_ers_result_t status, *result;
 
 	result = (pci_ers_result_t *) data;
 
-	if (device->bus == &pcie_port_bus_type && device->driver) {
-		driver = to_service_driver(device->driver);
-		if (driver &&
-			driver->err_handler &&
-			driver->err_handler->slot_reset) {
-			pcie_device = to_pcie_device(device);
-
-			/* Forward error message to service drivers */
-			status = driver->err_handler->slot_reset(
-					pcie_device->port);
-			*result = merge_result(*result, status);
-		}
-	}
+	handler = get_port_err_handler(device);
+	if (!handler || !handler->slot_reset)
+		return 0;
+
+	pcie_device = to_pcie_device(device);
+
+	/* Forward error message to service drivers */
+	status = handler->slot_reset(pcie_device->port);
+	*result = merge_result(*result, status);
 
 	return 0;
 }
@@ -220,19 +217,16 @@ static pci_ers_result_t pcie_portdrv_slot_reset(struct pci_dev *dev)
 static int resume_iter(struct device *device, void *data)
 {
 	struct pcie_device *pcie_device;
-	struct pcie_port_service_driver *driver;
+	struct pci_error_handlers *handler;
 
-	if (device->bus == &pcie_port_bus_type && device->driver) {
-		driver = to_service_driver(device->driver);
-		if (driver &&
-			driver->err_handler &&
-			driver->err_handler->resume) {
-			pcie_device = to_pcie_device(device);
-
-			/* Forward error message to service drivers */
-			driver->err_handler->resume(pcie_device->port);
-		}
-	}
+	handler = get_port_err_handler(device);
+	if (!handler || !handler->resume)
+		return 0;
+
+	pcie_device = to_pcie_device(device);
+
+	/* Forward error message to service drivers */
+	handler->resume(pcie_device->port);
 
 	return 0;
 }
-- 
1.7.0.4


--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux