In preparation for adding more common sysfs & links functionality, move the existing sysfs functions into a separate common file.
Signed-off-by: Mike Leach mike.leach@linaro.org --- drivers/hwtracing/coresight/Makefile | 3 +- drivers/hwtracing/coresight/coresight-sysfs.c | 82 +++++++++++++++++++ drivers/hwtracing/coresight/coresight.c | 73 ----------------- 3 files changed, 84 insertions(+), 74 deletions(-) create mode 100644 drivers/hwtracing/coresight/coresight-sysfs.c
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile index 43d563705e98..43b79e538477 100644 --- a/drivers/hwtracing/coresight/Makefile +++ b/drivers/hwtracing/coresight/Makefile @@ -2,7 +2,8 @@ # # Makefile for CoreSight drivers. # -obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o coresight-platform.o +obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \ + coresight-platform.o coresight-sysfs.o obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \ coresight-tmc-etf.o \ coresight-tmc-etr.o diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c b/drivers/hwtracing/coresight/coresight-sysfs.c new file mode 100644 index 000000000000..058a092ba75f --- /dev/null +++ b/drivers/hwtracing/coresight/coresight-sysfs.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + */ + +#include <linux/device.h> +#include <linux/kernel.h> + +#include "coresight-priv.h" + +static int coresight_create_sysfs_link(struct kobject *from, + struct kobject *to, + const char *link_name, + const char *group_name) +{ + if (group_name) + return sysfs_add_link_to_group(from, group_name, + to, link_name); + else + return sysfs_create_link(from, to, link_name); +} + +static void coresight_delete_sysfs_link(struct kobject *kobj, + const char *link_name, + const char *group_name) +{ + if (group_name) + sysfs_remove_link_from_group(kobj, group_name, link_name); + else + sysfs_remove_link(kobj, link_name); +} + +int coresight_add_sysfs_link(struct coresight_sysfs_link *info) +{ + int ret = 0; + + if (!info) + return -EINVAL; + if (!info->orig || !info->target || + !info->orig_name || !info->target_name) + return -EINVAL; + + /* first link orig->target */ + ret = coresight_create_sysfs_link(&info->orig->dev.kobj, + &info->target->dev.kobj, + info->orig_name, + info->orig->sysfs_link_grp); + if (ret) + return ret; + + /* second link target->orig */ + ret = coresight_create_sysfs_link(&info->target->dev.kobj, + &info->orig->dev.kobj, + info->target_name, + info->target->sysfs_link_grp); + + /* error in second link - remove first */ + if (ret) { + coresight_delete_sysfs_link(&info->orig->dev.kobj, + info->orig_name, + info->orig->sysfs_link_grp); + } + + return ret; +} + +void coresight_remove_sysfs_link(struct coresight_sysfs_link *info) +{ + if (!info) + return; + if (!info->orig || !info->target || + !info->orig_name || !info->target_name) + return; + + coresight_delete_sysfs_link(&info->orig->dev.kobj, + info->orig_name, + info->orig->sysfs_link_grp); + + coresight_delete_sysfs_link(&info->target->dev.kobj, + info->target_name, + info->target->sysfs_link_grp); +} diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index efd6b2f0d4fd..1e75cc7203b5 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -1032,79 +1032,6 @@ static void coresight_device_release(struct device *dev) kfree(csdev); }
-static int coresight_create_sysfs_link(struct kobject *from, - struct kobject *to, - const char *link_name, - const char *group_name) -{ - if (group_name) - return sysfs_add_link_to_group(from, group_name, - to, link_name); - else - return sysfs_create_link(from, to, link_name); -} - -static void coresight_delete_sysfs_link(struct kobject *kobj, - const char *link_name, - const char *group_name) -{ - if (group_name) - sysfs_remove_link_from_group(kobj, group_name, link_name); - else - sysfs_remove_link(kobj, link_name); -} - -int coresight_add_sysfs_link(struct coresight_sysfs_link *info) -{ - int ret = 0; - - if (!info) - return -EINVAL; - if (!info->orig || !info->target || - !info->orig_name || !info->target_name) - return -EINVAL; - - /* first link orig->target */ - ret = coresight_create_sysfs_link(&info->orig->dev.kobj, - &info->target->dev.kobj, - info->orig_name, - info->orig->sysfs_link_grp); - if (ret) - return ret; - - /* second link target->orig */ - ret = coresight_create_sysfs_link(&info->target->dev.kobj, - &info->orig->dev.kobj, - info->target_name, - info->target->sysfs_link_grp); - - /* error in second link - remove first */ - if (ret) { - coresight_delete_sysfs_link(&info->orig->dev.kobj, - info->orig_name, - info->orig->sysfs_link_grp); - } - - return ret; -} - -void coresight_remove_sysfs_link(struct coresight_sysfs_link *info) -{ - if (!info) - return; - if (!info->orig || !info->target || - !info->orig_name || !info->target_name) - return; - - coresight_delete_sysfs_link(&info->orig->dev.kobj, - info->orig_name, - info->orig->sysfs_link_grp); - - coresight_delete_sysfs_link(&info->target->dev.kobj, - info->target_name, - info->target->sysfs_link_grp); -} - static int coresight_orphan_match(struct device *dev, void *data) { int i;