Commit 1a89eb0a authored by Christian Gromm's avatar Christian Gromm Committed by Greg Kroah-Hartman

staging: most: configfs: add code for link removal

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: default avatarChristian Gromm <christian.gromm@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a15f465c
...@@ -16,6 +16,7 @@ struct mdev_link { ...@@ -16,6 +16,7 @@ struct mdev_link {
struct config_item item; struct config_item item;
struct list_head list; struct list_head list;
bool create_link; bool create_link;
bool destroy_link;
u16 num_buffers; u16 num_buffers;
u16 buffer_size; u16 buffer_size;
u16 subbuffer_size; u16 subbuffer_size;
...@@ -132,8 +133,7 @@ static ssize_t mdev_link_create_link_store(struct config_item *item, ...@@ -132,8 +133,7 @@ static ssize_t mdev_link_create_link_store(struct config_item *item,
if (ret) if (ret)
return ret; return ret;
if (!tmp) if (!tmp)
return most_remove_link(mdev_link->device, mdev_link->channel, return count;
mdev_link->comp);
ret = set_config_and_add_link(mdev_link); ret = set_config_and_add_link(mdev_link);
if (ret && ret != -ENODEV) if (ret && ret != -ENODEV)
return ret; return ret;
...@@ -142,6 +142,28 @@ static ssize_t mdev_link_create_link_store(struct config_item *item, ...@@ -142,6 +142,28 @@ static ssize_t mdev_link_create_link_store(struct config_item *item,
return count; return count;
} }
static ssize_t mdev_link_destroy_link_store(struct config_item *item,
const char *page, size_t count)
{
struct mdev_link *mdev_link = to_mdev_link(item);
bool tmp;
int ret;
ret = kstrtobool(page, &tmp);
if (ret)
return ret;
if (!tmp)
return count;
mdev_link->destroy_link = tmp;
ret = most_remove_link(mdev_link->device, 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) static ssize_t mdev_link_direction_show(struct config_item *item, char *page)
{ {
return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->direction); return snprintf(page, PAGE_SIZE, "%s\n", to_mdev_link(item)->direction);
...@@ -326,6 +348,7 @@ static ssize_t mdev_link_dbr_size_store(struct config_item *item, ...@@ -326,6 +348,7 @@ static ssize_t mdev_link_dbr_size_store(struct config_item *item,
} }
CONFIGFS_ATTR_WO(mdev_link_, create_link); CONFIGFS_ATTR_WO(mdev_link_, create_link);
CONFIGFS_ATTR_WO(mdev_link_, destroy_link);
CONFIGFS_ATTR(mdev_link_, device); CONFIGFS_ATTR(mdev_link_, device);
CONFIGFS_ATTR(mdev_link_, channel); CONFIGFS_ATTR(mdev_link_, channel);
CONFIGFS_ATTR(mdev_link_, comp); CONFIGFS_ATTR(mdev_link_, comp);
...@@ -340,6 +363,7 @@ CONFIGFS_ATTR(mdev_link_, dbr_size); ...@@ -340,6 +363,7 @@ CONFIGFS_ATTR(mdev_link_, dbr_size);
static struct configfs_attribute *mdev_link_attrs[] = { static struct configfs_attribute *mdev_link_attrs[] = {
&mdev_link_attr_create_link, &mdev_link_attr_create_link,
&mdev_link_attr_destroy_link,
&mdev_link_attr_device, &mdev_link_attr_device,
&mdev_link_attr_channel, &mdev_link_attr_channel,
&mdev_link_attr_comp, &mdev_link_attr_comp,
...@@ -356,6 +380,16 @@ static struct configfs_attribute *mdev_link_attrs[] = { ...@@ -356,6 +380,16 @@ static struct configfs_attribute *mdev_link_attrs[] = {
static void mdev_link_release(struct config_item *item) 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->device, 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)); kfree(to_mdev_link(item));
} }
......
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