@@ -36,7 +36,7 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
36
36
int i , rc ;
37
37
char * str = buf ;
38
38
39
- struct tpm_chip * chip = dev_get_drvdata (dev );
39
+ struct tpm_chip * chip = to_tpm_chip (dev );
40
40
41
41
tpm_cmd .header .in = tpm_readpubek_header ;
42
42
err = tpm_transmit_cmd (chip , & tpm_cmd , READ_PUBEK_RESULT_SIZE ,
@@ -92,9 +92,9 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
92
92
ssize_t rc ;
93
93
int i , j , num_pcrs ;
94
94
char * str = buf ;
95
- struct tpm_chip * chip = dev_get_drvdata (dev );
95
+ struct tpm_chip * chip = to_tpm_chip (dev );
96
96
97
- rc = tpm_getcap (dev , TPM_CAP_PROP_PCR , & cap ,
97
+ rc = tpm_getcap (chip , TPM_CAP_PROP_PCR , & cap ,
98
98
"attempting to determine the number of PCRS" );
99
99
if (rc )
100
100
return 0 ;
@@ -119,8 +119,8 @@ static ssize_t enabled_show(struct device *dev, struct device_attribute *attr,
119
119
cap_t cap ;
120
120
ssize_t rc ;
121
121
122
- rc = tpm_getcap (dev , TPM_CAP_FLAG_PERM , & cap ,
123
- "attempting to determine the permanent enabled state" );
122
+ rc = tpm_getcap (to_tpm_chip ( dev ) , TPM_CAP_FLAG_PERM , & cap ,
123
+ "attempting to determine the permanent enabled state" );
124
124
if (rc )
125
125
return 0 ;
126
126
@@ -135,8 +135,8 @@ static ssize_t active_show(struct device *dev, struct device_attribute *attr,
135
135
cap_t cap ;
136
136
ssize_t rc ;
137
137
138
- rc = tpm_getcap (dev , TPM_CAP_FLAG_PERM , & cap ,
139
- "attempting to determine the permanent active state" );
138
+ rc = tpm_getcap (to_tpm_chip ( dev ) , TPM_CAP_FLAG_PERM , & cap ,
139
+ "attempting to determine the permanent active state" );
140
140
if (rc )
141
141
return 0 ;
142
142
@@ -151,8 +151,8 @@ static ssize_t owned_show(struct device *dev, struct device_attribute *attr,
151
151
cap_t cap ;
152
152
ssize_t rc ;
153
153
154
- rc = tpm_getcap (dev , TPM_CAP_PROP_OWNER , & cap ,
155
- "attempting to determine the owner state" );
154
+ rc = tpm_getcap (to_tpm_chip ( dev ) , TPM_CAP_PROP_OWNER , & cap ,
155
+ "attempting to determine the owner state" );
156
156
if (rc )
157
157
return 0 ;
158
158
@@ -167,8 +167,8 @@ static ssize_t temp_deactivated_show(struct device *dev,
167
167
cap_t cap ;
168
168
ssize_t rc ;
169
169
170
- rc = tpm_getcap (dev , TPM_CAP_FLAG_VOL , & cap ,
171
- "attempting to determine the temporary state" );
170
+ rc = tpm_getcap (to_tpm_chip ( dev ) , TPM_CAP_FLAG_VOL , & cap ,
171
+ "attempting to determine the temporary state" );
172
172
if (rc )
173
173
return 0 ;
174
174
@@ -180,20 +180,21 @@ static DEVICE_ATTR_RO(temp_deactivated);
180
180
static ssize_t caps_show (struct device * dev , struct device_attribute * attr ,
181
181
char * buf )
182
182
{
183
+ struct tpm_chip * chip = to_tpm_chip (dev );
183
184
cap_t cap ;
184
185
ssize_t rc ;
185
186
char * str = buf ;
186
187
187
- rc = tpm_getcap (dev , TPM_CAP_PROP_MANUFACTURER , & cap ,
188
+ rc = tpm_getcap (chip , TPM_CAP_PROP_MANUFACTURER , & cap ,
188
189
"attempting to determine the manufacturer" );
189
190
if (rc )
190
191
return 0 ;
191
192
str += sprintf (str , "Manufacturer: 0x%x\n" ,
192
193
be32_to_cpu (cap .manufacturer_id ));
193
194
194
195
/* Try to get a TPM version 1.2 TPM_CAP_VERSION_INFO */
195
- rc = tpm_getcap (dev , CAP_VERSION_1_2 , & cap ,
196
- "attempting to determine the 1.2 version" );
196
+ rc = tpm_getcap (chip , CAP_VERSION_1_2 , & cap ,
197
+ "attempting to determine the 1.2 version" );
197
198
if (!rc ) {
198
199
str += sprintf (str ,
199
200
"TCG version: %d.%d\nFirmware version: %d.%d\n" ,
@@ -203,7 +204,7 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
203
204
cap .tpm_version_1_2 .revMinor );
204
205
} else {
205
206
/* Otherwise just use TPM_STRUCT_VER */
206
- rc = tpm_getcap (dev , CAP_VERSION_1_1 , & cap ,
207
+ rc = tpm_getcap (chip , CAP_VERSION_1_1 , & cap ,
207
208
"attempting to determine the 1.1 version" );
208
209
if (rc )
209
210
return 0 ;
@@ -222,7 +223,7 @@ static DEVICE_ATTR_RO(caps);
222
223
static ssize_t cancel_store (struct device * dev , struct device_attribute * attr ,
223
224
const char * buf , size_t count )
224
225
{
225
- struct tpm_chip * chip = dev_get_drvdata (dev );
226
+ struct tpm_chip * chip = to_tpm_chip (dev );
226
227
if (chip == NULL )
227
228
return 0 ;
228
229
@@ -234,7 +235,7 @@ static DEVICE_ATTR_WO(cancel);
234
235
static ssize_t durations_show (struct device * dev , struct device_attribute * attr ,
235
236
char * buf )
236
237
{
237
- struct tpm_chip * chip = dev_get_drvdata (dev );
238
+ struct tpm_chip * chip = to_tpm_chip (dev );
238
239
239
240
if (chip -> duration [TPM_LONG ] == 0 )
240
241
return 0 ;
@@ -251,7 +252,7 @@ static DEVICE_ATTR_RO(durations);
251
252
static ssize_t timeouts_show (struct device * dev , struct device_attribute * attr ,
252
253
char * buf )
253
254
{
254
- struct tpm_chip * chip = dev_get_drvdata (dev );
255
+ struct tpm_chip * chip = to_tpm_chip (dev );
255
256
256
257
return sprintf (buf , "%d %d %d %d [%s]\n" ,
257
258
jiffies_to_usecs (chip -> timeout_a ),
@@ -281,24 +282,12 @@ static const struct attribute_group tpm_dev_group = {
281
282
.attrs = tpm_dev_attrs ,
282
283
};
283
284
284
- int tpm_sysfs_add_device (struct tpm_chip * chip )
285
+ void tpm_sysfs_add_device (struct tpm_chip * chip )
285
286
{
286
- int err ;
287
- err = sysfs_create_group (& chip -> dev .parent -> kobj ,
288
- & tpm_dev_group );
289
-
290
- if (err )
291
- dev_err (& chip -> dev ,
292
- "failed to create sysfs attributes, %d\n" , err );
293
- return err ;
294
- }
295
-
296
- void tpm_sysfs_del_device (struct tpm_chip * chip )
297
- {
298
- /* The sysfs routines rely on an implicit tpm_try_get_ops, this
299
- * function is called before ops is null'd and the sysfs core
300
- * synchronizes this removal so that no callbacks are running or can
301
- * run again
287
+ /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del
288
+ * is called before ops is null'd and the sysfs core synchronizes this
289
+ * removal so that no callbacks are running or can run again
302
290
*/
303
- sysfs_remove_group (& chip -> dev .parent -> kobj , & tpm_dev_group );
291
+ WARN_ON (chip -> groups_cnt != 0 );
292
+ chip -> groups [chip -> groups_cnt ++ ] = & tpm_dev_group ;
304
293
}
0 commit comments