All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Gromm <christian.gromm@microchip.com>
To: gregkh@linuxfoundation.org
Cc: driverdev-devel@linuxdriverproject.org,
	Christian Gromm <christian.gromm@microchip.com>
Subject: [PATCH 19/50] staging: most: core: fix sysfs attribute management
Date: Tue, 21 Nov 2017 15:04:53 +0100	[thread overview]
Message-ID: <1511273124-7840-20-git-send-email-christian.gromm@microchip.com> (raw)
In-Reply-To: <1511273124-7840-1-git-send-email-christian.gromm@microchip.com>

This patch creates a new attribute group to manage the attributes
of a registered aim module in sysfs and changes the show and store
functions accordingly.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
---
 drivers/staging/most/core.c | 109 +++++++++++++++++++++++++++++---------------
 1 file changed, 73 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/most/core.c b/drivers/staging/most/core.c
index b9b9739..7014f6a 100644
--- a/drivers/staging/most/core.c
+++ b/drivers/staging/most/core.c
@@ -540,28 +540,57 @@ static const struct attribute_group *interface_attr_groups[] = {
 /*		     ___     ___
  *		     ___A I M___
  */
-static ssize_t links_show(struct device *dev, struct device_attribute *attr,
-			  char *buf)
+static struct most_aim *match_module(char *name)
+{
+	struct most_aim *aim;
+
+	list_for_each_entry(aim, &mc.mod_list, list) {
+		if (!strcmp(aim->name, name))
+			return aim;
+	}
+	return NULL;
+}
+
+static ssize_t links_show(struct device_driver *drv, char *buf)
 {
 	struct most_channel *c;
 	struct most_inst_obj *i;
-	struct most_aim *aim = to_most_aim(dev);
 	int offs = 0;
 
 	list_for_each_entry(i, &instance_list, list) {
 		list_for_each_entry(c, &i->channel_list, list) {
-			if (c->pipe0.aim == aim || c->pipe1.aim == aim) {
-				offs += snprintf(buf + offs, PAGE_SIZE - offs,
-						 "%s:%s\n",
+			if (c->pipe0.aim) {
+				offs += snprintf(buf + offs,
+						 PAGE_SIZE - offs,
+						 "%s:%s:%s\n",
+						 c->pipe0.aim->name,
+						 dev_name(&i->iface->dev),
+						 dev_name(&c->dev));
+			}
+			if (c->pipe1.aim) {
+				offs += snprintf(buf + offs,
+						 PAGE_SIZE - offs,
+						 "%s:%s:%s\n",
+						 c->pipe1.aim->name,
 						 dev_name(&i->iface->dev),
 						 dev_name(&c->dev));
 			}
 		}
 	}
-
 	return offs;
 }
 
+static ssize_t modules_show(struct device_driver *drv, char *buf)
+{
+	struct most_aim *aim;
+	int offs = 0;
+
+	list_for_each_entry(aim, &mc.mod_list, list) {
+		offs += snprintf(buf + offs, PAGE_SIZE - offs, "%s\n",
+				 aim->name);
+	}
+	return offs;
+}
 /**
  * split_string - parses and changes string in the buffer buf and
  * splits it into two mandatory and one optional substrings.
@@ -584,7 +613,7 @@ static ssize_t links_show(struct device *dev, struct device_attribute *attr,
  * Input: "mdev1:ep81"
  * Output: *a -> "mdev1", *b -> "ep81", *c == NULL
  */
-static int split_string(char *buf, char **a, char **b, char **c)
+static int split_string(char *buf, char **a, char **b, char **c, char **d)
 {
 	*a = strsep(&buf, ":");
 	if (!*a)
@@ -594,8 +623,12 @@ static int split_string(char *buf, char **a, char **b, char **c)
 	if (!*b)
 		return -EIO;
 
-	if (c)
-		*c = strsep(&buf, ":\n");
+	*c = strsep(&buf, ":\n");
+	if (!*c)
+		return -EIO;
+
+	if (d)
+		*d = strsep(&buf, ":\n");
 
 	return 0;
 }
@@ -680,38 +713,38 @@ inline int link_channel_to_aim(struct most_channel *c, struct most_aim *aim,
  * (1) would create the device node /dev/my_rxchannel
  * (2) would create the device node /dev/mdev1-ep81
  */
-static ssize_t add_link_store(struct device *dev,
-			      struct device_attribute *attr,
+static ssize_t add_link_store(struct device_driver *drv,
 			      const char *buf,
 			      size_t len)
 {
 	struct most_channel *c;
-	struct most_aim *aim = to_most_aim(dev);
+	struct most_aim *aim;
 	char buffer[STRING_SIZE];
 	char *mdev;
 	char *mdev_ch;
-	char *mdev_devnod;
+	char *aim_name;
+	char *aim_param;
 	char devnod_buf[STRING_SIZE];
 	int ret;
 	size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
 
 	strlcpy(buffer, buf, max_len);
 
-	ret = split_string(buffer, &mdev, &mdev_ch, &mdev_devnod);
+	ret = split_string(buffer, &mdev, &mdev_ch, &aim_name, &aim_param);
 	if (ret)
 		return ret;
-
-	if (!mdev_devnod || *mdev_devnod == 0) {
+	aim = match_module(aim_name);
+	if (!aim_param || *aim_param == 0) {
 		snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev,
 			 mdev_ch);
-		mdev_devnod = devnod_buf;
+		aim_param = devnod_buf;
 	}
 
 	c = get_channel_by_name(mdev, mdev_ch);
 	if (IS_ERR(c))
 		return -ENODEV;
 
-	ret = link_channel_to_aim(c, aim, mdev_devnod);
+	ret = link_channel_to_aim(c, aim, aim_param);
 	if (ret)
 		return ret;
 
@@ -728,24 +761,24 @@ static ssize_t add_link_store(struct device *dev,
  * Example:
  * echo "mdev0:ep81" >remove_link
  */
-static ssize_t remove_link_store(struct device *dev,
-				 struct device_attribute *attr,
+static ssize_t remove_link_store(struct device_driver *drv,
 				 const char *buf,
 				 size_t len)
 {
 	struct most_channel *c;
-	struct most_aim *aim = to_most_aim(dev);
+	struct most_aim *aim;
 	char buffer[STRING_SIZE];
 	char *mdev;
 	char *mdev_ch;
+	char *aim_name;
 	int ret;
 	size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
 
 	strlcpy(buffer, buf, max_len);
-	ret = split_string(buffer, &mdev, &mdev_ch, NULL);
+	ret = split_string(buffer, &mdev, &mdev_ch, &aim_name, NULL);
 	if (ret)
 		return ret;
-
+	aim = match_module(aim_name);
 	c = get_channel_by_name(mdev, mdev_ch);
 	if (IS_ERR(c))
 		return -ENODEV;
@@ -759,23 +792,27 @@ static ssize_t remove_link_store(struct device *dev,
 	return len;
 }
 
-static DEVICE_ATTR_RO(links);
-static DEVICE_ATTR_WO(add_link);
-static DEVICE_ATTR_WO(remove_link);
+#define DRV_ATTR(_name)  (&driver_attr_##_name.attr)
+
+static DRIVER_ATTR_RO(links);
+static DRIVER_ATTR_RO(modules);
+static DRIVER_ATTR_WO(add_link);
+static DRIVER_ATTR_WO(remove_link);
 
-static struct attribute *aim_attrs[] = {
-	DEV_ATTR(links),
-	DEV_ATTR(add_link),
-	DEV_ATTR(remove_link),
+static struct attribute *module_attrs[] = {
+	DRV_ATTR(links),
+	DRV_ATTR(modules),
+	DRV_ATTR(add_link),
+	DRV_ATTR(remove_link),
 	NULL,
 };
 
-static struct attribute_group aim_attr_group = {
-	.attrs = aim_attrs,
+static struct attribute_group module_attr_group = {
+	.attrs = module_attrs,
 };
 
-static const struct attribute_group *aim_attr_groups[] = {
-	&aim_attr_group,
+static const struct attribute_group *module_attr_groups[] = {
+	&module_attr_group,
 	NULL,
 };
 
@@ -1293,7 +1330,6 @@ int most_register_aim(struct most_aim *aim)
 	aim->dev.init_name = aim->name;
 	aim->dev.bus = &mc.bus;
 	aim->dev.parent = &mc.dev;
-	aim->dev.groups = aim_attr_groups;
 	aim->dev.release = release_aim;
 	ret = device_register(&aim->dev);
 	if (ret) {
@@ -1559,6 +1595,7 @@ static int __init most_init(void)
 	mc.bus.match = most_match,
 	mc.drv.name = "most_core",
 	mc.drv.bus = &mc.bus,
+	mc.drv.groups = module_attr_groups;
 
 	err = bus_register(&mc.bus);
 	if (err) {
-- 
2.7.4

  parent reply	other threads:[~2017-11-21 14:04 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-21 14:04 [PATCH 00/50] staging: most: rework driver architecture and fix defects Christian Gromm
2017-11-21 14:04 ` [PATCH 01/50] staging: most: move core files Christian Gromm
2017-11-21 14:04 ` [PATCH 02/50] staging: most: cdev: rename module Christian Gromm
2017-11-21 14:04 ` [PATCH 03/50] staging: most: i2c: " Christian Gromm
2017-11-21 14:04 ` [PATCH 04/50] staging: most: dim2: " Christian Gromm
2017-11-21 14:04 ` [PATCH 05/50] staging: most: net: " Christian Gromm
2017-11-21 14:04 ` [PATCH 06/50] staging: most: sound: " Christian Gromm
2017-11-21 14:04 ` [PATCH 07/50] staging: most: usb: " Christian Gromm
2017-11-21 14:04 ` [PATCH 08/50] staging: most: video: " Christian Gromm
2017-11-24 15:08   ` Greg KH
2017-11-21 14:04 ` [PATCH 09/50] staging: most: remove proprietary kobjects Christian Gromm
2017-11-24 15:19   ` Greg KH
2017-11-21 14:04 ` [PATCH 10/50] staging: most: core: remove function get_channel_by_iface Christian Gromm
2017-11-22 10:44   ` Frans Klaver
2017-11-21 14:04 ` [PATCH 11/50] staging: most: core: add a match function for the bus Christian Gromm
2017-11-21 14:04 ` [PATCH 12/50] staging: most: core: encapsulate code in function Christian Gromm
2017-11-21 14:04 ` [PATCH 13/50] staging: most: core: rename structure Christian Gromm
2017-11-21 14:04 ` [PATCH 14/50] staging: most: core: rename struct most_c_aim_obj to pipe Christian Gromm
2017-11-21 14:04 ` [PATCH 15/50] staging: most: core: rename struct memeber Christian Gromm
2017-11-21 14:04 ` [PATCH 16/50] staging: most: core: rename members aim* of struct most_channel Christian Gromm
2017-11-21 14:04 ` [PATCH 17/50] staging: most: core: use structure to pack driver specific data Christian Gromm
2017-11-21 14:04 ` [PATCH 18/50] staging: most: core: track aim modules with linked list Christian Gromm
2017-11-21 14:04 ` Christian Gromm [this message]
2017-11-21 14:04 ` [PATCH 20/50] staging: most: core: remove struct device Christian Gromm
2017-11-22 13:01   ` PrasannaKumar Muralidharan
2017-11-24 15:10     ` Greg KH
2017-11-24 15:20       ` Greg KH
2017-11-21 14:04 ` [PATCH 21/50] staging: most: core: rename function Christian Gromm
2017-11-21 14:04 ` [PATCH 22/50] staging: most: core: replace struct most_inst_obj Christian Gromm
2017-11-21 14:04 ` [PATCH 23/50] staging: most: core: put channel name in struct most_channel Christian Gromm
2017-11-21 14:04 ` [PATCH 24/50] staging: most: core: remove context pointer Christian Gromm
2017-11-21 14:04 ` [PATCH 25/50] staging: most: usb: remove pointer initialization Christian Gromm
2017-11-21 14:05 ` [PATCH 26/50] staging: most: rename struct most_aim Christian Gromm
2017-11-22 13:01   ` PrasannaKumar Muralidharan
2017-11-21 14:05 ` [PATCH 27/50] staging: most: rename functions to register a driver with most_core Christian Gromm
2017-11-21 14:05 ` [PATCH 28/50] staging: most: core: rename mod_list Christian Gromm
2017-11-21 14:05 ` [PATCH 29/50] staging: most: core: rename aim variables Christian Gromm
2017-11-21 14:05 ` [PATCH 30/50] staging: most: core: rename function link_channel_to_aim Christian Gromm
2017-11-21 14:05 ` [PATCH 31/50] staging: most: net: remove aim designators Christian Gromm
2017-11-21 14:05 ` [PATCH 32/50] staging: most: sound: remove aim designator Christian Gromm
2017-11-21 14:05 ` [PATCH 33/50] staging: most: video: remove aim designators Christian Gromm
2017-11-21 14:05 ` [PATCH 34/50] staging: most: cdev: rename struct aim_channel Christian Gromm
2017-11-21 14:05 ` [PATCH 35/50] staging: most: cdev: rename variable aim_devno Christian Gromm
2017-11-21 14:05 ` [PATCH 36/50] staging: most: cdev: rename class instance aim_class Christian Gromm
2017-11-21 14:05 ` [PATCH 37/50] staging: most: cdev: rename variable cdev_aim Christian Gromm
2017-11-21 14:05 ` [PATCH 38/50] staging: most: fix comment sections Christian Gromm
2017-11-21 14:05 ` [PATCH 39/50] staging: most: core: denote modules as components Christian Gromm
2017-11-21 14:05 ` [PATCH 40/50] staging: most: core: fix formatting Christian Gromm
2017-11-21 14:05 ` [PATCH 41/50] staging: most: usb: clear functional stall on OUT endpoint Christian Gromm
2017-11-22 13:01   ` PrasannaKumar Muralidharan
2017-11-21 14:05 ` [PATCH 42/50] staging: most: core: fix data type Christian Gromm
2017-11-22 13:02   ` PrasannaKumar Muralidharan
2017-11-24 15:09   ` Greg KH
2017-11-21 14:05 ` [PATCH 43/50] staging: most: core: check value returned by match function Christian Gromm
2017-11-21 14:05 ` [PATCH 44/50] staging: most: update driver usage file Christian Gromm
2017-11-21 14:05 ` [PATCH 45/50] staging: most: cdev: replace function prefix Christian Gromm
2017-11-21 14:05 ` [PATCH 46/50] staging: most: cdev: bundle module variables in structure Christian Gromm
2017-11-21 14:05 ` [PATCH 47/50] staging: most: core: remove class generation Christian Gromm
2017-11-22 13:02   ` PrasannaKumar Muralidharan
2017-11-21 14:05 ` [PATCH 48/50] staging: most: core: fix list traversing Christian Gromm
2017-11-21 14:05 ` [PATCH 49/50] staging: most: add ABI documentation Christian Gromm
2017-11-21 14:05 ` [PATCH 50/50] staging: most: usb: fix show/store function names Christian Gromm
2017-11-22 13:00 ` [PATCH 00/50] staging: most: rework driver architecture and fix defects PrasannaKumar Muralidharan
2017-11-24 15:11   ` Greg KH
2017-11-24 15:31 ` Greg KH
2017-11-24 15:46   ` Christian Gromm
2017-11-27 13:38   ` Christian Gromm
2017-11-27 15:07     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1511273124-7840-20-git-send-email-christian.gromm@microchip.com \
    --to=christian.gromm@microchip.com \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.