From a9b546cb0ff23190706b227bf4000640c457b557 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Wed, 31 May 2023 08:51:54 +0000 Subject: [PATCH] genprotimg: pv_img_set_control_flags: refactor code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce a function for setting the control flags. This makes it easier to add more control flags in the future. Reviewed-by: Steffen Eiden Signed-off-by: Marc Hartmayer Signed-off-by: Jan Höppner --- genprotimg/src/pv/pv_image.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/genprotimg/src/pv/pv_image.c b/genprotimg/src/pv/pv_image.c index bfc13eef..12219639 100644 --- a/genprotimg/src/pv/pv_image.c +++ b/genprotimg/src/pv/pv_image.c @@ -228,6 +228,14 @@ static gint pv_img_set_psw_addr(PvImage *img, const gchar *psw_addr_s, return 0; } +static void pv_img_set_control_flag(uint64_t *flags, const PvTristate option, const uint64_t flag) +{ + if (option == PV_TRUE) + *flags |= flag; + else if (option == PV_FALSE) + *flags &= ~flag; +} + static gint pv_img_set_control_flags(PvImage *img, const gchar *pcf_s, const gchar *scf_s, PvTristate allow_dump, @@ -235,6 +243,7 @@ static gint pv_img_set_control_flags(PvImage *img, const gchar *pcf_s, { uint64_t flags; + /* Set plain control flags */ if (pcf_s) { if (hex_str_toull(pcf_s, &flags, err) < 0) return -1; @@ -242,6 +251,11 @@ static gint pv_img_set_control_flags(PvImage *img, const gchar *pcf_s, img->pcf = flags; } + pv_img_set_control_flag(&img->pcf, allow_dump, PV_PCF_ALLOW_DUMPING); + pv_img_set_control_flag(&img->pcf, allow_pckmo, + PV_PCF_PCKM_ECC | PV_PCF_PCKMO_AES | PV_PCF_PCKMO_DEA_TDEA); + + /* Set secret control flags */ if (scf_s) { if (hex_str_toull(scf_s, &flags, err) < 0) return -1; @@ -249,16 +263,6 @@ static gint pv_img_set_control_flags(PvImage *img, const gchar *pcf_s, img->scf = flags; } - if (allow_dump == PV_TRUE) - img->pcf |= PV_PCF_ALLOW_DUMPING; - else if (allow_dump == PV_FALSE) - img->pcf &= ~PV_PCF_ALLOW_DUMPING; - - if (allow_pckmo == PV_TRUE) - img->pcf |= PV_PCF_PCKM_ECC | PV_PCF_PCKMO_AES | PV_PCF_PCKMO_DEA_TDEA; - else if (allow_pckmo == PV_FALSE) - img->pcf &= ~(PV_PCF_PCKM_ECC | PV_PCF_PCKMO_AES | PV_PCF_PCKMO_DEA_TDEA); - return 0; }