@@ -39,25 +39,24 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
39
39
{
40
40
struct tpm_buf tpm_buf ;
41
41
struct tpm_readpubek_out * out ;
42
- ssize_t rc ;
43
42
int i ;
44
43
char * str = buf ;
45
44
struct tpm_chip * chip = to_tpm_chip (dev );
46
45
char anti_replay [20 ];
47
46
48
47
memset (& anti_replay , 0 , sizeof (anti_replay ));
49
48
50
- if (tpm_buf_init ( & tpm_buf , TPM_TAG_RQU_COMMAND , TPM_ORD_READPUBEK ))
49
+ if (tpm_try_get_ops ( chip ))
51
50
return 0 ;
52
51
52
+ if (tpm_buf_init (& tpm_buf , TPM_TAG_RQU_COMMAND , TPM_ORD_READPUBEK ))
53
+ goto out_ops ;
54
+
53
55
tpm_buf_append (& tpm_buf , anti_replay , sizeof (anti_replay ));
54
56
55
- rc = tpm_transmit_cmd (chip , & tpm_buf , READ_PUBEK_RESULT_MIN_BODY_SIZE ,
56
- 0 , "attempting to read the PUBEK" );
57
- if (rc ) {
58
- tpm_buf_destroy (& tpm_buf );
59
- return 0 ;
60
- }
57
+ if (tpm_transmit_cmd (chip , & tpm_buf , READ_PUBEK_RESULT_MIN_BODY_SIZE ,
58
+ 0 , "attempting to read the PUBEK" ))
59
+ goto out_buf ;
61
60
62
61
out = (struct tpm_readpubek_out * )& tpm_buf .data [10 ];
63
62
str +=
@@ -88,9 +87,11 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
88
87
str += sprintf (str , "\n" );
89
88
}
90
89
91
- rc = str - buf ;
90
+ out_buf :
92
91
tpm_buf_destroy (& tpm_buf );
93
- return rc ;
92
+ out_ops :
93
+ tpm_put_ops (chip );
94
+ return str - buf ;
94
95
}
95
96
static DEVICE_ATTR_RO (pubek );
96
97
@@ -103,10 +104,15 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
103
104
char * str = buf ;
104
105
struct tpm_chip * chip = to_tpm_chip (dev );
105
106
107
+ if (tpm_try_get_ops (chip ))
108
+ return 0 ;
109
+
106
110
if (tpm1_getcap (chip , TPM_CAP_PROP_PCR , & cap ,
107
111
"attempting to determine the number of PCRS" ,
108
- sizeof (cap .num_pcrs )))
112
+ sizeof (cap .num_pcrs ))) {
113
+ tpm_put_ops (chip );
109
114
return 0 ;
115
+ }
110
116
111
117
num_pcrs = be32_to_cpu (cap .num_pcrs );
112
118
for (i = 0 ; i < num_pcrs ; i ++ ) {
@@ -119,74 +125,95 @@ static ssize_t pcrs_show(struct device *dev, struct device_attribute *attr,
119
125
str += sprintf (str , "%02X " , digest [j ]);
120
126
str += sprintf (str , "\n" );
121
127
}
128
+ tpm_put_ops (chip );
122
129
return str - buf ;
123
130
}
124
131
static DEVICE_ATTR_RO (pcrs );
125
132
126
133
static ssize_t enabled_show (struct device * dev , struct device_attribute * attr ,
127
134
char * buf )
128
135
{
136
+ struct tpm_chip * chip = to_tpm_chip (dev );
137
+ ssize_t rc = 0 ;
129
138
cap_t cap ;
130
- ssize_t rc ;
131
139
132
- rc = tpm1_getcap (to_tpm_chip (dev ), TPM_CAP_FLAG_PERM , & cap ,
133
- "attempting to determine the permanent enabled state" ,
134
- sizeof (cap .perm_flags ));
135
- if (rc )
140
+ if (tpm_try_get_ops (chip ))
136
141
return 0 ;
137
142
143
+ if (tpm1_getcap (chip , TPM_CAP_FLAG_PERM , & cap ,
144
+ "attempting to determine the permanent enabled state" ,
145
+ sizeof (cap .perm_flags )))
146
+ goto out_ops ;
147
+
138
148
rc = sprintf (buf , "%d\n" , !cap .perm_flags .disable );
149
+ out_ops :
150
+ tpm_put_ops (chip );
139
151
return rc ;
140
152
}
141
153
static DEVICE_ATTR_RO (enabled );
142
154
143
155
static ssize_t active_show (struct device * dev , struct device_attribute * attr ,
144
156
char * buf )
145
157
{
158
+ struct tpm_chip * chip = to_tpm_chip (dev );
159
+ ssize_t rc = 0 ;
146
160
cap_t cap ;
147
- ssize_t rc ;
148
161
149
- rc = tpm1_getcap (to_tpm_chip (dev ), TPM_CAP_FLAG_PERM , & cap ,
150
- "attempting to determine the permanent active state" ,
151
- sizeof (cap .perm_flags ));
152
- if (rc )
162
+ if (tpm_try_get_ops (chip ))
153
163
return 0 ;
154
164
165
+ if (tpm1_getcap (chip , TPM_CAP_FLAG_PERM , & cap ,
166
+ "attempting to determine the permanent active state" ,
167
+ sizeof (cap .perm_flags )))
168
+ goto out_ops ;
169
+
155
170
rc = sprintf (buf , "%d\n" , !cap .perm_flags .deactivated );
171
+ out_ops :
172
+ tpm_put_ops (chip );
156
173
return rc ;
157
174
}
158
175
static DEVICE_ATTR_RO (active );
159
176
160
177
static ssize_t owned_show (struct device * dev , struct device_attribute * attr ,
161
178
char * buf )
162
179
{
180
+ struct tpm_chip * chip = to_tpm_chip (dev );
181
+ ssize_t rc = 0 ;
163
182
cap_t cap ;
164
- ssize_t rc ;
165
183
166
- rc = tpm1_getcap (to_tpm_chip (dev ), TPM_CAP_PROP_OWNER , & cap ,
167
- "attempting to determine the owner state" ,
168
- sizeof (cap .owned ));
169
- if (rc )
184
+ if (tpm_try_get_ops (chip ))
170
185
return 0 ;
171
186
187
+ if (tpm1_getcap (to_tpm_chip (dev ), TPM_CAP_PROP_OWNER , & cap ,
188
+ "attempting to determine the owner state" ,
189
+ sizeof (cap .owned )))
190
+ goto out_ops ;
191
+
172
192
rc = sprintf (buf , "%d\n" , cap .owned );
193
+ out_ops :
194
+ tpm_put_ops (chip );
173
195
return rc ;
174
196
}
175
197
static DEVICE_ATTR_RO (owned );
176
198
177
199
static ssize_t temp_deactivated_show (struct device * dev ,
178
200
struct device_attribute * attr , char * buf )
179
201
{
202
+ struct tpm_chip * chip = to_tpm_chip (dev );
203
+ ssize_t rc = 0 ;
180
204
cap_t cap ;
181
- ssize_t rc ;
182
205
183
- rc = tpm1_getcap (to_tpm_chip (dev ), TPM_CAP_FLAG_VOL , & cap ,
184
- "attempting to determine the temporary state" ,
185
- sizeof (cap .stclear_flags ));
186
- if (rc )
206
+ if (tpm_try_get_ops (chip ))
187
207
return 0 ;
188
208
209
+ if (tpm1_getcap (to_tpm_chip (dev ), TPM_CAP_FLAG_VOL , & cap ,
210
+ "attempting to determine the temporary state" ,
211
+ sizeof (cap .stclear_flags )))
212
+ goto out_ops ;
213
+
189
214
rc = sprintf (buf , "%d\n" , cap .stclear_flags .deactivated );
215
+ out_ops :
216
+ tpm_put_ops (chip );
190
217
return rc ;
191
218
}
192
219
static DEVICE_ATTR_RO (temp_deactivated );
@@ -195,15 +222,18 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
195
222
char * buf )
196
223
{
197
224
struct tpm_chip * chip = to_tpm_chip (dev );
198
- cap_t cap ;
199
- ssize_t rc ;
225
+ ssize_t rc = 0 ;
200
226
char * str = buf ;
227
+ cap_t cap ;
201
228
202
- rc = tpm1_getcap (chip , TPM_CAP_PROP_MANUFACTURER , & cap ,
203
- "attempting to determine the manufacturer" ,
204
- sizeof (cap .manufacturer_id ));
205
- if (rc )
229
+ if (tpm_try_get_ops (chip ))
206
230
return 0 ;
231
+
232
+ if (tpm1_getcap (chip , TPM_CAP_PROP_MANUFACTURER , & cap ,
233
+ "attempting to determine the manufacturer" ,
234
+ sizeof (cap .manufacturer_id )))
235
+ goto out_ops ;
236
+
207
237
str += sprintf (str , "Manufacturer: 0x%x\n" ,
208
238
be32_to_cpu (cap .manufacturer_id ));
209
239
@@ -220,31 +250,34 @@ static ssize_t caps_show(struct device *dev, struct device_attribute *attr,
220
250
cap .tpm_version_1_2 .revMinor );
221
251
} else {
222
252
/* Otherwise just use TPM_STRUCT_VER */
223
- rc = tpm1_getcap (chip , TPM_CAP_VERSION_1_1 , & cap ,
224
- "attempting to determine the 1.1 version" ,
225
- sizeof (cap .tpm_version ));
226
- if (rc )
227
- return 0 ;
253
+ if (tpm1_getcap (chip , TPM_CAP_VERSION_1_1 , & cap ,
254
+ "attempting to determine the 1.1 version" ,
255
+ sizeof (cap .tpm_version )))
256
+ goto out_ops ;
228
257
str += sprintf (str ,
229
258
"TCG version: %d.%d\nFirmware version: %d.%d\n" ,
230
259
cap .tpm_version .Major ,
231
260
cap .tpm_version .Minor ,
232
261
cap .tpm_version .revMajor ,
233
262
cap .tpm_version .revMinor );
234
263
}
235
-
236
- return str - buf ;
264
+ rc = str - buf ;
265
+ out_ops :
266
+ tpm_put_ops (chip );
267
+ return rc ;
237
268
}
238
269
static DEVICE_ATTR_RO (caps );
239
270
240
271
static ssize_t cancel_store (struct device * dev , struct device_attribute * attr ,
241
272
const char * buf , size_t count )
242
273
{
243
274
struct tpm_chip * chip = to_tpm_chip (dev );
244
- if (chip == NULL )
275
+
276
+ if (tpm_try_get_ops (chip ))
245
277
return 0 ;
246
278
247
279
chip -> ops -> cancel (chip );
280
+ tpm_put_ops (chip );
248
281
return count ;
249
282
}
250
283
static DEVICE_ATTR_WO (cancel );
0 commit comments