[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v6 5/8] tmp backend: Add new api to read backend
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v6 5/8] tmp backend: Add new api to read backend TpmInfo |
Date: |
Tue, 18 Jul 2017 09:28:09 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 |
On 07/18/2017 05:39 AM, Marc-André Lureau wrote:
> Hi
>
> On Tue, Jul 18, 2017 at 1:49 AM, Amarnath Valluri
> <address@hidden> wrote:
>> TPM configuration options are backend implementation details and shall not be
>> part of base TPMBackend object, and these shall not be accessed directly
>> outside
>> of the class, hence added a new interface method, get_tpm_options() to
>> TPMDriverOps., which shall be implemented by the derived classes to return
>> configured tpm options.
>>
> One usually prefer to have the true case first.
>
>> + } else {
>> + tpm_pt->ops->has_path = true;
>> }
>>
>> + tpm_pt->ops->path = g_strdup(value);
>
> Interestingly, ops->path will be set even if ops->has_path = false. I
> am not sure the visitors will handle that case properly (for visit or
> dealloc etc). Could you set ops->has_path = true uncondtionnally?
tmp_pt->opt->path is ignored if has_path is false; if it is assigned to
malloc'd memory, then you leak that memory when freeing tpm_pt.
>
>
>
>> tpm_pt->tpm_dev = g_strdup(value);
>>
>> - tb->path = g_strdup(tpm_pt->tpm_dev);
>> -
>> tpm_pt->tpm_fd = qemu_open(tpm_pt->tpm_dev, O_RDWR);
>> if (tpm_pt->tpm_fd < 0) {
>> error_report("Cannot access TPM device using '%s': %s",
>> @@ -382,8 +389,8 @@ static int tpm_passthrough_handle_device_opts(QemuOpts
>> *opts, TPMBackend *tb)
>> tpm_pt->tpm_fd = -1;
>>
>> err_free_parameters:
>> - g_free(tb->path);
>> - tb->path = NULL;
>> + g_free(tpm_pt->ops->path);
>> + tpm_pt->ops->path = NULL;
>>
>
> Shouldn't it also free cancel_path?
Even better, don't open-code it. Use
qapi_free_TPMPassthruState(tpm_pt), so that the generated code gets
everything for you.
>> +static TpmTypeOptions *tpm_passthrough_get_tpm_options(TPMBackend *tb)
>> +{
>> + TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
>> + TpmTypeOptions *ops = NULL;
>> + TPMPassthroughOptions *pops = NULL;
>> +
>> + pops = g_new0(TPMPassthroughOptions, 1);
>> + if (!pops) {
>> + return NULL;
>> + }
>> +
>
> There is no check for small allocation failure elsewhere, I would drop that.
In fact, g_new0() can't fail (if you're out of memory, it abort()s
instead of returning NULL). Coverity will warn about dead code.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH v6 0/8] Provide support for the software TPM emulator, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 1/8] tpm-backend: Remove unneeded member variable from backend class, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 4/8] tpm-backend: Made few interface methods optional, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 5/8] tmp backend: Add new api to read backend TpmInfo, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 3/8] tpm-backend: Initialize and free data members in it's own methods, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 2/8] tpm-backend: Move thread handling inside TPMBackend, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 6/8] tpm-backend: Move realloc_buffer() implementation to tpm-tis model, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 7/8] tpm-passthrough: move reusable code to utils, Amarnath Valluri, 2017/07/18
- [Qemu-devel] [PATCH v6 8/8] tpm: Added support for TPM emulator, Amarnath Valluri, 2017/07/18