.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2015, 2016 IBM Corporation |
---|
3 | 4 | * Copyright (C) 2016 Intel Corporation |
---|
.. | .. |
---|
7 | 8 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
---|
8 | 9 | * |
---|
9 | 10 | * Device driver for vTPM (vTPM proxy driver) |
---|
10 | | - * |
---|
11 | | - * This program is free software; you can redistribute it and/or |
---|
12 | | - * modify it under the terms of the GNU General Public License as |
---|
13 | | - * published by the Free Software Foundation, version 2 of the |
---|
14 | | - * License. |
---|
15 | | - * |
---|
16 | 11 | */ |
---|
17 | 12 | |
---|
18 | 13 | #include <linux/types.h> |
---|
.. | .. |
---|
303 | 298 | static int vtpm_proxy_is_driver_command(struct tpm_chip *chip, |
---|
304 | 299 | u8 *buf, size_t count) |
---|
305 | 300 | { |
---|
306 | | - struct tpm_input_header *hdr = (struct tpm_input_header *)buf; |
---|
| 301 | + struct tpm_header *hdr = (struct tpm_header *)buf; |
---|
307 | 302 | |
---|
308 | | - if (count < sizeof(struct tpm_input_header)) |
---|
| 303 | + if (count < sizeof(struct tpm_header)) |
---|
309 | 304 | return 0; |
---|
310 | 305 | |
---|
311 | 306 | if (chip->flags & TPM_CHIP_FLAG_TPM2) { |
---|
.. | .. |
---|
401 | 396 | { |
---|
402 | 397 | struct tpm_buf buf; |
---|
403 | 398 | int rc; |
---|
404 | | - const struct tpm_output_header *header; |
---|
| 399 | + const struct tpm_header *header; |
---|
405 | 400 | struct proxy_dev *proxy_dev = dev_get_drvdata(&chip->dev); |
---|
406 | 401 | |
---|
407 | 402 | if (chip->flags & TPM_CHIP_FLAG_TPM2) |
---|
.. | .. |
---|
416 | 411 | |
---|
417 | 412 | proxy_dev->state |= STATE_DRIVER_COMMAND; |
---|
418 | 413 | |
---|
419 | | - rc = tpm_transmit_cmd(chip, NULL, buf.data, tpm_buf_length(&buf), 0, |
---|
420 | | - TPM_TRANSMIT_NESTED, |
---|
421 | | - "attempting to set locality"); |
---|
| 414 | + rc = tpm_transmit_cmd(chip, &buf, 0, "attempting to set locality"); |
---|
422 | 415 | |
---|
423 | 416 | proxy_dev->state &= ~STATE_DRIVER_COMMAND; |
---|
424 | 417 | |
---|
.. | .. |
---|
427 | 420 | goto out; |
---|
428 | 421 | } |
---|
429 | 422 | |
---|
430 | | - header = (const struct tpm_output_header *)buf.data; |
---|
| 423 | + header = (const struct tpm_header *)buf.data; |
---|
431 | 424 | rc = be32_to_cpu(header->return_code); |
---|
432 | 425 | if (rc) |
---|
433 | 426 | locality = -1; |
---|
.. | .. |
---|
677 | 670 | } |
---|
678 | 671 | } |
---|
679 | 672 | |
---|
680 | | -#ifdef CONFIG_COMPAT |
---|
681 | | -static long vtpmx_fops_compat_ioctl(struct file *f, unsigned int ioctl, |
---|
682 | | - unsigned long arg) |
---|
683 | | -{ |
---|
684 | | - return vtpmx_fops_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); |
---|
685 | | -} |
---|
686 | | -#endif |
---|
687 | | - |
---|
688 | 673 | static const struct file_operations vtpmx_fops = { |
---|
689 | 674 | .owner = THIS_MODULE, |
---|
690 | 675 | .unlocked_ioctl = vtpmx_fops_ioctl, |
---|
691 | | -#ifdef CONFIG_COMPAT |
---|
692 | | - .compat_ioctl = vtpmx_fops_compat_ioctl, |
---|
693 | | -#endif |
---|
| 676 | + .compat_ioctl = compat_ptr_ioctl, |
---|
694 | 677 | .llseek = noop_llseek, |
---|
695 | 678 | }; |
---|
696 | 679 | |
---|
.. | .. |
---|
700 | 683 | .fops = &vtpmx_fops, |
---|
701 | 684 | }; |
---|
702 | 685 | |
---|
703 | | -static int vtpmx_init(void) |
---|
704 | | -{ |
---|
705 | | - return misc_register(&vtpmx_miscdev); |
---|
706 | | -} |
---|
707 | | - |
---|
708 | | -static void vtpmx_cleanup(void) |
---|
709 | | -{ |
---|
710 | | - misc_deregister(&vtpmx_miscdev); |
---|
711 | | -} |
---|
712 | | - |
---|
713 | 686 | static int __init vtpm_module_init(void) |
---|
714 | 687 | { |
---|
715 | 688 | int rc; |
---|
716 | 689 | |
---|
717 | | - rc = vtpmx_init(); |
---|
718 | | - if (rc) { |
---|
719 | | - pr_err("couldn't create vtpmx device\n"); |
---|
720 | | - return rc; |
---|
721 | | - } |
---|
722 | | - |
---|
723 | 690 | workqueue = create_workqueue("tpm-vtpm"); |
---|
724 | 691 | if (!workqueue) { |
---|
725 | 692 | pr_err("couldn't create workqueue\n"); |
---|
726 | | - rc = -ENOMEM; |
---|
727 | | - goto err_vtpmx_cleanup; |
---|
| 693 | + return -ENOMEM; |
---|
728 | 694 | } |
---|
729 | 695 | |
---|
730 | | - return 0; |
---|
731 | | - |
---|
732 | | -err_vtpmx_cleanup: |
---|
733 | | - vtpmx_cleanup(); |
---|
| 696 | + rc = misc_register(&vtpmx_miscdev); |
---|
| 697 | + if (rc) { |
---|
| 698 | + pr_err("couldn't create vtpmx device\n"); |
---|
| 699 | + destroy_workqueue(workqueue); |
---|
| 700 | + } |
---|
734 | 701 | |
---|
735 | 702 | return rc; |
---|
736 | 703 | } |
---|
.. | .. |
---|
738 | 705 | static void __exit vtpm_module_exit(void) |
---|
739 | 706 | { |
---|
740 | 707 | destroy_workqueue(workqueue); |
---|
741 | | - vtpmx_cleanup(); |
---|
| 708 | + misc_deregister(&vtpmx_miscdev); |
---|
742 | 709 | } |
---|
743 | 710 | |
---|
744 | 711 | module_init(vtpm_module_init); |
---|