Re: [PATCH 05/22] aerdrv: rework find_device_iter

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

 



Hidetoshi Seto wrote:
Simplify ID comparison path by having unified path labeled "found:"
to register device to be handled. If we cannot register any more,
stop iteration by returning 1.

And too-simple subfunctions only used here are inlined.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
---
 drivers/pci/pcie/aer/aerdrv_core.c |   87 +++++++++++------------------------
 1 files changed, 28 insertions(+), 59 deletions(-)

diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
index 1feb725..6fd8f55 100644
--- a/drivers/pci/pcie/aer/aerdrv_core.c
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -132,40 +132,13 @@ static void set_downstream_devices_error_reporting(struct pci_dev *dev,
 	pci_walk_bus(dev->subordinate, set_device_error_reporting, &enable);
 }
-static inline int compare_device_id(struct pci_dev *dev,
-			struct aer_err_info *e_info)
-{
-	if (e_info->id == ((dev->bus->number << 8) | dev->devfn)) {
-		/*
-		 * Device ID match
-		 */
-		return 1;
-	}
-
-	return 0;
-}
-
-static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev)
-{
-	if (e_info->error_dev_num < AER_MAX_MULTI_ERR_DEVICES) {
-		e_info->dev[e_info->error_dev_num] = dev;
-		e_info->error_dev_num++;
-		return 1;
-	}
-
-	return 0;
-}
-
-
 #define	PCI_BUS(x)	(((x) >> 8) & 0xff)
static int find_device_iter(struct pci_dev *dev, void *data)
 {
 	int pos;
-	u32 status;
-	u32 mask;
+	u32 status, mask;
 	u16 reg16;
-	int result;
 	struct aer_err_info *e_info = (struct aer_err_info *)data;
/*
@@ -173,23 +146,12 @@ static int find_device_iter(struct pci_dev *dev, void *data)
 	 * reported by root port.
 	 */
 	if (!nosourceid && (PCI_BUS(e_info->id) != 0)) {
-		result = compare_device_id(dev, e_info);
-		if (result)
-			add_error_device(e_info, dev);
+		/* Device ID match? */
+		if (e_info->id == ((dev->bus->number << 8) | dev->devfn))
+			goto found;
- /*
-		 * If there is no multiple error, we stop
-		 * or continue based on the id comparing.
-		 */
+		/* Continue id comparing if there is no multiple error */
 		if (!e_info->multi_error_valid)
-			return result;
-
-		/*
-		 * If there are multiple errors and id does match,
-		 * We need continue to search other devices under
-		 * the root port. Return 0 means that.
-		 */
-		if (result)
 			return 0;
 	}
@@ -199,15 +161,16 @@ static int find_device_iter(struct pci_dev *dev, void *data)
 	 *      2) bus id is equal to 0. Some ports might lose the bus
 	 *              id of error source id;
 	 *      3) There are multiple errors and prior id comparing fails;
-	 * We check AER status registers to find the initial reporter.
+	 * We check AER status registers to find possible reporter.
 	 */
 	if (atomic_read(&dev->enable_cnt) == 0)
 		return 0;
 	pos = pci_pcie_cap(dev);
 	if (!pos)
 		return 0;
+
 	/* Check if AER is enabled */
-	pci_read_config_word(dev, pos+PCI_EXP_DEVCTL, &reg16);
+	pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &reg16);
 	if (!(reg16 & (
 		PCI_EXP_DEVCTL_CERE |
 		PCI_EXP_DEVCTL_NFERE |
@@ -218,31 +181,37 @@ static int find_device_iter(struct pci_dev *dev, void *data)
 	if (!pos)
 		return 0;
- status = 0;
-	mask = 0;
+	/* Check if error is recorded */
 	if (e_info->severity == AER_CORRECTABLE) {
 		pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &status);
 		pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, &mask);
-		if (status & ~mask) {
-			add_error_device(e_info, dev);
-			goto added;
-		}
 	} else {
 		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
 		pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, &mask);
-		if (status & ~mask) {
-			add_error_device(e_info, dev);
-			goto added;
-		}
 	}
+	if (status & ~mask)
+		goto found;
return 0; -added:
+found:
+	/* List this device */
+	if (e_info->error_dev_num < AER_MAX_MULTI_ERR_DEVICES) {
+		e_info->dev[e_info->error_dev_num] = dev;
+		e_info->error_dev_num++;
+	} else {
+		/* We cannot handle more... Stop iteration */
+		return 1;
+	}
+
+	/*
+	 * If there are multiple errors, we need to continue searching
+	 * other devices under the root port. Return 0 means that.
+	 */
 	if (e_info->multi_error_valid)
 		return 0;
-	else
-		return 1;
+
+	return 1;
 }
/**

How about changing like the below?

bool is_error_source(struct pci_dev, struct aer_err_info *e_info)
{
	if (the device is an error source)
		return true;
	return false;
}

int add_error_device()
{
	if (the error buffer is full)
		return -ENOSPC;
	Add error information to the buffuer;
	return 0;
}

static int find_device_iter(struct pci_dev *dev, void *data)
{
	if (is_error_source(dev, e_info)) {
		/* If the error buffer is full, stop iteration */
		if (add_error_device(...)) {
			Maybe error message is required here;
			return 1;
		}
/* If there is only a single error, stop iteration */ if (!e_info->multi_error_valid)
			return 1;
	}
	return 0;
}

Thanks,
Kenji Kaneshige


--
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