From 42813295dfa3689c73e93726e7ebbbdb466dd246 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 27 Oct 2014 09:37:35 -0700 Subject: soc: ti: Use list_first_entry_or_null() at appropriate places Use list_first_entry_or_null() for first_region() and first_queue_range(). list_first_entry() expects the list is not empty, so first_region() and first_queue_range() never return NULL. Thus use list_first_entry_or_null() instead. Signed-off-by: Axel Lin Signed-off-by: Santosh Shilimkar --- drivers/soc/ti/knav_qmss.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/soc') diff --git a/drivers/soc/ti/knav_qmss.h b/drivers/soc/ti/knav_qmss.h index bc9dcc8cc3ce..51da2341280d 100644 --- a/drivers/soc/ti/knav_qmss.h +++ b/drivers/soc/ti/knav_qmss.h @@ -348,15 +348,15 @@ struct knav_range_info { list_for_each_entry(region, &kdev->regions, list) #define first_region(kdev) \ - list_first_entry(&kdev->regions, \ - struct knav_region, list) + list_first_entry_or_null(&kdev->regions, \ + struct knav_region, list) #define for_each_queue_range(kdev, range) \ list_for_each_entry(range, &kdev->queue_ranges, list) #define first_queue_range(kdev) \ - list_first_entry(&kdev->queue_ranges, \ - struct knav_range_info, list) + list_first_entry_or_null(&kdev->queue_ranges, \ + struct knav_range_info, list) #define for_each_pool(kdev, pool) \ list_for_each_entry(pool, &kdev->pools, list) -- cgit v1.2.3 From ea6d4c07ca872b875b31e9a9bc99c21359c0f19c Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 27 Oct 2014 09:37:35 -0700 Subject: soc: ti: knav_qmss_queue: Fix unbalanced locking ins knav_pool_create() Don't call mutex_unlock() in the error patch if the mutex_lock() is not called. Signed-off-by: Axel Lin Signed-off-by: Santosh Shilimkar --- drivers/soc/ti/knav_qmss_queue.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/soc') diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c index 0a2c8634c48b..d66aaf2c2ecd 100644 --- a/drivers/soc/ti/knav_qmss_queue.c +++ b/drivers/soc/ti/knav_qmss_queue.c @@ -785,7 +785,7 @@ void *knav_pool_create(const char *name, dev_err(kdev->dev, "out of descs in region(%d) for pool(%s)\n", region_id, name); ret = -ENOMEM; - goto err; + goto err_unlock; } /* Region maintains a sorted (by region offset) list of pools @@ -815,15 +815,16 @@ void *knav_pool_create(const char *name, dev_err(kdev->dev, "pool(%s) create failed: fragmented desc pool in region(%d)\n", name, region_id); ret = -ENOMEM; - goto err; + goto err_unlock; } mutex_unlock(&knav_dev_lock); kdesc_fill_pool(pool); return pool; -err: +err_unlock: mutex_unlock(&knav_dev_lock); +err: kfree(pool->name); devm_kfree(kdev->dev, pool); return ERR_PTR(ret); -- cgit v1.2.3 From 39179cb5b789e0c0275ccb8fa83cfaf9257d1474 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 27 Oct 2014 09:37:35 -0700 Subject: soc: ti: knav_qmss_queue: Return proper error if devm_kzalloc fails Return -ENOMEM if devm_kzalloc fails. Signed-off-by: Axel Lin Signed-off-by: Santosh Shilimkar --- drivers/soc/ti/knav_qmss_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/soc') diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c index d66aaf2c2ecd..6f22d5622c98 100644 --- a/drivers/soc/ti/knav_qmss_queue.c +++ b/drivers/soc/ti/knav_qmss_queue.c @@ -1640,7 +1640,7 @@ static int knav_queue_init_queues(struct knav_device *kdev) size = (1 << kdev->inst_shift) * kdev->num_queues_in_use; kdev->instances = devm_kzalloc(kdev->dev, size, GFP_KERNEL); if (!kdev->instances) - return -1; + return -ENOMEM; for_each_queue_range(kdev, range) { if (range->ops && range->ops->init_range) -- cgit v1.2.3 From 148bb0439adeeae466dca31dd4c643e194bee023 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 3 Nov 2014 10:21:54 -0800 Subject: soc: ti: knav_qmss_queue: Use list_for_each_entry_safe to prevent use after free list_for_each_entry_safe() is necessary if list objects are deleted from the list while traversing it. Signed-off-by: Axel Lin Signed-off-by: Santosh Shilimkar --- drivers/soc/ti/knav_qmss_queue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/soc') diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c index 6f22d5622c98..9b8dd6732681 100644 --- a/drivers/soc/ti/knav_qmss_queue.c +++ b/drivers/soc/ti/knav_qmss_queue.c @@ -1306,14 +1306,14 @@ static void knav_free_queue_ranges(struct knav_device *kdev) static void knav_queue_free_regions(struct knav_device *kdev) { struct knav_region *region; - struct knav_pool *pool; + struct knav_pool *pool, *tmp; unsigned size; for (;;) { region = first_region(kdev); if (!region) break; - list_for_each_entry(pool, ®ion->pools, region_inst) + list_for_each_entry_safe(pool, tmp, ®ion->pools, region_inst) knav_pool_destroy(pool); size = region->virt_end - region->virt_start; -- cgit v1.2.3