linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Saheed O. Bolarinwa" <refactormyself@gmail.com>
To: helgaas@kernel.org, Wolfram Sang <wsa@kernel.org>
Cc: "Saheed O. Bolarinwa" <refactormyself@gmail.com>,
	bjorn@helgaas.com, skhan@linuxfoundation.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-i2c@vger.kernel.org
Subject: [RFC PATCH 12/17] i2c: Drop uses of pci_read_config_*() return value
Date: Sat,  1 Aug 2020 13:24:41 +0200	[thread overview]
Message-ID: <20200801112446.149549-13-refactormyself@gmail.com> (raw)
In-Reply-To: <20200801112446.149549-1-refactormyself@gmail.com>

The return value of pci_read_config_*() may not indicate a device error.
However, the value read by these functions is more likely to indicate
this kind of error. This presents two overlapping ways of reporting
errors and complicates error checking.

It is possible to move to one single way of checking for error if the
dependency on the return value of these functions is removed, then it
can later be made to return void.

Remove all uses of the return value of pci_read_config_*().
Check the actual value read for ~0. In this case, ~0 is an invalid
value thus it indicates some kind of error.

Suggested-by: Bjorn Helgaas <bjorn@helgaas.com>
Signed-off-by: Saheed O. Bolarinwa <refactormyself@gmail.com>
---
 drivers/i2c/busses/i2c-ali15x3.c |  6 ++++--
 drivers/i2c/busses/i2c-elektor.c |  3 ++-
 drivers/i2c/busses/i2c-nforce2.c |  4 ++--
 drivers/i2c/busses/i2c-sis5595.c | 17 +++++++++++------
 drivers/i2c/busses/i2c-sis630.c  |  7 ++++---
 drivers/i2c/busses/i2c-viapro.c  | 11 ++++++-----
 6 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 02185a1cfa77..fa103131746d 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -171,9 +171,11 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
 								SMBBA,
 								ali15x3_smba))
 			goto error;
-		if (PCIBIOS_SUCCESSFUL != pci_read_config_word(ALI15X3_dev,
-								SMBBA, &a))
+
+		pci_read_config_word(ALI15X3_dev, SMBBA, &a);
+		if (a == (u16)~0)
 			goto error;
+
 		if ((a & ~(ALI15X3_SMB_IOSIZE - 1)) != ali15x3_smba) {
 			/* make sure it works */
 			dev_err(&ALI15X3_dev->dev,
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 140426db28df..82c8d6d55561 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -207,7 +207,8 @@ static int elektor_match(struct device *dev, unsigned int id)
 		if (cy693_dev) {
 			unsigned char config;
 			/* yeap, we've found cypress, let's check config */
-			if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
+			pci_read_config_byte(cy693_dev, 0x47, &config);
+			if (config != (u8)~0) {
 
 				dev_dbg(dev, "found cy82c693, config "
 					"register 0x47 = 0x%02x\n", config);
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 777278386f58..dc5d032c5a1d 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -327,8 +327,8 @@ static int nforce2_probe_smb(struct pci_dev *dev, int bar, int alt_reg,
 		/* Older incarnations of the device used non-standard BARs */
 		u16 iobase;
 
-		if (pci_read_config_word(dev, alt_reg, &iobase)
-		    != PCIBIOS_SUCCESSFUL) {
+		pci_read_config_word(dev, alt_reg, &iobase);
+		if (iobase == (u16)~0) {
 			dev_err(&dev->dev, "Error reading PCI config for %s\n",
 				name);
 			return -EIO;
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index c793a5c14cda..9b3fbde9cd9c 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -178,9 +178,11 @@ static int sis5595_setup(struct pci_dev *SIS5595_dev)
 		if (pci_write_config_word(SIS5595_dev, ACPI_BASE, sis5595_base)
 		    != PCIBIOS_SUCCESSFUL)
 			goto error;
-		if (pci_read_config_word(SIS5595_dev, ACPI_BASE, &a)
-		    != PCIBIOS_SUCCESSFUL)
+
+		pci_read_config_word(SIS5595_dev, ACPI_BASE, &a);
+		if (a == (u16)~0)
 			goto error;
+
 		if ((a & ~(SIS5595_EXTENT - 1)) != sis5595_base) {
 			/* doesn't work for some chips! */
 			dev_err(&SIS5595_dev->dev, "force address failed - not supported?\n");
@@ -188,17 +190,20 @@ static int sis5595_setup(struct pci_dev *SIS5595_dev)
 		}
 	}
 
-	if (pci_read_config_byte(SIS5595_dev, SIS5595_ENABLE_REG, &val)
-	    != PCIBIOS_SUCCESSFUL)
+	pci_read_config_byte(SIS5595_dev, SIS5595_ENABLE_REG, &val);
+	if (val == (u8)~0)
 		goto error;
+
 	if ((val & 0x80) == 0) {
 		dev_info(&SIS5595_dev->dev, "enabling ACPI\n");
 		if (pci_write_config_byte(SIS5595_dev, SIS5595_ENABLE_REG, val | 0x80)
 		    != PCIBIOS_SUCCESSFUL)
 			goto error;
-		if (pci_read_config_byte(SIS5595_dev, SIS5595_ENABLE_REG, &val)
-		    != PCIBIOS_SUCCESSFUL)
+
+		pci_read_config_byte(SIS5595_dev, SIS5595_ENABLE_REG, &val);
+		if (val == (u8)~0)
 			goto error;
+
 		if ((val & 0x80) == 0) {
 			/* doesn't work for some chips? */
 			dev_err(&SIS5595_dev->dev, "ACPI enable failed - not supported?\n");
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index cfb8e04a2a83..73b17436f964 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -430,7 +430,8 @@ static int sis630_setup(struct pci_dev *sis630_dev)
 	   Enable ACPI first , so we can accsess reg 74-75
 	   in acpi io space and read acpi base addr
 	*/
-	if (pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, &b)) {
+	pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, &b);
+	if (b == (u8)~0) {
 		dev_err(&sis630_dev->dev, "Error: Can't read bios ctl reg\n");
 		retval = -ENODEV;
 		goto exit;
@@ -444,8 +445,8 @@ static int sis630_setup(struct pci_dev *sis630_dev)
 	}
 
 	/* Determine the ACPI base address */
-	if (pci_read_config_word(sis630_dev,
-				 SIS630_ACPI_BASE_REG, &acpi_base)) {
+	pci_read_config_word(sis630_dev, SIS630_ACPI_BASE_REG, &acpi_base);
+	if (acpi_base == (u16)~0) {
 		dev_err(&sis630_dev->dev,
 			"Error: Can't determine ACPI base address\n");
 		retval = -ENODEV;
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 4abc7771af06..14bfa5401845 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -321,12 +321,13 @@ static int vt596_probe(struct pci_dev *pdev,
 		goto found;
 	}
 
-	if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) ||
-	    !(vt596_smba & 0x0001)) {
+	pci_read_config_word(pdev, id->driver_data, &vt596_smba);
+	if ((vt596_smba == (u16)~0) || !(vt596_smba & 0x0001)) {
 		/* try 2nd address and config reg. for 596 */
-		if (id->device == PCI_DEVICE_ID_VIA_82C596_3 &&
-		    !pci_read_config_word(pdev, SMBBA2, &vt596_smba) &&
-		    (vt596_smba & 0x0001)) {
+		pci_read_config_word(pdev, SMBBA2, &vt596_smba);
+		if ((id->device == PCI_DEVICE_ID_VIA_82C596_3) &&
+					(vt596_smba != (u16)~0) &&
+					(vt596_smba & 0x0001)) {
 			SMBHSTCFG = 0x84;
 		} else {
 			/* no matches at all */
-- 
2.18.4


  parent reply	other threads:[~2020-08-01 12:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01 11:24 [RFC PATCH 00/17] Drop uses of pci_read_config_*() return value Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 01/17] ata: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 02/17] atm: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 03/17] bcma: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 04/17] hwrng: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 05/17] dmaengine: ioat: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 06/17] edac: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 07/17] fpga: altera-cvp: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 08/17] gpio: " Saheed O. Bolarinwa
2020-08-18 19:59   ` Bartosz Golaszewski
2020-08-19  2:21     ` Bjorn Helgaas
2020-08-01 11:24 ` [RFC PATCH 09/17] drm/i915/vga: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 10/17] hwmon: " Saheed O. Bolarinwa
2020-08-04 21:26   ` Guenter Roeck
2020-08-01 11:24 ` [RFC PATCH 11/17] intel_th: pci: " Saheed O. Bolarinwa
2020-08-01 11:24 ` Saheed O. Bolarinwa [this message]
2020-08-01 11:24 ` [RFC PATCH 13/17] ide: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 14/17] IB: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 15/17] iommu/vt-d: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 16/17] mtd: " Saheed O. Bolarinwa
2020-08-01 11:24 ` [RFC PATCH 17/17] net: " Saheed O. Bolarinwa
2020-08-01 12:56 ` [RFC PATCH 00/17] " Borislav Petkov
2020-08-02 14:53   ` Tom Rix
2020-08-02 17:28   ` Saheed Bolarinwa
2020-08-02 18:46     ` Borislav Petkov
2020-08-02 19:14       ` Bjorn Helgaas
2020-08-02 20:18         ` Borislav Petkov
2020-08-03  6:56         ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200801112446.149549-13-refactormyself@gmail.com \
    --to=refactormyself@gmail.com \
    --cc=bjorn@helgaas.com \
    --cc=helgaas@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).