netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: netdev@vger.kernel.org, valex@mellanox.com,
	linyunsheng@huawei.com, lihong.yang@intel.com
Subject: Re: [PATCH 08/15] devlink: add devres managed devlinkm_alloc and devlinkm_free
Date: Mon, 3 Feb 2020 12:29:19 +0100	[thread overview]
Message-ID: <20200203112919.GB2260@nanopsycho> (raw)
In-Reply-To: <20200130225913.1671982-9-jacob.e.keller@intel.com>

Thu, Jan 30, 2020 at 11:59:03PM CET, jacob.e.keller@intel.com wrote:
>Add devres managed allocation functions for allocating a devlink
>instance. These can be used by device drivers based on the devres
>framework which want to allocate a devlink instance.
>
>For simplicity and to reduce churn in the devlink core code, the devres
>management works by creating a node with a double-pointer. The devlink
>instance is allocated using the normal devlink_alloc and released using
>the normal devlink_free.
>
>An alternative solution where the raw memory for devlink is allocated
>directly via devres_alloc could be done. Such an implementation would
>either significantly increase code duplication or code churn in order to
>refactor the setup from the allocation.
>
>The new devres managed allocation function will be used by the ice
>driver in a following change to implement initial devlink support.
>
>Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
>---
> include/net/devlink.h |  4 ++++
> lib/devres.c          |  1 +
> net/core/devlink.c    | 54 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 59 insertions(+)
>
>diff --git a/include/net/devlink.h b/include/net/devlink.h
>index 63e954241404..1c3540280396 100644
>--- a/include/net/devlink.h
>+++ b/include/net/devlink.h
>@@ -858,11 +858,15 @@ struct ib_device;
> struct net *devlink_net(const struct devlink *devlink);
> void devlink_net_set(struct devlink *devlink, struct net *net);
> struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
>+struct devlink *devlinkm_alloc(struct device * dev,
>+			       const struct devlink_ops *ops,
>+			       size_t priv_size);
> int devlink_register(struct devlink *devlink, struct device *dev);
> void devlink_unregister(struct devlink *devlink);
> void devlink_reload_enable(struct devlink *devlink);
> void devlink_reload_disable(struct devlink *devlink);
> void devlink_free(struct devlink *devlink);
>+void devlinkm_free(struct device *dev, struct devlink *devlink);
> int devlink_port_register(struct devlink *devlink,
> 			  struct devlink_port *devlink_port,
> 			  unsigned int port_index);
>diff --git a/lib/devres.c b/lib/devres.c
>index 6ef51f159c54..239c81d40612 100644
>--- a/lib/devres.c
>+++ b/lib/devres.c
>@@ -5,6 +5,7 @@
> #include <linux/gfp.h>
> #include <linux/export.h>
> #include <linux/of_address.h>
>+#include <net/devlink.h>
> 
> enum devm_ioremap_type {
> 	DEVM_IOREMAP = 0,
>diff --git a/net/core/devlink.c b/net/core/devlink.c
>index 574008c536fa..b2b855d12a11 100644
>--- a/net/core/devlink.c
>+++ b/net/core/devlink.c
>@@ -6531,6 +6531,60 @@ void devlink_free(struct devlink *devlink)
> }
> EXPORT_SYMBOL_GPL(devlink_free);
> 
>+static void devres_devlink_release(struct device *dev, void *res)
>+{
>+	devlink_free(*(struct devlink **)res);
>+}
>+
>+static int devres_devlink_match(struct device *dev, void *res, void *data)
>+{
>+	return *(struct devlink **)res == data;
>+}
>+
>+/**
>+ * devlinkm_alloc - Allocate devlink instance managed by devres
>+ * @dev: device to allocate devlink for
>+ * @ops: devlink ops structure
>+ * @priv_size: size of private data portion
>+ *
>+ * Allocate a devlink instance and manage its release via devres.
>+ */
>+struct devlink *devlinkm_alloc(struct device *dev,

Why "devlinkm"? Looks like the usual prefix for this is "devm_"
So "devm_devlink_alloc/free"?


>+			       const struct devlink_ops *ops,
>+			       size_t priv_size)
>+{
>+	struct devlink **ptr, *devlink = NULL;
>+
>+	ptr = devres_alloc(devres_devlink_release, sizeof(*ptr), GFP_KERNEL);
>+	if (!ptr)
>+		return NULL;
>+
>+	devlink = devlink_alloc(ops, priv_size);
>+	if (devlink) {
>+		*ptr = devlink;
>+		devres_add(dev, ptr);
>+	} else {
>+		devres_free(ptr);
>+	}
>+
>+	return devlink;
>+}
>+EXPORT_SYMBOL_GPL(devlinkm_alloc);
>+
>+/**
>+ * devlinkm_free - Free devlink instance managed by devres
>+ * @dev: device to remove the allocated devlink from
>+ * @devlink: devlink instance to free
>+ *
>+ * Find and remove the devres node associated with the given devlink.
>+ */
>+void devlinkm_free(struct device *dev, struct devlink *devlink)
>+{
>+	WARN_ON(devres_release(dev, devres_devlink_release,
>+			       devres_devlink_match, devlink));
>+}
>+EXPORT_SYMBOL_GPL(devlinkm_free);
>+
> static void devlink_port_type_warn(struct work_struct *work)
> {
> 	WARN(true, "Type was not set for devlink port.");
>-- 
>2.25.0.rc1
>

  parent reply	other threads:[~2020-02-03 11:29 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 22:58 [RFC PATCH 00/13] devlink direct region reading Jacob Keller
2020-01-30 22:58 ` [PATCH 01/15] devlink: prepare to support region operations Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-02-03 11:35   ` Jiri Pirko
2020-02-03 16:48     ` Jacob Keller
2020-02-03 17:07     ` Jacob Keller
2020-02-03 17:10       ` Jacob Keller
2020-02-03 17:14     ` Jacob Keller
2020-02-03 17:17     ` Jacob Keller
2020-01-30 22:58 ` [PATCH 02/15] devlink: add functions to take snapshot while locked Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:09     ` Jacob Keller
2020-02-03 11:39   ` Jiri Pirko
2020-02-03 16:45     ` Jacob Keller
2020-01-30 22:58 ` [PATCH 03/15] devlink: add operation to take an immediate snapshot Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-02-03  8:19   ` Yunsheng Lin
2020-02-03 11:50     ` Jiri Pirko
2020-02-03 11:50   ` Jiri Pirko
2020-02-03 16:33     ` Jacob Keller
2020-02-03 19:32     ` Jacob Keller
2020-02-03 21:30       ` Jiri Pirko
2020-02-04 19:20         ` Jacob Keller
2020-01-30 22:58 ` [PATCH 04/15] netdevsim: support taking immediate snapshot via devlink Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:12     ` Jacob Keller
2020-01-30 22:59 ` [PATCH 05/15] ice: use __le16 types for explicitly Little Endian values Jacob Keller
2020-01-30 22:59 ` [PATCH 06/15] ice: create function to read a section of the NVM and Shadow RAM Jacob Keller
2020-01-30 22:59 ` [PATCH 07/15] ice: implement full NVM read from ETHTOOL_GEEPROM Jacob Keller
2020-01-30 22:59 ` [PATCH 08/15] devlink: add devres managed devlinkm_alloc and devlinkm_free Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:16     ` Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-02-01  0:51     ` Jacob Keller
2020-02-01 17:43       ` Jakub Kicinski
2020-02-03 16:35         ` Jacob Keller
2020-02-03 11:29   ` Jiri Pirko [this message]
2020-02-03 16:56     ` Jacob Keller
2020-01-30 22:59 ` [PATCH 09/15] ice: enable initial devlink support Jacob Keller
2020-01-30 22:59 ` [PATCH 10/15] ice: add basic handler for devlink .info_get Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:25     ` Jacob Keller
2020-01-30 22:59 ` [PATCH 11/15] ice: add board identifier info to " Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:26     ` Jacob Keller
2020-01-30 22:59 ` [PATCH 12/15] ice: add a devlink region to dump shadow RAM contents Jacob Keller
2020-01-30 22:59 ` [PATCH 13/15] devlink: support directly reading from region memory Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:27     ` Jacob Keller
2020-01-31 19:15     ` Jacob Keller
2020-02-03 13:44   ` Jiri Pirko
2020-02-03 16:40     ` Jacob Keller
2020-01-30 22:59 ` [PATCH 14/15] ice: support direct read of the shadow ram region Jacob Keller
2020-01-30 22:59 ` [PATCH 15/15] ice: add ice.rst devlink documentation file Jacob Keller
2020-01-31 18:07   ` Jakub Kicinski
2020-01-31 18:28     ` Jacob Keller
2020-01-30 22:59 ` [RFC PATCH 1/3] Update kernel headers Jacob Keller
2020-01-30 22:59 ` [RFC PATCH 2/3] devlink: add support for DEVLINK_CMD_REGION_TAKE_SNAPSHOT Jacob Keller
2020-01-30 22:59 ` [RFC PATCH 3/3] devlink: stop requiring snapshot for regions Jacob Keller
2020-01-30 23:03 ` [RFC PATCH 00/13] devlink direct region reading Jacob Keller
2020-01-31 18:06 ` Jakub Kicinski
2020-01-31 18:09   ` Jacob Keller

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=20200203112919.GB2260@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=jacob.e.keller@intel.com \
    --cc=lihong.yang@intel.com \
    --cc=linyunsheng@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=valex@mellanox.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).