static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)

{

    int fd = -1;

    char *dev;

    char path[PATH_MAX];



    if (tpm_pt->options->cancel_path) {

        fd = qemu_open(tpm_pt->options->cancel_path, O_WRONLY);

        if (fd < 0) {

            error_report("Could not open TPM cancel path : %s",

                         strerror(errno));

        }

        return fd;

    }



    dev = strrchr(tpm_pt->tpm_dev, '/');

    if (dev) {

        dev++;

        if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel",

                     dev) < sizeof(path)) {

            fd = qemu_open(path, O_WRONLY);

            if (fd >= 0) {

                tpm_pt->options->cancel_path = g_strdup(path);

            } else {

                error_report("tpm_passthrough: Could not open TPM cancel "

                             "path %s : %s", path, strerror(errno));

            }

        }

    } else {

       error_report("tpm_passthrough: Bad TPM device path %s",

                    tpm_pt->tpm_dev);

    }



    return fd;

}

static int tpm_passthrough_open_sysfs_cancel(TPMPassthruState *tpm_pt)

{

    int fd = -1;

    char *dev;

    char path[PATH_MAX];



    if (tpm_pt->options->cancel_path) {

        fd = qemu_open(tpm_pt->options->cancel_path, O_WRONLY);

        if (fd < 0) {

            error_report("Could not open TPM cancel path : %s",

                         strerror(errno));

        }

        return fd;

    }



    dev = strrchr(tpm_pt->tpm_dev, '/');

    if (dev) {

        dev++;

        if (snprintf(path, sizeof(path), "/sys/class/misc/%s/device/cancel",

                     dev) < sizeof(path)) {

            fd = qemu_open(path, O_WRONLY);

            if (fd >= 0) {

                tpm_pt->options->cancel_path = g_strdup(path);

            } else {

                error_report("tpm_passthrough: Could not open TPM cancel "

                             "path %s : %s", path, strerror(errno));

            }

        }

    } else {

       error_report("tpm_passthrough: Bad TPM device path %s",

                    tpm_pt->tpm_dev);

    }



    return fd;

}

            if (fd >= 0) {                 tpm_pt->options->cancel_path = g_strdup(path);             } else {
static int FUNC_0(TPMPassthruState *VAR_0)

{

    int VAR_1 = -1;

    char *VAR_2;

    char VAR_3[PATH_MAX];



    if (VAR_0->options->cancel_path) {

        VAR_1 = qemu_open(VAR_0->options->cancel_path, O_WRONLY);

        if (VAR_1 < 0) {

            error_report("Could not open TPM cancel VAR_3 : %s",

                         strerror(errno));

        }

        return VAR_1;

    }



    VAR_2 = strrchr(VAR_0->tpm_dev, '/');

    if (VAR_2) {

        VAR_2++;

        if (snprintf(VAR_3, sizeof(VAR_3), "/sys/class/misc/%s/device/cancel",

                     VAR_2) < sizeof(VAR_3)) {

            VAR_1 = qemu_open(VAR_3, O_WRONLY);

            if (VAR_1 >= 0) {

                VAR_0->options->cancel_path = g_strdup(VAR_3);

            } else {

                error_report("tpm_passthrough: Could not open TPM cancel "

                             "VAR_3 %s : %s", VAR_3, strerror(errno));

            }

        }

    } else {

       error_report("tpm_passthrough: Bad TPM device VAR_3 %s",

                    VAR_0->tpm_dev);

    }



    return VAR_1;

}

static int FUNC_0(TPMPassthruState *VAR_0)
{ int VAR_1 = -1; char *VAR_2; char VAR_3[PATH_MAX]; if (VAR_0->options->cancel_path) { VAR_1 = qemu_open(VAR_0->options->cancel_path, O_WRONLY); if (VAR_1 < 0) { error_report("Could not open TPM cancel VAR_3 : %s",
strerror(errno)); } return VAR_1; } VAR_2 = strrchr(VAR_0->tpm_dev, '/'); if (VAR_2) { VAR_2++; if (snprintf(VAR_3, sizeof(VAR_3), "/sys/class/misc/%s/device/cancel",
VAR_2) < sizeof(VAR_3)) { VAR_1 = qemu_open(VAR_3, O_WRONLY); if (VAR_1 >= 0) { VAR_0->options->cancel_path = g_strdup(VAR_3); } else { error_report("tpm_passthrough: Could not open TPM cancel "
"VAR_3 %s : %s", VAR_3, strerror(errno)); } } } else { error_report("tpm_passthrough: Bad TPM device VAR_3 %s",
VAR_0->tpm_dev); } return VAR_1; }