This patch adds code that cleans up established links whenever the destroy attribute is set or if the config_item (directory) is being removed. Signed-off-by: Christian Gromm <christian.gromm@xxxxxxxxxxxxx> --- drivers/staging/most/configfs.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/staging/most/configfs.c b/drivers/staging/most/configfs.c index 1e1d7d0..cb0256a 100644 --- a/drivers/staging/most/configfs.c +++ b/drivers/staging/most/configfs.c @@ -18,6 +18,7 @@ struct mdev_link { struct config_item item; struct list_head list; int create; + int destroy; u16 num_buffers; u16 buffer_size; u16 subbuffer_size; @@ -134,11 +135,8 @@ static ssize_t mdev_link_create_store(struct config_item *item, ret = kstrtou16(p, 0, &tmp); if (ret) return ret; - if (tmp > 1) + if (tmp != 1) return -ERANGE; - if (!tmp) - return most_remove_link(mdev_link->mdev, mdev_link->channel, - mdev_link->comp); if (!mdev_link->mdev || !mdev_link->channel || !mdev_link->comp) { pr_err("Config parameters incomplete\n"); @@ -152,6 +150,29 @@ static ssize_t mdev_link_create_store(struct config_item *item, return count; } +static ssize_t mdev_link_destroy_store(struct config_item *item, + const char *page, size_t count) +{ + struct mdev_link *mdev_link = to_mdev_link(item); + u16 tmp; + int ret; + char *p = (char *)page; + + ret = kstrtou16(p, 0, &tmp); + if (ret) + return ret; + if (tmp != 1) + return -ERANGE; + mdev_link->destroy = tmp; + ret = most_remove_link(mdev_link->mdev, mdev_link->channel, + mdev_link->comp); + if (ret) + return ret; + if (!list_empty(&mdev_link_list)) + list_del(&mdev_link->list); + return count; +} + static ssize_t mdev_link_direction_show(struct config_item *item, char *page) { return sprintf(page, "%s\n", to_mdev_link(item)->direction); @@ -344,6 +365,7 @@ static ssize_t mdev_link_dbr_size_store(struct config_item *item, } CONFIGFS_ATTR_WO(mdev_link_, create); +CONFIGFS_ATTR_WO(mdev_link_, destroy); CONFIGFS_ATTR(mdev_link_, mdev); CONFIGFS_ATTR(mdev_link_, channel); CONFIGFS_ATTR(mdev_link_, comp); @@ -358,6 +380,7 @@ CONFIGFS_ATTR(mdev_link_, dbr_size); static struct configfs_attribute *mdev_link_attrs[] = { &mdev_link_attr_create, + &mdev_link_attr_destroy, &mdev_link_attr_mdev, &mdev_link_attr_channel, &mdev_link_attr_comp, @@ -374,6 +397,16 @@ static struct configfs_attribute *mdev_link_attrs[] = { static void mdev_link_release(struct config_item *item) { + struct mdev_link *mdev_link = to_mdev_link(item); + int ret; + + if (!list_empty(&mdev_link_list)) { + ret = most_remove_link(mdev_link->mdev, mdev_link->channel, + mdev_link->comp); + if (ret && (ret != -ENODEV)) + pr_err("Removing link failed.\n"); + list_del(&mdev_link->list); + } kfree(to_mdev_link(item)); } -- 2.7.4 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel