Commit 92bf269f authored by Giovanni Cabiddu's avatar Giovanni Cabiddu Committed by Herbert Xu
Browse files

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: default avatarGiovanni Cabiddu <giovanni.cabiddu@intel.com>
Reviewed-by: default avatarAdam Guerin <adam.guerin@intel.com>
Reviewed-by: default avatarFiona Trahe <fiona.trahe@intel.com>
Reviewed-by: default avatarWojciech Ziemba <wojciech.ziemba@intel.com>
Reviewed-by: default avatarVladis Dronov <vdronov@redhat.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5ee52118
Loading
Loading
Loading
Loading
+40 −1
Original line number Diff line number Diff line
@@ -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);