qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 4/6] crypto/tlscredspsk: Access QOM parent via QCRYPTO_TLS_CREDS() macro
Date: Mon, 10 Feb 2025 17:21:33 +0100	[thread overview]
Message-ID: <20250210162135.14123-5-philmd@linaro.org> (raw)
In-Reply-To: <20250210162135.14123-1-philmd@linaro.org>

Prefer accessing QCryptoTLSCredsPSK's QOM parent via the
QCRYPTO_TLS_CREDS() cast macro, rather than parent_obj.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 crypto/tlscredspsk.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/crypto/tlscredspsk.c b/crypto/tlscredspsk.c
index 033f1d4287b..69769bc0b28 100644
--- a/crypto/tlscredspsk.c
+++ b/crypto/tlscredspsk.c
@@ -71,6 +71,7 @@ static int
 qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *psk_creds,
                            Error **errp)
 {
+    QCryptoTLSCreds *creds = QCRYPTO_TLS_CREDS(psk_creds);
     g_autofree char *pskfile = NULL;
     g_autofree char *dhparams = NULL;
     const char *username;
@@ -79,18 +80,18 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *psk_creds,
     gnutls_datum_t key = { .data = NULL };
 
     trace_qcrypto_tls_creds_psk_load(psk_creds,
-            psk_creds->parent_obj.dir ? psk_creds->parent_obj.dir : "<nodir>");
+                                     creds->dir ? creds->dir : "<nodir>");
 
-    if (psk_creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
+    if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_SERVER) {
         if (psk_creds->username) {
             error_setg(errp, "username should not be set when endpoint=server");
             goto cleanup;
         }
 
-        if (qcrypto_tls_creds_get_path(&psk_creds->parent_obj,
+        if (qcrypto_tls_creds_get_path(creds,
                                        QCRYPTO_TLS_CREDS_DH_PARAMS,
                                        false, &dhparams, errp) < 0 ||
-            qcrypto_tls_creds_get_path(&psk_creds->parent_obj,
+            qcrypto_tls_creds_get_path(creds,
                                        QCRYPTO_TLS_CREDS_PSKFILE,
                                        true, &pskfile, errp) < 0) {
             goto cleanup;
@@ -103,8 +104,8 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *psk_creds,
             goto cleanup;
         }
 
-        if (qcrypto_tls_creds_get_dh_params_file(&psk_creds->parent_obj, dhparams,
-                                                 &psk_creds->parent_obj.dh_params,
+        if (qcrypto_tls_creds_get_dh_params_file(creds, dhparams,
+                                                 &creds->dh_params,
                                                  errp) < 0) {
             goto cleanup;
         }
@@ -116,9 +117,9 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *psk_creds,
             goto cleanup;
         }
         gnutls_psk_set_server_dh_params(psk_creds->data.server,
-                                        psk_creds->parent_obj.dh_params);
+                                        creds->dh_params);
     } else {
-        if (qcrypto_tls_creds_get_path(&psk_creds->parent_obj,
+        if (qcrypto_tls_creds_get_path(creds,
                                        QCRYPTO_TLS_CREDS_PSKFILE,
                                        true, &pskfile, errp) < 0) {
             goto cleanup;
@@ -159,7 +160,9 @@ qcrypto_tls_creds_psk_load(QCryptoTLSCredsPSK *psk_creds,
 static void
 qcrypto_tls_creds_psk_unload(QCryptoTLSCredsPSK *psk_creds)
 {
-    if (psk_creds->parent_obj.endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) {
+    QCryptoTLSCreds *creds = QCRYPTO_TLS_CREDS(psk_creds);
+
+    if (creds->endpoint == QCRYPTO_TLS_CREDS_ENDPOINT_CLIENT) {
         if (psk_creds->data.client) {
             gnutls_psk_free_client_credentials(psk_creds->data.client);
             psk_creds->data.client = NULL;
@@ -170,9 +173,9 @@ qcrypto_tls_creds_psk_unload(QCryptoTLSCredsPSK *psk_creds)
             psk_creds->data.server = NULL;
         }
     }
-    if (psk_creds->parent_obj.dh_params) {
-        gnutls_dh_params_deinit(psk_creds->parent_obj.dh_params);
-        psk_creds->parent_obj.dh_params = NULL;
+    if (creds->dh_params) {
+        gnutls_dh_params_deinit(creds->dh_params);
+        creds->dh_params = NULL;
     }
 }
 
-- 
2.47.1



  parent reply	other threads:[~2025-02-10 16:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-10 16:21 [PATCH 0/6] crypto/tlscreds: QOM style cleanups Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 1/6] crypto/tlscredsx509: Rename 'creds' -> 'x509_creds' Philippe Mathieu-Daudé
2025-02-10 16:32   ` Daniel P. Berrangé
2025-02-10 16:21 ` [PATCH 2/6] crypto/tlscredsx509: Access QOM parent via QCRYPTO_TLS_CREDS() macro Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 3/6] crypto/tlscredspsk: Rename 'creds' -> 'psk_creds' Philippe Mathieu-Daudé
2025-02-10 16:21 ` Philippe Mathieu-Daudé [this message]
2025-02-10 16:21 ` [PATCH 5/6] crypto/tlscredsanon: Rename 'creds' -> 'anon_creds' Philippe Mathieu-Daudé
2025-02-10 16:21 ` [PATCH 6/6] crypto/tlscredsanon: Access QOM parent via QCRYPTO_TLS_CREDS() macro Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250210162135.14123-5-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).