aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKylene Hall <kjhall@us.ibm.com>2005-06-24 01:02:00 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-06-24 03:05:26 -0400
commit6659ca2ab6730c3bbb9fa495f2327b95b955decd (patch)
tree1b8a9a09a830b0a5233c6e9f073c53260dbef819
parent81179bb6a54c2c626b4cbcc084ca974bb2d7f2a3 (diff)
[PATCH] tpm: sysfs owernship changes
In the current driver all sysfs files end up owned by the base driver module rather than the module that actually owns the device this is a problem if the module is unloaded and the file is open. This patch fixes all that and lumps the files into an attribute_group. Signed-off-by: Kylene Hall <kjhall@us.ibm.com> Signed-off-by: Yani Ioannou <yani.ioannou@gmail.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/char/tpm/tpm.c35
-rw-r--r--drivers/char/tpm/tpm.h9
-rw-r--r--drivers/char/tpm/tpm_atmel.c16
-rw-r--r--drivers/char/tpm/tpm_nsc.c17
4 files changed, 64 insertions, 13 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 84b2d46e6ff0..b72050c851d2 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -208,7 +208,8 @@ static const u8 pcrread[] = {
208 0, 0, 0, 0 /* PCR index */ 208 0, 0, 0, 0 /* PCR index */
209}; 209};
210 210
211static ssize_t show_pcrs(struct device *dev, struct device_attribute *attr, char *buf) 211ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr,
212 char *buf)
212{ 213{
213 u8 data[READ_PCR_RESULT_SIZE]; 214 u8 data[READ_PCR_RESULT_SIZE];
214 ssize_t len; 215 ssize_t len;
@@ -243,7 +244,7 @@ static ssize_t show_pcrs(struct device *dev, struct device_attribute *attr, char
243 return str - buf; 244 return str - buf;
244} 245}
245 246
246static DEVICE_ATTR(pcrs, S_IRUGO, show_pcrs, NULL); 247EXPORT_SYMBOL_GPL(tpm_show_pcrs);
247 248
248#define READ_PUBEK_RESULT_SIZE 314 249#define READ_PUBEK_RESULT_SIZE 314
249static const u8 readpubek[] = { 250static const u8 readpubek[] = {
@@ -252,7 +253,8 @@ static const u8 readpubek[] = {
252 0, 0, 0, 124, /* TPM_ORD_ReadPubek */ 253 0, 0, 0, 124, /* TPM_ORD_ReadPubek */
253}; 254};
254 255
255static ssize_t show_pubek(struct device *dev, struct device_attribute *attr, char *buf) 256ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
257 char *buf)
256{ 258{
257 u8 *data; 259 u8 *data;
258 ssize_t len; 260 ssize_t len;
@@ -311,7 +313,7 @@ out:
311 return rc; 313 return rc;
312} 314}
313 315
314static DEVICE_ATTR(pubek, S_IRUGO, show_pubek, NULL); 316EXPORT_SYMBOL_GPL(tpm_show_pubek);
315 317
316#define CAP_VER_RESULT_SIZE 18 318#define CAP_VER_RESULT_SIZE 18
317static const u8 cap_version[] = { 319static const u8 cap_version[] = {
@@ -332,7 +334,8 @@ static const u8 cap_manufacturer[] = {
332 0, 0, 1, 3 334 0, 0, 1, 3
333}; 335};
334 336
335static ssize_t show_caps(struct device *dev, struct device_attribute *attr, char *buf) 337ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr,
338 char *buf)
336{ 339{
337 u8 data[sizeof(cap_manufacturer)]; 340 u8 data[sizeof(cap_manufacturer)];
338 ssize_t len; 341 ssize_t len;
@@ -365,8 +368,20 @@ static ssize_t show_caps(struct device *dev, struct device_attribute *attr, char
365 368
366 return str - buf; 369 return str - buf;
367} 370}
371EXPORT_SYMBOL_GPL(tpm_show_caps);
372
373ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
374 const char *buf, size_t count)
375{
376 struct tpm_chip *chip = dev_get_drvdata(dev);
377 if (chip == NULL)
378 return 0;
379
380 chip->vendor->cancel(chip);
381 return count;
382}
383EXPORT_SYMBOL_GPL(tpm_store_cancel);
368 384
369static DEVICE_ATTR(caps, S_IRUGO, show_caps, NULL);
370 385
371/* 386/*
372 * Device file system interface to the TPM 387 * Device file system interface to the TPM
@@ -517,9 +532,7 @@ void __devexit tpm_remove(struct pci_dev *pci_dev)
517 pci_set_drvdata(pci_dev, NULL); 532 pci_set_drvdata(pci_dev, NULL);
518 misc_deregister(&chip->vendor->miscdev); 533 misc_deregister(&chip->vendor->miscdev);
519 534
520 device_remove_file(&pci_dev->dev, &dev_attr_pubek); 535 sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group);
521 device_remove_file(&pci_dev->dev, &dev_attr_pcrs);
522 device_remove_file(&pci_dev->dev, &dev_attr_caps);
523 536
524 pci_disable_device(pci_dev); 537 pci_disable_device(pci_dev);
525 538
@@ -648,9 +661,7 @@ dev_num_search_complete:
648 661
649 list_add(&chip->list, &tpm_chip_list); 662 list_add(&chip->list, &tpm_chip_list);
650 663
651 device_create_file(&pci_dev->dev, &dev_attr_pubek); 664 sysfs_create_group(&pci_dev->dev.kobj, chip->vendor->attr_group);
652 device_create_file(&pci_dev->dev, &dev_attr_pcrs);
653 device_create_file(&pci_dev->dev, &dev_attr_caps);
654 665
655 return 0; 666 return 0;
656} 667}
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 3a5af7e06624..a3ff4dc5bdb3 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -35,6 +35,14 @@ enum tpm_addr {
35 TPM_DATA = 0x4F 35 TPM_DATA = 0x4F
36}; 36};
37 37
38extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
39 char *);
40extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
41 char *);
42extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
43 char *);
44extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
45 const char *, size_t);
38 46
39struct tpm_chip; 47struct tpm_chip;
40 48
@@ -47,6 +55,7 @@ struct tpm_vendor_specific {
47 int (*send) (struct tpm_chip *, u8 *, size_t); 55 int (*send) (struct tpm_chip *, u8 *, size_t);
48 void (*cancel) (struct tpm_chip *); 56 void (*cancel) (struct tpm_chip *);
49 struct miscdevice miscdev; 57 struct miscdevice miscdev;
58 struct attribute_group *attr_group;
50}; 59};
51 60
52struct tpm_chip { 61struct tpm_chip {
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index 3271391892e8..07abfb7143b1 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -126,6 +126,21 @@ static struct file_operations atmel_ops = {
126 .release = tpm_release, 126 .release = tpm_release,
127}; 127};
128 128
129static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
130static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
131static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
132static DEVICE_ATTR(cancel, S_IWUSR |S_IWGRP, NULL, tpm_store_cancel);
133
134static struct attribute* atmel_attrs[] = {
135 &dev_attr_pubek.attr,
136 &dev_attr_pcrs.attr,
137 &dev_attr_caps.attr,
138 &dev_attr_cancel.attr,
139 0,
140};
141
142static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
143
129static struct tpm_vendor_specific tpm_atmel = { 144static struct tpm_vendor_specific tpm_atmel = {
130 .recv = tpm_atml_recv, 145 .recv = tpm_atml_recv,
131 .send = tpm_atml_send, 146 .send = tpm_atml_send,
@@ -133,6 +148,7 @@ static struct tpm_vendor_specific tpm_atmel = {
133 .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL, 148 .req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
134 .req_complete_val = ATML_STATUS_DATA_AVAIL, 149 .req_complete_val = ATML_STATUS_DATA_AVAIL,
135 .base = TPM_ATML_BASE, 150 .base = TPM_ATML_BASE,
151 .attr_group = &atmel_attr_grp,
136 .miscdev = { .fops = &atmel_ops, }, 152 .miscdev = { .fops = &atmel_ops, },
137}; 153};
138 154
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 24832abe0b2d..675290169508 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -224,6 +224,21 @@ static struct file_operations nsc_ops = {
224 .release = tpm_release, 224 .release = tpm_release,
225}; 225};
226 226
227static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
228static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
229static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
230static DEVICE_ATTR(cancel, S_IWUSR|S_IWGRP, NULL, tpm_store_cancel);
231
232static struct attribute * nsc_attrs[] = {
233 &dev_attr_pubek.attr,
234 &dev_attr_pcrs.attr,
235 &dev_attr_caps.attr,
236 &dev_attr_cancel.attr,
237 0,
238};
239
240static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs };
241
227static struct tpm_vendor_specific tpm_nsc = { 242static struct tpm_vendor_specific tpm_nsc = {
228 .recv = tpm_nsc_recv, 243 .recv = tpm_nsc_recv,
229 .send = tpm_nsc_send, 244 .send = tpm_nsc_send,
@@ -231,8 +246,8 @@ static struct tpm_vendor_specific tpm_nsc = {
231 .req_complete_mask = NSC_STATUS_OBF, 246 .req_complete_mask = NSC_STATUS_OBF,
232 .req_complete_val = NSC_STATUS_OBF, 247 .req_complete_val = NSC_STATUS_OBF,
233 .base = TPM_NSC_BASE, 248 .base = TPM_NSC_BASE,
249 .attr_group = &nsc_attr_grp,
234 .miscdev = { .fops = &nsc_ops, }, 250 .miscdev = { .fops = &nsc_ops, },
235
236}; 251};
237 252
238static int __devinit tpm_nsc_init(struct pci_dev *pci_dev, 253static int __devinit tpm_nsc_init(struct pci_dev *pci_dev,