All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcel Selhorst <selhorst@crypto.rub.de>
To: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>,
	Kylene Jo Hall <kjhall@us.ibm.com>,
	matthieu castet <castet.matthieu@free.fr>,
	Alex Williamson <alex.williamson@hp.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] tpm_infineon: Bugfix in PNPACPI-handling
Date: Sun, 07 Aug 2005 13:58:32 +0200	[thread overview]
Message-ID: <42F5F768.3000204@crypto.rub.de> (raw)

Dear all,

Changelog:

This patch corrects the PNP-handling inside the tpm-driver
and some minor coding style bugs.
Note: the pci-device and pnp-device mixture is currently necessary,
since the used "tpm"-interface requires a pci-dev in order to register
the driver. This will be fixed within the next iterations.

Signed-off-by: Marcel Selhorst <selhorst@crypto.rub.de>
---

diff -pruN linux-2.6.13-rc5/drivers/char/tpm/tpm_infineon.c
linux-2.6.13-rc5.new/drivers/char/tpm/tpm_infineon.c
--- linux-2.6.13-rc5/drivers/char/tpm/tpm_infineon.c	2005-08-06 17:07:55.000000000 +0000
+++ linux-2.6.13-rc5.new/drivers/char/tpm/tpm_infineon.c	2005-08-06
18:56:46.000000000 +0000
@@ -14,7 +14,6 @@
  * License.
  */

-#include <acpi/acpi_bus.h>
 #include <linux/pnp.h>
 #include "tpm.h"

@@ -29,9 +28,10 @@
 #define	TPM_MAX_TRIES		5000
 #define	TPM_INFINEON_DEV_VEN_VALUE	0x15D1

-/* These values will be filled after ACPI-call */
+/* These values will be filled after PnP-call */
 static int TPM_INF_DATA = 0;
 static int TPM_INF_ADDR = 0;
+static int pnp_registered = 0;

 /* TPM header definitions */
 enum infineon_tpm_header {
@@ -356,24 +356,26 @@ static const struct pnp_device_id tpm_pn
 	{"IFX0102", 0},
 	{"", 0}
 };
+MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);

-static int __devinit tpm_inf_acpi_probe(struct pnp_dev *dev,
+static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
 					const struct pnp_device_id *dev_id)
 {
-	TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff);
-	TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff);
-	tpm_inf.base = pnp_port_start(dev, 1);
-	dev_info(&dev->dev, "Found %s with ID %s\n",
+	if (pnp_port_valid(dev, 0)) {
+	    TPM_INF_ADDR = (pnp_port_start(dev, 0) & 0xff);
+	    TPM_INF_DATA = ((TPM_INF_ADDR + 1) & 0xff);
+	    tpm_inf.base = pnp_port_start(dev, 1);
+	    dev_info(&dev->dev, "Found %s with ID %s\n",
 		 dev->name, dev_id->id);
-	if (!((tpm_inf.base >> 8) & 0xff))
-		tpm_inf.base = 0;
-	return 0;
+	    return 0;
+	} else
+	    return -ENODEV;
 }

 static struct pnp_driver tpm_inf_pnp = {
 	.name = "tpm_inf_pnp",
 	.id_table = tpm_pnp_tbl,
-	.probe = tpm_inf_acpi_probe,
+	.probe = tpm_inf_pnp_probe,
 };

 static int __devinit tpm_inf_probe(struct pci_dev *pci_dev,
@@ -386,19 +388,28 @@ static int __devinit tpm_inf_probe(struc
 	int productid[2];
 	char chipname[20];

-	if (pci_enable_device(pci_dev))
-		return -EIO;
+	rc = pci_enable_device(pci_dev);
+	if (rc)
+	    return rc;

 	dev_info(&pci_dev->dev, "LPC-bus found at 0x%x\n", pci_id->device);

-	/* read IO-ports from ACPI */
-	pnp_register_driver(&tpm_inf_pnp);
-	pnp_unregister_driver(&tpm_inf_pnp);
+	/* read IO-ports from PnP */
+	rc = pnp_register_driver(&tpm_inf_pnp);
+	if (rc < 0) {
+	    dev_err(&pci_dev->dev, "Error %x from pnp_register_driver!\n",rc);
+	    goto error2;
+	}
+	if (!rc) {
+	    dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
+	    goto error;
+	} else
+	    pnp_registered = 1;

 	/* Make sure, we have received valid config ports */
 	if (!TPM_INF_ADDR) {
-		pci_disable_device(pci_dev);
-		return -EIO;
+	    dev_err(&pci_dev->dev, "No valid IO-ports received!\n");
+	    goto error;
 	}

 	/* query chip for its vendor, its version number a.s.o. */
@@ -418,23 +429,21 @@ static int __devinit tpm_inf_probe(struc

 	switch ((productid[0] << 8) | productid[1]) {
 	case 6:
-		sprintf(chipname, " (SLD 9630 TT 1.1)");
+		snprintf(chipname, sizeof(chipname), " (SLD 9630 TT 1.1)");
 		break;
 	case 11:
-		sprintf(chipname, " (SLB 9635 TT 1.2)");
+		snprintf(chipname, sizeof(chipname), " (SLB 9635 TT 1.2)");
 		break;
 	default:
-		sprintf(chipname, " (unknown chip)");
+		snprintf(chipname, sizeof(chipname), " (unknown chip)");
 		break;
 	}
-	chipname[19] = 0;

 	if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) {

 		if (tpm_inf.base == 0) {
-			dev_err(&pci_dev->dev, "No IO-ports found!\n");
-			pci_disable_device(pci_dev);
-			return -EIO;
+		    dev_err(&pci_dev->dev, "No IO-ports found!\n");
+		    goto error;
 		}
 		/* configure TPM with IO-ports */
 		outb(IOLIMH, TPM_INF_ADDR);
@@ -452,8 +461,7 @@ static int __devinit tpm_inf_probe(struc
 			dev_err(&pci_dev->dev,
 				"Could not set IO-ports to %04x\n",
 				tpm_inf.base);
-			pci_disable_device(pci_dev);
-			return -EIO;
+		    goto error;
 		}

 		/* activate register */
@@ -479,14 +487,16 @@ static int __devinit tpm_inf_probe(struc
 			 productid[0], productid[1], chipname);

 		rc = tpm_register_hardware(pci_dev, &tpm_inf);
-		if (rc < 0) {
-			pci_disable_device(pci_dev);
-			return -ENODEV;
-		}
+		if (rc < 0)
+		    goto error;
 		return 0;
 	} else {
 		dev_info(&pci_dev->dev, "No Infineon TPM found!\n");
+error:
+		pnp_unregister_driver(&tpm_inf_pnp);
+error2:
 		pci_disable_device(pci_dev);
+		pnp_registered = 0;
 		return -ENODEV;
 	}
 }
@@ -521,6 +531,8 @@ static int __init init_inf(void)

 static void __exit cleanup_inf(void)
 {
+	if (pnp_registered)
+	    pnp_unregister_driver(&tpm_inf_pnp);	
 	pci_unregister_driver(&inf_pci_driver);
 }


             reply	other threads:[~2005-08-07 11:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-07 11:58 Marcel Selhorst [this message]
2005-08-07 16:52 ` [PATCH] tpm_infineon: Bugfix in PNPACPI-handling Andrew Morton

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=42F5F768.3000204@crypto.rub.de \
    --to=selhorst@crypto.rub.de \
    --cc=akpm@osdl.org \
    --cc=alex.williamson@hp.com \
    --cc=castet.matthieu@free.fr \
    --cc=kjhall@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.