diff options
Diffstat (limited to 'drivers/char/tpm')
-rw-r--r-- | drivers/char/tpm/tpm.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 7b1f67d9f301..2035c15ffcce 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -255,7 +255,7 @@ static const u8 readpubek[] = { | |||
255 | 255 | ||
256 | static ssize_t show_pubek(struct device *dev, struct device_attribute *attr, char *buf) | 256 | static ssize_t show_pubek(struct device *dev, struct device_attribute *attr, char *buf) |
257 | { | 257 | { |
258 | u8 data[READ_PUBEK_RESULT_SIZE]; | 258 | u8 *data; |
259 | ssize_t len; | 259 | ssize_t len; |
260 | __be32 *native_val; | 260 | __be32 *native_val; |
261 | int i; | 261 | int i; |
@@ -266,12 +266,18 @@ static ssize_t show_pubek(struct device *dev, struct device_attribute *attr, cha | |||
266 | if (chip == NULL) | 266 | if (chip == NULL) |
267 | return -ENODEV; | 267 | return -ENODEV; |
268 | 268 | ||
269 | data = kmalloc(READ_PUBEK_RESULT_SIZE, GFP_KERNEL); | ||
270 | if (!data) | ||
271 | return -ENOMEM; | ||
272 | |||
269 | memcpy(data, readpubek, sizeof(readpubek)); | 273 | memcpy(data, readpubek, sizeof(readpubek)); |
270 | memset(data + sizeof(readpubek), 0, 20); /* zero nonce */ | 274 | memset(data + sizeof(readpubek), 0, 20); /* zero nonce */ |
271 | 275 | ||
272 | if ((len = tpm_transmit(chip, data, sizeof(data))) < | 276 | if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) < |
273 | READ_PUBEK_RESULT_SIZE) | 277 | READ_PUBEK_RESULT_SIZE) { |
274 | return len; | 278 | rc = len; |
279 | goto out; | ||
280 | } | ||
275 | 281 | ||
276 | /* | 282 | /* |
277 | ignore header 10 bytes | 283 | ignore header 10 bytes |
@@ -304,7 +310,10 @@ static ssize_t show_pubek(struct device *dev, struct device_attribute *attr, cha | |||
304 | if ((i + 1) % 16 == 0) | 310 | if ((i + 1) % 16 == 0) |
305 | str += sprintf(str, "\n"); | 311 | str += sprintf(str, "\n"); |
306 | } | 312 | } |
307 | return str - buf; | 313 | rc = str - buf; |
314 | out: | ||
315 | kfree(data); | ||
316 | return rc; | ||
308 | } | 317 | } |
309 | 318 | ||
310 | static DEVICE_ATTR(pubek, S_IRUGO, show_pubek, NULL); | 319 | static DEVICE_ATTR(pubek, S_IRUGO, show_pubek, NULL); |
@@ -330,7 +339,7 @@ static const u8 cap_manufacturer[] = { | |||
330 | 339 | ||
331 | static ssize_t show_caps(struct device *dev, struct device_attribute *attr, char *buf) | 340 | static ssize_t show_caps(struct device *dev, struct device_attribute *attr, char *buf) |
332 | { | 341 | { |
333 | u8 data[READ_PUBEK_RESULT_SIZE]; | 342 | u8 data[sizeof(cap_manufacturer)]; |
334 | ssize_t len; | 343 | ssize_t len; |
335 | char *str = buf; | 344 | char *str = buf; |
336 | 345 | ||