]> err.no Git - linux-2.6/commitdiff
[PATCH] tpm: fix error handling
authorJeff Garzik <jeff@garzik.org>
Wed, 11 Oct 2006 08:21:51 +0000 (01:21 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Wed, 11 Oct 2006 18:14:22 +0000 (11:14 -0700)
- handle sysfs error
- handle driver model errors
- de-obfuscate platform_device_register_simple() call, which included an
  assignment in between two function calls, in the same C statement.

Signed-off-by: Jeff Garzik <jeff@garzik.org>
Acked-by: Kylene Hall <kjhall@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/char/tpm/tpm.c
drivers/char/tpm/tpm_atmel.c
drivers/char/tpm/tpm_nsc.c

index a082a2e342522a78edfd642f272784bd1fbee276..6ad2d3bb945c06fc2dc86d92eaa8d2fa410c0308 100644 (file)
@@ -1153,7 +1153,14 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
 
        spin_unlock(&driver_lock);
 
-       sysfs_create_group(&dev->kobj, chip->vendor.attr_group);
+       if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) {
+               list_del(&chip->list);
+               put_device(dev);
+               clear_bit(chip->dev_num, dev_mask);
+               kfree(chip);
+               kfree(devname);
+               return NULL;
+       }
 
        chip->bios_dir = tpm_bios_log_setup(devname);
 
index ad8ffe49256f75990e45a535b534851133eb8526..1ab0896070be2fa7cbc97006de065f5b27ef85dc 100644 (file)
@@ -184,7 +184,9 @@ static int __init init_atmel(void)
        unsigned long base;
        struct  tpm_chip *chip;
 
-       driver_register(&atml_drv);
+       rc = driver_register(&atml_drv);
+       if (rc)
+               return rc;
 
        if ((iobase = atmel_get_base_addr(&base, &region_size)) == NULL) {
                rc = -ENODEV;
@@ -195,10 +197,8 @@ static int __init init_atmel(void)
            (atmel_request_region
             (tpm_atmel.base, region_size, "tpm_atmel0") == NULL) ? 0 : 1;
 
-
-       if (IS_ERR
-           (pdev =
-            platform_device_register_simple("tpm_atmel", -1, NULL, 0))) {
+       pdev = platform_device_register_simple("tpm_atmel", -1, NULL, 0);
+       if (IS_ERR(pdev)) {
                rc = PTR_ERR(pdev);
                goto err_rel_reg;
        }
index 26287aace87db5376bd7a48b18d37ba03564937f..608f73071bef91acbdbcb93d6bf17a7527d9a26a 100644 (file)
@@ -284,7 +284,7 @@ static struct device_driver nsc_drv = {
 static int __init init_nsc(void)
 {
        int rc = 0;
-       int lo, hi;
+       int lo, hi, err;
        int nscAddrBase = TPM_ADDR;
        struct tpm_chip *chip;
        unsigned long base;
@@ -297,7 +297,9 @@ static int __init init_nsc(void)
                        return -ENODEV;
        }
 
-       driver_register(&nsc_drv);
+       err = driver_register(&nsc_drv);
+       if (err)
+               return err;
 
        hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
        lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);