mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 17:08:10 +00:00
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>
This commit is contained in:
parent
5ee52118ac
commit
92bf269fbf
1 changed files with 40 additions and 1 deletions
|
@ -128,6 +128,24 @@ 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;
|
||||
|
@ -208,7 +226,8 @@ static int adf_cfg_key_val_get(struct adf_accel_dev *accel_dev,
|
|||
* @type: Type - string, int or address
|
||||
*
|
||||
* Function adds configuration key - value entry in the appropriate section
|
||||
* in the given acceleration device
|
||||
* in the given acceleration device. If the key exists already, the value
|
||||
* is updated.
|
||||
* To be used by QAT device specific drivers.
|
||||
*
|
||||
* Return: 0 on success, error code otherwise.
|
||||
|
@ -222,6 +241,8 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
|
|||
struct adf_cfg_key_val *key_val;
|
||||
struct adf_cfg_section *section = adf_cfg_sec_find(accel_dev,
|
||||
section_name);
|
||||
char temp_val[ADF_CFG_MAX_VAL_LEN_IN_BYTES];
|
||||
|
||||
if (!section)
|
||||
return -EFAULT;
|
||||
|
||||
|
@ -246,6 +267,24 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,
|
|||
return -EINVAL;
|
||||
}
|
||||
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).
|
||||
*/
|
||||
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 {
|
||||
kfree(key_val);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
down_write(&cfg->lock);
|
||||
adf_cfg_keyval_add(key_val, section);
|
||||
up_write(&cfg->lock);
|
||||
|
|
Loading…
Reference in a new issue