Skip to content

Commit 92bf269

Browse files
gcabidduherbertx
authored andcommitted
crypto: qat - change behaviour of adf_cfg_add_key_value_param()
The function adf_cfg_add_key_value_param() allows to insert duplicates entries in the key value store of the driver. Change the behaviour of that function to the following policy: - if the key doesn't exist, add it; - if the key already exists with a different value, then delete it and replace it with a new one containing the new value; - if the key exists with the same value, then return without doing anything. The behaviour of this function has been changed in order to easily update key-values in the driver database. In particular this is required to update the value of the ServiceEnables key used to change the service loaded on a device. Signed-off-by: Giovanni Cabiddu <giovanni.cabiddu@intel.com> Reviewed-by: Adam Guerin <adam.guerin@intel.com> Reviewed-by: Fiona Trahe <fiona.trahe@intel.com> Reviewed-by: Wojciech Ziemba <wojciech.ziemba@intel.com> Reviewed-by: Vladis Dronov <vdronov@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 5ee5211 commit 92bf269

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

drivers/crypto/qat/qat_common/adf_cfg.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ static void adf_cfg_keyval_add(struct adf_cfg_key_val *new,
128128
list_add_tail(&new->list, &sec->param_head);
129129
}
130130

131+
static void adf_cfg_keyval_remove(const char *key, struct adf_cfg_section *sec)
132+
{
133+
struct list_head *head = &sec->param_head;
134+
struct list_head *list_ptr, *tmp;
135+
136+
list_for_each_prev_safe(list_ptr, tmp, head) {
137+
struct adf_cfg_key_val *ptr =
138+
list_entry(list_ptr, struct adf_cfg_key_val, list);
139+
140+
if (strncmp(ptr->key, key, sizeof(ptr->key)))
141+
continue;
142+
143+
list_del(list_ptr);
144+
kfree(ptr);
145+
break;
146+
}
147+
}
148+
131149
static void adf_cfg_keyval_del_all(struct list_head *head)
132150
{
133151
struct list_head *list_ptr, *tmp;
@@ -208,7 +226,8 @@ static int adf_cfg_key_val_get(struct adf_accel_dev *accel_dev,
208226
* @type: Type - string, int or address
209227
*
210228
* Function adds configuration key - value entry in the appropriate section
211-
* in the given acceleration device
229+
* in the given acceleration device. If the key exists already, the value
230+
* is updated.
212231
* To be used by QAT device specific drivers.
213232
*
214233
* Return: 0 on success, error code otherwise.
@@ -222,6 +241,8 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
222241
struct adf_cfg_key_val *key_val;
223242
struct adf_cfg_section *section = adf_cfg_sec_find(accel_dev,
224243
section_name);
244+
char temp_val[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
245+
225246
if (!section)
226247
return -EFAULT;
227248

@@ -246,6 +267,24 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
246267
return -EINVAL;
247268
}
248269
key_val->type = type;
270+
271+
/* Add the key-value pair as below policy:
272+
* 1. if the key doesn't exist, add it;
273+
* 2. if the key already exists with a different value then update it
274+
* to the new value (the key is deleted and the newly created
275+
* key_val containing the new value is added to the database);
276+
* 3. if the key exists with the same value, then return without doing
277+
* anything (the newly created key_val is freed).
278+
*/
279+
if (!adf_cfg_key_val_get(accel_dev, section_name, key, temp_val)) {
280+
if (strncmp(temp_val, key_val->val, sizeof(temp_val))) {
281+
adf_cfg_keyval_remove(key, section);
282+
} else {
283+
kfree(key_val);
284+
return 0;
285+
}
286+
}
287+
249288
down_write(&cfg->lock);
250289
adf_cfg_keyval_add(key_val, section);
251290
up_write(&cfg->lock);

0 commit comments

Comments
 (0)