Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 83420
b: refs/heads/master
c: 5bd91f1
h: refs/heads/master
v: v3
  • Loading branch information
Richard MUSIL authored and Linus Torvalds committed Feb 6, 2008
1 parent 34c265c commit 059815b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: eed4a2aba7ff6d8c40d3d55b81f80352765ffcee
refs/heads/master: 5bd91f18be2fc0dd0384fbfca6d3cdd79a8050dd
44 changes: 27 additions & 17 deletions trunk/drivers/char/tpm/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,18 +1031,13 @@ void tpm_remove_hardware(struct device *dev)

spin_unlock(&driver_lock);

dev_set_drvdata(dev, NULL);
misc_deregister(&chip->vendor.miscdev);
kfree(chip->vendor.miscdev.name);

sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
tpm_bios_log_teardown(chip->bios_dir);

clear_bit(chip->dev_num, dev_mask);

kfree(chip);

put_device(dev);
/* write it this way to be explicit (chip->dev == dev) */
put_device(chip->dev);
}
EXPORT_SYMBOL_GPL(tpm_remove_hardware);

Expand Down Expand Up @@ -1082,6 +1077,26 @@ int tpm_pm_resume(struct device *dev)
}
EXPORT_SYMBOL_GPL(tpm_pm_resume);

/*
* Once all references to platform device are down to 0,
* release all allocated structures.
* In case vendor provided release function,
* call it too.
*/
static void tpm_dev_release(struct device *dev)
{
struct tpm_chip *chip = dev_get_drvdata(dev);

if (chip->vendor.release)
chip->vendor.release(dev);

chip->release(dev);

clear_bit(chip->dev_num, dev_mask);
kfree(chip->vendor.miscdev.name);
kfree(chip);
}

/*
* Called from tpm_<specific>.c probe function only for devices
* the driver has determined it should claim. Prior to calling
Expand Down Expand Up @@ -1136,34 +1151,29 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend

chip->vendor.miscdev.parent = dev;
chip->dev = get_device(dev);
chip->release = dev->release;
dev->release = tpm_dev_release;
dev_set_drvdata(dev, chip);

if (misc_register(&chip->vendor.miscdev)) {
dev_err(chip->dev,
"unable to misc_register %s, minor %d\n",
chip->vendor.miscdev.name,
chip->vendor.miscdev.minor);
put_device(dev);
clear_bit(chip->dev_num, dev_mask);
kfree(chip);
kfree(devname);
put_device(chip->dev);
return NULL;
}

spin_lock(&driver_lock);

dev_set_drvdata(dev, chip);

list_add(&chip->list, &tpm_chip_list);

spin_unlock(&driver_lock);

if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) {
list_del(&chip->list);
misc_deregister(&chip->vendor.miscdev);
put_device(dev);
clear_bit(chip->dev_num, dev_mask);
kfree(chip);
kfree(devname);
put_device(chip->dev);
return NULL;
}

Expand Down
2 changes: 2 additions & 0 deletions trunk/drivers/char/tpm/tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct tpm_vendor_specific {
int (*send) (struct tpm_chip *, u8 *, size_t);
void (*cancel) (struct tpm_chip *);
u8 (*status) (struct tpm_chip *);
void (*release) (struct device *);
struct miscdevice miscdev;
struct attribute_group *attr_group;
struct list_head list;
Expand Down Expand Up @@ -106,6 +107,7 @@ struct tpm_chip {
struct dentry **bios_dir;

struct list_head list;
void (*release) (struct device *);
};

#define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
Expand Down

0 comments on commit 059815b

Please sign in to comment.