From: Ahsan Atta <ahsan.atta@intel.com>
To: herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org, qat-linux@intel.com,
Ahsan Atta <ahsan.atta@intel.com>,
Giovanni Cabiddu <giovanni.cabiddu@intel.com>
Subject: [PATCH 2/2] crypto: qat - avoid redundant config list walks when adding a key
Date: Fri, 18 Sep 2026 13:41:12 +0100 [thread overview]
Message-ID: <20260918124112.537571-3-ahsan.atta@intel.com> (raw)
In-Reply-To: <20260918124112.537571-1-ahsan.atta@intel.com>
adf_cfg_add_key_value_param() now resolves the target section under
cfg->lock, but still calls adf_cfg_key_val_get(), which re-walks the
section list to find that same section and then walks param_head to
read the current value into a temporary buffer. If the value differs it
calls adf_cfg_keyval_remove(), which walks param_head a third time to
locate the entry that was already found.
Look up the existing entry once with adf_cfg_key_value_find() and act on
that pointer directly: free the new copy if the value is unchanged, or
unlink and free the old entry before adding the new one. This drops two
redundant list walks and the on-stack temp_val copy, and removes the now
unused adf_cfg_keyval_remove() helper. No functional change.
Signed-off-by: Ahsan Atta <ahsan.atta@intel.com>
Reviewed-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com>
---
drivers/crypto/intel/qat/qat_common/adf_cfg.c | 47 ++++++-------------
1 file changed, 15 insertions(+), 32 deletions(-)
diff --git a/drivers/crypto/intel/qat/qat_common/adf_cfg.c b/drivers/crypto/intel/qat/qat_common/adf_cfg.c
index e13db9ede0fa..e2ef5284abef 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_cfg.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_cfg.c
@@ -145,24 +145,6 @@ static void adf_cfg_keyval_add(struct adf_cfg_key_val *new,
list_add_tail(&new->list, &sec->param_head);
}
-static void adf_cfg_keyval_remove(const char *key, struct adf_cfg_section *sec)
-{
- struct list_head *head = &sec->param_head;
- struct list_head *list_ptr, *tmp;
-
- list_for_each_prev_safe(list_ptr, tmp, head) {
- struct adf_cfg_key_val *ptr =
- list_entry(list_ptr, struct adf_cfg_key_val, list);
-
- if (strncmp(ptr->key, key, sizeof(ptr->key)))
- continue;
-
- list_del(list_ptr);
- kfree(ptr);
- break;
- }
-}
-
static void adf_cfg_keyval_del_all(struct list_head *head)
{
struct list_head *list_ptr, *tmp;
@@ -271,9 +253,8 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
enum adf_cfg_val_type type)
{
struct adf_cfg_device_data *cfg = accel_dev->cfg;
+ struct adf_cfg_key_val *key_val, *existing;
struct adf_cfg_section *section;
- struct adf_cfg_key_val *key_val;
- char temp_val[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
int ret = 0;
key_val = kzalloc_obj(*key_val);
@@ -295,14 +276,6 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
}
key_val->type = type;
- /* Add the key-value pair as below policy:
- * 1. if the key doesn't exist, add it;
- * 2. if the key already exists with a different value then update it
- * to the new value (the key is deleted and the newly created
- * key_val containing the new value is added to the database);
- * 3. if the key exists with the same value, then return without doing
- * anything (the newly created key_val is freed).
- */
down_write(&cfg->lock);
section = adf_cfg_sec_find(accel_dev, section_name);
@@ -312,13 +285,23 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
goto unlock;
}
- if (!adf_cfg_key_val_get(accel_dev, section_name, key, temp_val)) {
- if (strncmp(temp_val, key_val->val, sizeof(temp_val))) {
- adf_cfg_keyval_remove(key, section);
- } else {
+ /*
+ * Add the key-value pair as below policy:
+ * 1. if the key doesn't exist, add it;
+ * 2. if the key already exists with a different value then update it
+ * to the new value (the key is deleted and the newly created
+ * key_val containing the new value is added to the database);
+ * 3. if the key exists with the same value, then return without doing
+ * anything (the newly created key_val is freed).
+ */
+ existing = adf_cfg_key_value_find(section, key);
+ if (existing) {
+ if (!strncmp(existing->val, key_val->val, sizeof(existing->val))) {
kfree(key_val);
goto unlock;
}
+ list_del(&existing->list);
+ kfree(existing);
}
adf_cfg_keyval_add(key_val, section);
--
2.50.1
next prev parent reply other threads:[~2026-09-18 12:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 12:41 [PATCH 0/2] crypto: qat - fix config table locking Ahsan Atta
2026-09-18 12:41 ` [PATCH 1/2] crypto: qat - hold cfg->lock when accessing config sections Ahsan Atta
2026-09-18 12:41 ` Ahsan Atta [this message]
2026-09-23 8:51 ` [PATCH 0/2] crypto: qat - fix config table locking Herbert Xu
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=20260918124112.537571-3-ahsan.atta@intel.com \
--to=ahsan.atta@intel.com \
--cc=giovanni.cabiddu@intel.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=qat-linux@intel.com \
/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