From 375fb53ec1be6df6cfd0ac4932f14f0b7f57a761 Mon Sep 17 00:00:00 2001 From: Ioana Ciornei Date: Sun, 1 Nov 2015 16:38:20 +0200 Subject: staging: android: replace explicit NULL comparison This patch replaces explicit NULL comparison with ! operator in order to simplify the code Signed-off-by: Ioana Ciornei Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/compat_ion.c | 6 +++--- drivers/staging/android/sync.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/ion/compat_ion.c b/drivers/staging/android/ion/compat_ion.c index a402fdaf54ca..9a978d21785e 100644 --- a/drivers/staging/android/ion/compat_ion.c +++ b/drivers/staging/android/ion/compat_ion.c @@ -137,7 +137,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data32 = compat_ptr(arg); data = compat_alloc_user_space(sizeof(*data)); - if (data == NULL) + if (!data) return -EFAULT; err = compat_get_ion_allocation_data(data32, data); @@ -156,7 +156,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data32 = compat_ptr(arg); data = compat_alloc_user_space(sizeof(*data)); - if (data == NULL) + if (!data) return -EFAULT; err = compat_get_ion_handle_data(data32, data); @@ -173,7 +173,7 @@ long compat_ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) data32 = compat_ptr(arg); data = compat_alloc_user_space(sizeof(*data)); - if (data == NULL) + if (!data) return -EFAULT; err = compat_get_ion_custom_data(data32, data); diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index f83e00c78051..5413f28afe8e 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -43,7 +43,7 @@ struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops, return NULL; obj = kzalloc(size, GFP_KERNEL); - if (obj == NULL) + if (!obj) return NULL; kref_init(&obj->kref); @@ -130,7 +130,7 @@ struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size) return NULL; pt = kzalloc(size, GFP_KERNEL); - if (pt == NULL) + if (!pt) return NULL; spin_lock_irqsave(&obj->child_list_lock, flags); @@ -155,7 +155,7 @@ static struct sync_fence *sync_fence_alloc(int size, const char *name) struct sync_fence *fence; fence = kzalloc(size, GFP_KERNEL); - if (fence == NULL) + if (!fence) return NULL; fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops, @@ -193,7 +193,7 @@ struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) struct sync_fence *fence; fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]), name); - if (fence == NULL) + if (!fence) return NULL; fence->num_fences = 1; @@ -215,7 +215,7 @@ struct sync_fence *sync_fence_fdget(int fd) { struct file *file = fget(fd); - if (file == NULL) + if (!file) return NULL; if (file->f_op != &sync_fence_fops) @@ -262,7 +262,7 @@ struct sync_fence *sync_fence_merge(const char *name, unsigned long size = offsetof(struct sync_fence, cbs[num_fences]); fence = sync_fence_alloc(size, name); - if (fence == NULL) + if (!fence) return NULL; atomic_set(&fence->status, num_fences); @@ -583,14 +583,14 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg) } fence2 = sync_fence_fdget(data.fd2); - if (fence2 == NULL) { + if (!fence2) { err = -ENOENT; goto err_put_fd; } data.name[sizeof(data.name) - 1] = '\0'; fence3 = sync_fence_merge(data.name, fence, fence2); - if (fence3 == NULL) { + if (!fence3) { err = -ENOMEM; goto err_put_fence2; } @@ -666,7 +666,7 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *fence, size = 4096; data = kzalloc(size, GFP_KERNEL); - if (data == NULL) + if (!data) return -ENOMEM; strlcpy(data->name, fence->name, sizeof(data->name)); -- cgit v1.2.1 From 36f16ff25c0290aa700dc0944f41dc14ff050432 Mon Sep 17 00:00:00 2001 From: Ioana Ciornei Date: Sun, 1 Nov 2015 16:38:21 +0200 Subject: staging: android: replace uint32_t with u32 This patch makes use of the preferred kernel types such as u16, u32. Signed-off-by: Ioana Ciornei Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/lowmemorykiller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c index e679d8432810..de65db7d938f 100644 --- a/drivers/staging/android/lowmemorykiller.c +++ b/drivers/staging/android/lowmemorykiller.c @@ -43,7 +43,7 @@ #include #include -static uint32_t lowmem_debug_level = 1; +static u32 lowmem_debug_level = 1; static short lowmem_adj[6] = { 0, 1, -- cgit v1.2.1 From f8b053e3da56cdfa798ce5d7014860798b04b7bc Mon Sep 17 00:00:00 2001 From: Ioana Ciornei Date: Sun, 1 Nov 2015 16:38:22 +0200 Subject: staging: android: properly align function arguments Fix alingment issues by properly indenting function arguments in accordance with the kernel coding style. Signed-off-by: Ioana Ciornei Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/lowmemorykiller.c | 4 ++-- drivers/staging/android/sync.c | 4 ++-- drivers/staging/android/timed_gpio.c | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c index de65db7d938f..8b5a4a82d8b8 100644 --- a/drivers/staging/android/lowmemorykiller.c +++ b/drivers/staging/android/lowmemorykiller.c @@ -105,8 +105,8 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) } lowmem_print(3, "lowmem_scan %lu, %x, ofree %d %d, ma %hd\n", - sc->nr_to_scan, sc->gfp_mask, other_free, - other_file, min_score_adj); + sc->nr_to_scan, sc->gfp_mask, other_free, + other_file, min_score_adj); if (min_score_adj == OOM_SCORE_ADJ_MAX + 1) { lowmem_print(5, "lowmem_scan %lu, %x, return 0\n", diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 5413f28afe8e..e0c1acb2ba69 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -313,7 +313,7 @@ struct sync_fence *sync_fence_merge(const char *name, EXPORT_SYMBOL(sync_fence_merge); int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode, - int wake_flags, void *key) + int wake_flags, void *key) { struct sync_fence_waiter *wait; @@ -353,7 +353,7 @@ int sync_fence_wait_async(struct sync_fence *fence, EXPORT_SYMBOL(sync_fence_wait_async); int sync_fence_cancel_async(struct sync_fence *fence, - struct sync_fence_waiter *waiter) + struct sync_fence_waiter *waiter) { unsigned long flags; int ret = 0; diff --git a/drivers/staging/android/timed_gpio.c b/drivers/staging/android/timed_gpio.c index ce11726f1a6c..5246f42c1227 100644 --- a/drivers/staging/android/timed_gpio.c +++ b/drivers/staging/android/timed_gpio.c @@ -76,8 +76,8 @@ static void gpio_enable(struct timed_output_dev *dev, int value) value = data->max_timeout; hrtimer_start(&data->timer, - ktime_set(value / 1000, (value % 1000) * 1000000), - HRTIMER_MODE_REL); + ktime_set(value / 1000, (value % 1000) * 1000000), + HRTIMER_MODE_REL); } spin_unlock_irqrestore(&data->lock, flags); @@ -94,8 +94,8 @@ static int timed_gpio_probe(struct platform_device *pdev) return -EBUSY; gpio_data = devm_kzalloc(&pdev->dev, - sizeof(struct timed_gpio_data) * pdata->num_gpios, - GFP_KERNEL); + sizeof(*gpio_data) * pdata->num_gpios, + GFP_KERNEL); if (!gpio_data) return -ENOMEM; @@ -104,7 +104,7 @@ static int timed_gpio_probe(struct platform_device *pdev) gpio_dat = &gpio_data[i]; hrtimer_init(&gpio_dat->timer, CLOCK_MONOTONIC, - HRTIMER_MODE_REL); + HRTIMER_MODE_REL); gpio_dat->timer.function = gpio_timer_func; spin_lock_init(&gpio_dat->lock); -- cgit v1.2.1 From 49112c7fc2329a668d886f4410d9666328d8b2ef Mon Sep 17 00:00:00 2001 From: Ioana Ciornei Date: Sun, 1 Nov 2015 16:38:23 +0200 Subject: staging: android: remove multiple blank lines This patch removes multiple blank lines in order to follow the linux kernel coding style. Signed-off-by: Ioana Ciornei Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/timed_gpio.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/timed_gpio.c b/drivers/staging/android/timed_gpio.c index 5246f42c1227..bcd9924d4631 100644 --- a/drivers/staging/android/timed_gpio.c +++ b/drivers/staging/android/timed_gpio.c @@ -25,7 +25,6 @@ #include "timed_output.h" #include "timed_gpio.h" - struct timed_gpio_data { struct timed_output_dev dev; struct hrtimer timer; -- cgit v1.2.1 From d3ae4fa40088045b500f4d1ce85eb926b6cd2d3e Mon Sep 17 00:00:00 2001 From: Gustavo Padovan Date: Thu, 26 Nov 2015 11:03:56 -0200 Subject: staging/android: add TODO to de-stage android sync framework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove CONFIG_SW_SYNC_USER, it is used only for testing/debugging and should not be upstreamed. - port CONFIG_SW_SYNC_USER tests interfaces to use debugfs somehow - port libsync tests to kselftest - clean up and ABI check for security issues - move the sync framework to drivers/base/dma-buf Cc: Arve Hjønnevåg Cc: Riley Andrews Cc: Daniel Vetter Cc: Rob Clark Cc: Greg Hackmann Cc: John Harrison Signed-off-by: Gustavo Padovan Acked-by: Daniel Vetter Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/TODO | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO index 8f3ac37bfe12..64d8c8720960 100644 --- a/drivers/staging/android/TODO +++ b/drivers/staging/android/TODO @@ -25,5 +25,13 @@ ion/ exposes existing cma regions and doesn't reserve unecessarily memory when booting a system which doesn't use ion. +sync framework: + - remove CONFIG_SW_SYNC_USER, it is used only for testing/debugging and + should not be upstreamed. + - port CONFIG_SW_SYNC_USER tests interfaces to use debugfs somehow + - port libsync tests to kselftest + - clean up and ABI check for security issues + - move it to drivers/base/dma-buf + Please send patches to Greg Kroah-Hartman and Cc: Arve Hjønnevåg and Riley Andrews -- cgit v1.2.1 From 2b40182a19bc238465688fb989fb33b99e953121 Mon Sep 17 00:00:00 2001 From: Chen Feng Date: Mon, 12 Oct 2015 15:00:16 +0800 Subject: staging: android: ion: Add ion driver for Hi6220 SoC platform Add ion support for hi6220 SoC platform. Signed-off-by: Chen Feng Signed-off-by: Yu Dongbin Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ion/Kconfig | 7 + drivers/staging/android/ion/Makefile | 1 + drivers/staging/android/ion/hisilicon/Kconfig | 5 + drivers/staging/android/ion/hisilicon/Makefile | 1 + drivers/staging/android/ion/hisilicon/hi6220_ion.c | 223 +++++++++++++++++++++ 5 files changed, 237 insertions(+) create mode 100644 drivers/staging/android/ion/hisilicon/Kconfig create mode 100644 drivers/staging/android/ion/hisilicon/Makefile create mode 100644 drivers/staging/android/ion/hisilicon/hi6220_ion.c (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig index 345234624492..19c1572f1525 100644 --- a/drivers/staging/android/ion/Kconfig +++ b/drivers/staging/android/ion/Kconfig @@ -33,3 +33,10 @@ config ION_TEGRA help Choose this option if you wish to use ion on an nVidia Tegra. +config ION_HISI + tristate "Ion for Hisilicon" + depends on ARCH_HISI && ION + help + Choose this option if you wish to use ion on Hisilicon Platform. + +source "drivers/staging/android/ion/hisilicon/Kconfig" diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile index b56fd2bf2b4f..18cc2aa593c2 100644 --- a/drivers/staging/android/ion/Makefile +++ b/drivers/staging/android/ion/Makefile @@ -7,4 +7,5 @@ endif obj-$(CONFIG_ION_DUMMY) += ion_dummy_driver.o obj-$(CONFIG_ION_TEGRA) += tegra/ +obj-$(CONFIG_ION_HISI) += hisilicon/ diff --git a/drivers/staging/android/ion/hisilicon/Kconfig b/drivers/staging/android/ion/hisilicon/Kconfig new file mode 100644 index 000000000000..2b4bd0798290 --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/Kconfig @@ -0,0 +1,5 @@ +config HI6220_ION + bool "Hi6220 ION Driver" + depends on ARCH_HISI && ION + help + Build the Hisilicon Hi6220 ion driver. diff --git a/drivers/staging/android/ion/hisilicon/Makefile b/drivers/staging/android/ion/hisilicon/Makefile new file mode 100644 index 000000000000..2a89414280ac --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_HI6220_ION) += hi6220_ion.o diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c new file mode 100644 index 000000000000..e3c07b2ba00e --- /dev/null +++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c @@ -0,0 +1,223 @@ +/* + * Hisilicon Hi6220 ION Driver + * + * Copyright (c) 2015 Hisilicon Limited. + * + * Author: Chen Feng + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "Ion: " fmt + +#include +#include +#include +#include +#include +#include "../ion_priv.h" +#include "../ion.h" + +struct hi6220_ion_type_table { + const char *name; + enum ion_heap_type type; +}; + +static struct hi6220_ion_type_table ion_type_table[] = { + {"ion_system", ION_HEAP_TYPE_SYSTEM}, + {"ion_system_contig", ION_HEAP_TYPE_SYSTEM_CONTIG}, + {"ion_carveout", ION_HEAP_TYPE_CARVEOUT}, + {"ion_chunk", ION_HEAP_TYPE_CHUNK}, + {"ion_dma", ION_HEAP_TYPE_DMA}, + {"ion_custom", ION_HEAP_TYPE_CUSTOM}, +}; + +static struct ion_device *idev; +static int num_heaps; +static struct ion_heap **heaps; +static struct ion_platform_heap **heaps_data; + +static int get_type_by_name(const char *name, enum ion_heap_type *type) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ion_type_table); i++) { + if (strncmp(name, ion_type_table[i].name, strlen(name))) + continue; + + *type = ion_type_table[i].type; + return 0; + } + + return -EINVAL; +} + +static int hi6220_set_platform_data(struct platform_device *pdev) +{ + unsigned int base; + unsigned int size; + unsigned int id; + const char *heap_name; + const char *type_name; + enum ion_heap_type type; + int ret; + struct device_node *np; + struct ion_platform_heap *p_data; + const struct device_node *dt_node = pdev->dev.of_node; + int index = 0; + + for_each_child_of_node(dt_node, np) + num_heaps++; + + heaps_data = devm_kzalloc(&pdev->dev, + sizeof(struct ion_platform_heap *) * + num_heaps, + GFP_KERNEL); + if (!heaps_data) + return -ENOMEM; + + for_each_child_of_node(dt_node, np) { + ret = of_property_read_string(np, "heap-name", &heap_name); + if (ret < 0) { + pr_err("check the name of node %s\n", np->name); + continue; + } + + ret = of_property_read_u32(np, "heap-id", &id); + if (ret < 0) { + pr_err("check the id %s\n", np->name); + continue; + } + + ret = of_property_read_u32(np, "heap-base", &base); + if (ret < 0) { + pr_err("check the base of node %s\n", np->name); + continue; + } + + ret = of_property_read_u32(np, "heap-size", &size); + if (ret < 0) { + pr_err("check the size of node %s\n", np->name); + continue; + } + + ret = of_property_read_string(np, "heap-type", &type_name); + if (ret < 0) { + pr_err("check the type of node %s\n", np->name); + continue; + } + + ret = get_type_by_name(type_name, &type); + if (ret < 0) { + pr_err("type name error %s!\n", type_name); + continue; + } + pr_info("heap index %d : name %s base 0x%x size 0x%x id %d type %d\n", + index, heap_name, base, size, id, type); + + p_data = devm_kzalloc(&pdev->dev, + sizeof(struct ion_platform_heap), + GFP_KERNEL); + if (!p_data) + return -ENOMEM; + + p_data->name = heap_name; + p_data->base = base; + p_data->size = size; + p_data->id = id; + p_data->type = type; + + heaps_data[index] = p_data; + index++; + } + return 0; +} + +static int hi6220_ion_probe(struct platform_device *pdev) +{ + int i; + int err; + static struct ion_platform_heap *p_heap; + + idev = ion_device_create(NULL); + err = hi6220_set_platform_data(pdev); + if (err) { + pr_err("ion set platform data error!\n"); + goto err_free_idev; + } + heaps = devm_kzalloc(&pdev->dev, + sizeof(struct ion_heap *) * num_heaps, + GFP_KERNEL); + if (!heaps) { + err = -ENOMEM; + goto err_free_idev; + } + + /* + * create the heaps as specified in the dts file + */ + for (i = 0; i < num_heaps; i++) { + p_heap = heaps_data[i]; + heaps[i] = ion_heap_create(p_heap); + if (IS_ERR_OR_NULL(heaps[i])) { + err = PTR_ERR(heaps[i]); + goto err_free_heaps; + } + + ion_device_add_heap(idev, heaps[i]); + + pr_info("%s: adding heap %s of type %d with %lx@%lx\n", + __func__, p_heap->name, p_heap->type, + p_heap->base, (unsigned long)p_heap->size); + } + return err; + +err_free_heaps: + for (i = 0; i < num_heaps; ++i) { + ion_heap_destroy(heaps[i]); + heaps[i] = NULL; + } +err_free_idev: + ion_device_destroy(idev); + + return err; +} + +static int hi6220_ion_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < num_heaps; i++) { + ion_heap_destroy(heaps[i]); + heaps[i] = NULL; + } + ion_device_destroy(idev); + + return 0; +} + +static const struct of_device_id hi6220_ion_match_table[] = { + {.compatible = "hisilicon,hi6220-ion"}, + {}, +}; + +static struct platform_driver hi6220_ion_driver = { + .probe = hi6220_ion_probe, + .remove = hi6220_ion_remove, + .driver = { + .name = "ion-hi6220", + .of_match_table = hi6220_ion_match_table, + }, +}; + +static int __init hi6220_ion_init(void) +{ + int ret; + + ret = platform_driver_register(&hi6220_ion_driver); + return ret; +} + +subsys_initcall(hi6220_ion_init); -- cgit v1.2.1 From a2df4e33d71ff819c9afcdf34392030cee349f47 Mon Sep 17 00:00:00 2001 From: Wenwei Tao Date: Wed, 9 Dec 2015 00:15:52 +0800 Subject: staging: android: ashmem.c: destroy slabs when init fails when ashmem init fails, destroy the slabs, leave no garbage. Signed-off-by: Wenwei Tao Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/ashmem.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c index 3f2a3d611e4b..5bb1283d19cd 100644 --- a/drivers/staging/android/ashmem.c +++ b/drivers/staging/android/ashmem.c @@ -831,14 +831,14 @@ static struct miscdevice ashmem_misc = { static int __init ashmem_init(void) { - int ret; + int ret = -ENOMEM; ashmem_area_cachep = kmem_cache_create("ashmem_area_cache", sizeof(struct ashmem_area), 0, 0, NULL); if (unlikely(!ashmem_area_cachep)) { pr_err("failed to create slab cache\n"); - return -ENOMEM; + goto out; } ashmem_range_cachep = kmem_cache_create("ashmem_range_cache", @@ -846,13 +846,13 @@ static int __init ashmem_init(void) 0, 0, NULL); if (unlikely(!ashmem_range_cachep)) { pr_err("failed to create slab cache\n"); - return -ENOMEM; + goto out_free1; } ret = misc_register(&ashmem_misc); if (unlikely(ret)) { pr_err("failed to register misc device!\n"); - return ret; + goto out_free2; } register_shrinker(&ashmem_shrinker); @@ -860,5 +860,12 @@ static int __init ashmem_init(void) pr_info("initialized\n"); return 0; + +out_free2: + kmem_cache_destroy(ashmem_range_cachep); +out_free1: + kmem_cache_destroy(ashmem_area_cachep); +out: + return ret; } device_initcall(ashmem_init); -- cgit v1.2.1 From 73465f1c08258637dc8c49c2c8d1a1233d9861c7 Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Fri, 11 Dec 2015 13:11:49 +0000 Subject: staging/android/sync: Support sync points created from dma-fences MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Debug output assumes all sync points are built on top of Android sync points and when we start creating them from dma-fences will NULL ptr deref unless taught about this. v4: Corrected patch ownership. Signed-off-by: Maarten Lankhorst Signed-off-by: Tvrtko Ursulin Cc: Maarten Lankhorst Cc: devel@driverdev.osuosl.org Cc: Riley Andrews Cc: Arve Hjønnevåg Reviewed-by: Jesse Barnes Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sync_debug.c | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index 91ed2c4cff45..f45d13cdd42b 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -82,36 +82,42 @@ static const char *sync_status_str(int status) return "error"; } -static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence) +static void sync_print_pt(struct seq_file *s, struct fence *pt, bool fence) { int status = 1; - struct sync_timeline *parent = sync_pt_parent(pt); - if (fence_is_signaled_locked(&pt->base)) - status = pt->base.status; + if (fence_is_signaled_locked(pt)) + status = pt->status; seq_printf(s, " %s%spt %s", - fence ? parent->name : "", + fence && pt->ops->get_timeline_name ? + pt->ops->get_timeline_name(pt) : "", fence ? "_" : "", sync_status_str(status)); if (status <= 0) { struct timespec64 ts64 = - ktime_to_timespec64(pt->base.timestamp); + ktime_to_timespec64(pt->timestamp); seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec); } - if (parent->ops->timeline_value_str && - parent->ops->pt_value_str) { + if ((!fence || pt->ops->timeline_value_str) && + pt->ops->fence_value_str) { char value[64]; + bool success; - parent->ops->pt_value_str(pt, value, sizeof(value)); - seq_printf(s, ": %s", value); - if (fence) { - parent->ops->timeline_value_str(parent, value, - sizeof(value)); - seq_printf(s, " / %s", value); + pt->ops->fence_value_str(pt, value, sizeof(value)); + success = strlen(value); + + if (success) + seq_printf(s, ": %s", value); + + if (success && fence) { + pt->ops->timeline_value_str(pt, value, sizeof(value)); + + if (strlen(value)) + seq_printf(s, " / %s", value); } } @@ -138,7 +144,7 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) list_for_each(pos, &obj->child_list_head) { struct sync_pt *pt = container_of(pos, struct sync_pt, child_list); - sync_print_pt(s, pt, false); + sync_print_pt(s, &pt->base, false); } spin_unlock_irqrestore(&obj->child_list_lock, flags); } @@ -153,11 +159,7 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence) sync_status_str(atomic_read(&fence->status))); for (i = 0; i < fence->num_fences; ++i) { - struct sync_pt *pt = - container_of(fence->cbs[i].sync_pt, - struct sync_pt, base); - - sync_print_pt(s, pt, true); + sync_print_pt(s, fence->cbs[i].sync_pt, true); } spin_lock_irqsave(&fence->wq.lock, flags); -- cgit v1.2.1 From 0f477c6dea709465550aa0922fd0c5b686e6e8eb Mon Sep 17 00:00:00 2001 From: Maarten Lankhorst Date: Fri, 11 Dec 2015 13:11:50 +0000 Subject: staging/android/sync: add sync_fence_create_dma MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows users of dma fences to create a android fence. v2: Added kerneldoc. (Tvrtko Ursulin). v4: Updated comments from review feedback my Maarten. Signed-off-by: Maarten Lankhorst Signed-off-by: Tvrtko Ursulin Cc: Maarten Lankhorst Cc: Daniel Vetter Cc: devel@driverdev.osuosl.org Cc: Riley Andrews Cc: Arve Hjønnevåg Reviewed-by: Jesse Barnes Tested-by: Jesse Barnes Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sync.c | 13 +++++++++---- drivers/staging/android/sync.h | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index e0c1acb2ba69..78c62dfb3978 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -188,7 +188,7 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb) } /* TODO: implement a create which takes more that one sync_pt */ -struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) +struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt) { struct sync_fence *fence; @@ -199,16 +199,21 @@ struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) fence->num_fences = 1; atomic_set(&fence->status, 1); - fence->cbs[0].sync_pt = &pt->base; + fence->cbs[0].sync_pt = pt; fence->cbs[0].fence = fence; - if (fence_add_callback(&pt->base, &fence->cbs[0].cb, - fence_check_cb_func)) + if (fence_add_callback(pt, &fence->cbs[0].cb, fence_check_cb_func)) atomic_dec(&fence->status); sync_fence_debug_add(fence); return fence; } +EXPORT_SYMBOL(sync_fence_create_dma); + +struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) +{ + return sync_fence_create_dma(name, &pt->base); +} EXPORT_SYMBOL(sync_fence_create); struct sync_fence *sync_fence_fdget(int fd) diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index 61f8a3aede96..afa0752275a7 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -254,6 +254,16 @@ void sync_pt_free(struct sync_pt *pt); */ struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt); +/** + * sync_fence_create_dma() - creates a sync fence from dma-fence + * @name: name of fence to create + * @pt: dma-fence to add to the fence + * + * Creates a fence containg @pt. Once this is called, the fence takes + * ownership of @pt. + */ +struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt); + /* * API for sync_fence consumers */ -- cgit v1.2.1 From 699f685569434510d944e419f4048c4e3ba8d631 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 14 Dec 2015 17:34:08 -0800 Subject: android: unconditionally remove callbacks in sync_fence_free() Using fence->status to determine whether or not there are callbacks remaining on the sync_fence is racy since fence->status may have been decremented to 0 on another CPU before fence_check_cb_func() has completed. By unconditionally calling fence_remove_callback() for each fence in the sync_fence, we guarantee that each callback has either completed (since fence_remove_callback() grabs the fence lock) or been removed. Signed-off-by: Andrew Bresticker Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/staging/android/sync.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/staging/android') diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 78c62dfb3978..ed43796b5b58 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -524,12 +524,10 @@ static const struct fence_ops android_fence_ops = { static void sync_fence_free(struct kref *kref) { struct sync_fence *fence = container_of(kref, struct sync_fence, kref); - int i, status = atomic_read(&fence->status); + int i; for (i = 0; i < fence->num_fences; ++i) { - if (status) - fence_remove_callback(fence->cbs[i].sync_pt, - &fence->cbs[i].cb); + fence_remove_callback(fence->cbs[i].sync_pt, &fence->cbs[i].cb); fence_put(fence->cbs[i].sync_pt); } -- cgit v1.2.1