tpm-chip.c (6ea24cf79e055f0a62a64baa8587e2254a493c7b) tpm-chip.c (8cfffc9d4d3786d3b496a021d7224e06328bac7d)
1/*
2 * Copyright (C) 2004 IBM Corporation
3 * Copyright (C) 2014 Intel Corporation
4 *
5 * Authors:
6 * Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
7 * Leendert van Doorn <leendert@watson.ibm.com>
8 * Dave Safford <safford@watson.ibm.com>

--- 35 unchanged lines hidden (view full) ---

44{
45 struct tpm_chip *pos, *chip = NULL;
46
47 rcu_read_lock();
48 list_for_each_entry_rcu(pos, &tpm_chip_list, list) {
49 if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num)
50 continue;
51
1/*
2 * Copyright (C) 2004 IBM Corporation
3 * Copyright (C) 2014 Intel Corporation
4 *
5 * Authors:
6 * Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
7 * Leendert van Doorn <leendert@watson.ibm.com>
8 * Dave Safford <safford@watson.ibm.com>

--- 35 unchanged lines hidden (view full) ---

44{
45 struct tpm_chip *pos, *chip = NULL;
46
47 rcu_read_lock();
48 list_for_each_entry_rcu(pos, &tpm_chip_list, list) {
49 if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num)
50 continue;
51
52 if (try_module_get(pos->pdev->driver->owner)) {
52 if (try_module_get(pos->dev.parent->driver->owner)) {
53 chip = pos;
54 break;
55 }
56 }
57 rcu_read_unlock();
58 return chip;
59}
60

--- 47 unchanged lines hidden (view full) ---

108 kfree(chip);
109 return ERR_PTR(-ENOMEM);
110 }
111
112 set_bit(chip->dev_num, dev_mask);
113
114 scnprintf(chip->devname, sizeof(chip->devname), "tpm%d", chip->dev_num);
115
53 chip = pos;
54 break;
55 }
56 }
57 rcu_read_unlock();
58 return chip;
59}
60

--- 47 unchanged lines hidden (view full) ---

108 kfree(chip);
109 return ERR_PTR(-ENOMEM);
110 }
111
112 set_bit(chip->dev_num, dev_mask);
113
114 scnprintf(chip->devname, sizeof(chip->devname), "tpm%d", chip->dev_num);
115
116 chip->pdev = dev;
117
118 dev_set_drvdata(dev, chip);
119
120 chip->dev.class = tpm_class;
121 chip->dev.release = tpm_dev_release;
116 dev_set_drvdata(dev, chip);
117
118 chip->dev.class = tpm_class;
119 chip->dev.release = tpm_dev_release;
122 chip->dev.parent = chip->pdev;
120 chip->dev.parent = dev;
123#ifdef CONFIG_ACPI
124 chip->dev.groups = chip->groups;
125#endif
126
127 if (chip->dev_num == 0)
128 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR);
129 else
130 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num);
131
132 dev_set_name(&chip->dev, "%s", chip->devname);
133
134 device_initialize(&chip->dev);
135
136 cdev_init(&chip->cdev, &tpm_fops);
121#ifdef CONFIG_ACPI
122 chip->dev.groups = chip->groups;
123#endif
124
125 if (chip->dev_num == 0)
126 chip->dev.devt = MKDEV(MISC_MAJOR, TPM_MINOR);
127 else
128 chip->dev.devt = MKDEV(MAJOR(tpm_devt), chip->dev_num);
129
130 dev_set_name(&chip->dev, "%s", chip->devname);
131
132 device_initialize(&chip->dev);
133
134 cdev_init(&chip->cdev, &tpm_fops);
137 chip->cdev.owner = chip->pdev->driver->owner;
135 chip->cdev.owner = dev->driver->owner;
138 chip->cdev.kobj.parent = &chip->dev.kobj;
139
140 rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
141 if (rc) {
142 put_device(&chip->dev);
143 return ERR_PTR(rc);
144 }
145

--- 90 unchanged lines hidden (view full) ---

236 /* Make the chip available. */
237 spin_lock(&driver_lock);
238 list_add_tail_rcu(&chip->list, &tpm_chip_list);
239 spin_unlock(&driver_lock);
240
241 chip->flags |= TPM_CHIP_FLAG_REGISTERED;
242
243 if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
136 chip->cdev.kobj.parent = &chip->dev.kobj;
137
138 rc = devm_add_action(dev, (void (*)(void *)) put_device, &chip->dev);
139 if (rc) {
140 put_device(&chip->dev);
141 return ERR_PTR(rc);
142 }
143

--- 90 unchanged lines hidden (view full) ---

234 /* Make the chip available. */
235 spin_lock(&driver_lock);
236 list_add_tail_rcu(&chip->list, &tpm_chip_list);
237 spin_unlock(&driver_lock);
238
239 chip->flags |= TPM_CHIP_FLAG_REGISTERED;
240
241 if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
244 rc = __compat_only_sysfs_link_entry_to_kobj(&chip->pdev->kobj,
245 &chip->dev.kobj,
246 "ppi");
242 rc = __compat_only_sysfs_link_entry_to_kobj(
243 &chip->dev.parent->kobj, &chip->dev.kobj, "ppi");
247 if (rc && rc != -ENOENT) {
248 tpm_chip_unregister(chip);
249 return rc;
250 }
251 }
252
253 return 0;
254out_err:

--- 18 unchanged lines hidden (view full) ---

273 return;
274
275 spin_lock(&driver_lock);
276 list_del_rcu(&chip->list);
277 spin_unlock(&driver_lock);
278 synchronize_rcu();
279
280 if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
244 if (rc && rc != -ENOENT) {
245 tpm_chip_unregister(chip);
246 return rc;
247 }
248 }
249
250 return 0;
251out_err:

--- 18 unchanged lines hidden (view full) ---

270 return;
271
272 spin_lock(&driver_lock);
273 list_del_rcu(&chip->list);
274 spin_unlock(&driver_lock);
275 synchronize_rcu();
276
277 if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
281 sysfs_remove_link(&chip->pdev->kobj, "ppi");
278 sysfs_remove_link(&chip->dev.parent->kobj, "ppi");
282
283 tpm1_chip_unregister(chip);
284 tpm_del_char_device(chip);
285}
286EXPORT_SYMBOL_GPL(tpm_chip_unregister);
279
280 tpm1_chip_unregister(chip);
281 tpm_del_char_device(chip);
282}
283EXPORT_SYMBOL_GPL(tpm_chip_unregister);