On 03.02.26 18:32, Stefan Berger wrote:


On 2/1/26 12:27 PM, Vladimir Sementsov-Ogievskiy wrote:
The code tends to include errno into error messages after
tpm_util_test_tpmdev() and tpm_emulator_ctrlcmd() calls.

Both has error paths, where errno is not set, examples:

tpm_emulator_ctrlcmd()
   qemu_chr_fe_write_all()
     qemu_chr_write()
       replay_char_write_event_load()
         ...
         *res = replay_get_dword();
         ...

tpm_util_test_tpmdev()
   tpm_util_test()
     tpm_util_request()
       ...
       if (n != requestlen) {
           return -EFAULT;
       }
       ...

Both doesn't document that they set errno.

Let's drop these explicit usage of errno. If we need this information,
it should be added to errp deeper in the stack.

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Reviewed-by: Stefan Berger <[email protected]>
Reviewed-by: Markus Armbruster <[email protected]>
---

@@ -539,8 +535,7 @@ static void tpm_emulator_cancel_cmd(TPMBackend *tb)
      /* FIXME: make the function non-blocking, or it may block a VCPU */
      if (tpm_emulator_ctrlcmd(tpm_emu, CMD_CANCEL_TPM_CMD, &res, 0,
                               sizeof(ptm_res), sizeof(res)) < 0) {
-        error_report("tpm-emulator: Could not cancel command: %s",
-                     strerror(errno));
+        error_report("tpm-emulator: Could not cancel command: %s");

Remove the '%s'.

I get these build errors now:

../backends/tpm/tpm_emulator.c: In function ‘tpm_emulator_cancel_cmd’:
../backends/tpm/tpm_emulator.c:538:22: error: format ‘%s’ expects a matching 
‘char *’ argument [-Werror=format=]
   538 |         error_report("tpm-emulator: Could not cancel command: %s");
       |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../backends/tpm/tpm_emulator.c: In function ‘tpm_emulator_post_load’:
../backends/tpm/tpm_emulator.c:958:9: error: unused variable ‘ret’ 
[-Werror=unused-variable]
   958 |     int ret;
       |         ^~~
cc1: all warnings being treated as errors


ashamed :/ I've checked compilation without tpm in config. Sorry, will resend.


--
Best regards,
Vladimir

Reply via email to