Commit dc2c6322 authored by Geliang Tang's avatar Geliang Tang Committed by Herbert Xu

crypto: qat - use list_for_each_entry*

Use list_for_each_entry*() instead of list_for_each*() to simplify
the code.
Signed-off-by: default avatarGeliang Tang <geliangtang@163.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent e4ae86e2
...@@ -255,12 +255,9 @@ static int adf_ctl_ioctl_dev_config(struct file *fp, unsigned int cmd, ...@@ -255,12 +255,9 @@ static int adf_ctl_ioctl_dev_config(struct file *fp, unsigned int cmd,
static int adf_ctl_is_device_in_use(int id) static int adf_ctl_is_device_in_use(int id)
{ {
struct list_head *itr, *head = adf_devmgr_get_head(); struct adf_accel_dev *dev;
list_for_each(itr, head) {
struct adf_accel_dev *dev =
list_entry(itr, struct adf_accel_dev, list);
list_for_each_entry(dev, adf_devmgr_get_head(), list) {
if (id == dev->accel_id || id == ADF_CFG_ALL_DEVICES) { if (id == dev->accel_id || id == ADF_CFG_ALL_DEVICES) {
if (adf_devmgr_in_reset(dev) || adf_dev_in_use(dev)) { if (adf_devmgr_in_reset(dev) || adf_dev_in_use(dev)) {
dev_info(&GET_DEV(dev), dev_info(&GET_DEV(dev),
...@@ -275,12 +272,10 @@ static int adf_ctl_is_device_in_use(int id) ...@@ -275,12 +272,10 @@ static int adf_ctl_is_device_in_use(int id)
static int adf_ctl_stop_devices(uint32_t id) static int adf_ctl_stop_devices(uint32_t id)
{ {
struct list_head *itr, *head = adf_devmgr_get_head(); struct adf_accel_dev *accel_dev;
int ret = 0; int ret = 0;
list_for_each_prev(itr, head) { list_for_each_entry_reverse(accel_dev, adf_devmgr_get_head(), list) {
struct adf_accel_dev *accel_dev =
list_entry(itr, struct adf_accel_dev, list);
if (id == accel_dev->accel_id || id == ADF_CFG_ALL_DEVICES) { if (id == accel_dev->accel_id || id == ADF_CFG_ALL_DEVICES) {
if (!adf_dev_started(accel_dev)) if (!adf_dev_started(accel_dev))
continue; continue;
......
...@@ -67,13 +67,10 @@ void qat_crypto_put_instance(struct qat_crypto_instance *inst) ...@@ -67,13 +67,10 @@ void qat_crypto_put_instance(struct qat_crypto_instance *inst)
static int qat_crypto_free_instances(struct adf_accel_dev *accel_dev) static int qat_crypto_free_instances(struct adf_accel_dev *accel_dev)
{ {
struct qat_crypto_instance *inst; struct qat_crypto_instance *inst, *tmp;
struct list_head *list_ptr, *tmp;
int i; int i;
list_for_each_safe(list_ptr, tmp, &accel_dev->crypto_list) { list_for_each_entry_safe(inst, tmp, &accel_dev->crypto_list, list) {
inst = list_entry(list_ptr, struct qat_crypto_instance, list);
for (i = 0; i < atomic_read(&inst->refctr); i++) for (i = 0; i < atomic_read(&inst->refctr); i++)
qat_crypto_put_instance(inst); qat_crypto_put_instance(inst);
...@@ -89,7 +86,7 @@ static int qat_crypto_free_instances(struct adf_accel_dev *accel_dev) ...@@ -89,7 +86,7 @@ static int qat_crypto_free_instances(struct adf_accel_dev *accel_dev)
if (inst->pke_rx) if (inst->pke_rx)
adf_remove_ring(inst->pke_rx); adf_remove_ring(inst->pke_rx);
list_del(list_ptr); list_del(&inst->list);
kfree(inst); kfree(inst);
} }
return 0; return 0;
...@@ -97,17 +94,13 @@ static int qat_crypto_free_instances(struct adf_accel_dev *accel_dev) ...@@ -97,17 +94,13 @@ static int qat_crypto_free_instances(struct adf_accel_dev *accel_dev)
struct qat_crypto_instance *qat_crypto_get_instance_node(int node) struct qat_crypto_instance *qat_crypto_get_instance_node(int node)
{ {
struct adf_accel_dev *accel_dev = NULL; struct adf_accel_dev *accel_dev = NULL, *tmp_dev;
struct qat_crypto_instance *inst = NULL; struct qat_crypto_instance *inst = NULL, *tmp_inst;
struct list_head *itr;
unsigned long best = ~0; unsigned long best = ~0;
list_for_each(itr, adf_devmgr_get_head()) { list_for_each_entry(tmp_dev, adf_devmgr_get_head(), list) {
struct adf_accel_dev *tmp_dev;
unsigned long ctr; unsigned long ctr;
tmp_dev = list_entry(itr, struct adf_accel_dev, list);
if ((node == dev_to_node(&GET_DEV(tmp_dev)) || if ((node == dev_to_node(&GET_DEV(tmp_dev)) ||
dev_to_node(&GET_DEV(tmp_dev)) < 0) && dev_to_node(&GET_DEV(tmp_dev)) < 0) &&
adf_dev_started(tmp_dev) && adf_dev_started(tmp_dev) &&
...@@ -123,10 +116,7 @@ struct qat_crypto_instance *qat_crypto_get_instance_node(int node) ...@@ -123,10 +116,7 @@ struct qat_crypto_instance *qat_crypto_get_instance_node(int node)
if (!accel_dev) { if (!accel_dev) {
pr_info("QAT: Could not find a device on node %d\n", node); pr_info("QAT: Could not find a device on node %d\n", node);
/* Get any started device */ /* Get any started device */
list_for_each(itr, adf_devmgr_get_head()) { list_for_each_entry(tmp_dev, adf_devmgr_get_head(), list) {
struct adf_accel_dev *tmp_dev;
tmp_dev = list_entry(itr, struct adf_accel_dev, list);
if (adf_dev_started(tmp_dev) && if (adf_dev_started(tmp_dev) &&
!list_empty(&tmp_dev->crypto_list)) { !list_empty(&tmp_dev->crypto_list)) {
accel_dev = tmp_dev; accel_dev = tmp_dev;
...@@ -139,11 +129,9 @@ struct qat_crypto_instance *qat_crypto_get_instance_node(int node) ...@@ -139,11 +129,9 @@ struct qat_crypto_instance *qat_crypto_get_instance_node(int node)
return NULL; return NULL;
best = ~0; best = ~0;
list_for_each(itr, &accel_dev->crypto_list) { list_for_each_entry(tmp_inst, &accel_dev->crypto_list, list) {
struct qat_crypto_instance *tmp_inst;
unsigned long ctr; unsigned long ctr;
tmp_inst = list_entry(itr, struct qat_crypto_instance, list);
ctr = atomic_read(&tmp_inst->refctr); ctr = atomic_read(&tmp_inst->refctr);
if (best > ctr) { if (best > ctr) {
inst = tmp_inst; inst = tmp_inst;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment