Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1561106 > unrolled thread
| Started by | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| First post | 2017-01-18 00:30 +0100 |
| Last post | 2017-01-18 08:20 +0100 |
| Articles | 8 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Florian Fainelli <f.fainelli@gmail.com> - 2017-01-18 00:30 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-18 00:40 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Florian Fainelli <f.fainelli@gmail.com> - 2017-01-18 01:00 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-18 01:10 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Florian Fainelli <f.fainelli@gmail.com> - 2017-01-18 01:20 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-18 01:10 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Florian Fainelli <f.fainelli@gmail.com> - 2017-01-18 01:10 +0100
Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-18 08:20 +0100
| From | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| Date | 2017-01-18 00:30 +0100 |
| Subject | [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() |
| Message-ID | <t0Lmp-4UR-5@gated-at.bofh.it> |
Add a helper function to lookup a device reference given a class name.
This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and
make it more generic.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/base/core.c | 31 +++++++++++++++++++++++++++++++
include/linux/device.h | 2 ++
2 files changed, 33 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8c25e68e67d7..fb9fced38634 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2058,6 +2058,37 @@ struct device *device_find_child(struct device *parent, void *data,
}
EXPORT_SYMBOL_GPL(device_find_child);
+static int device_class_name_match(struct device *dev, void *class)
+{
+ if (dev->class != NULL && !strcmp(dev->class->name, class))
+ return 1;
+
+ return 0;
+}
+
+/**
+ * device_find_in_class_name - device iterator for locating a particular device
+ * within the specified class name
+ * @parent: parent struct device
+ * @class_name: Class name to match against
+ *
+ * This function returns 1 if the device (specified by @parent), or one of its child
+ * is in the class whose name is specified by @class_name. Returns 0 otherwise.
+ *
+ * NOTE: you will need to drop the reference with put_device() after use.
+ */
+struct device *device_find_in_class_name(struct device *parent,
+ char *class_name)
+{
+ if (device_class_name_match(parent, class_name)) {
+ get_device(parent);
+ return parent;
+ }
+
+ return device_find_child(parent, class_name, device_class_name_match);
+}
+EXPORT_SYMBOL_GPL(device_find_in_class_name);
+
int __init devices_init(void)
{
devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
diff --git a/include/linux/device.h b/include/linux/device.h
index 491b4c0ca633..fbc2a255f92e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1120,6 +1120,8 @@ extern int device_for_each_child_reverse(struct device *dev, void *data,
int (*fn)(struct device *dev, void *data));
extern struct device *device_find_child(struct device *dev, void *data,
int (*match)(struct device *dev, void *data));
+extern struct device *device_find_in_class_name(struct device *parent,
+ char *class_name);
extern int device_rename(struct device *dev, const char *new_name);
extern int device_move(struct device *dev, struct device *new_parent,
enum dpm_order dpm_order);
--
2.9.3
[toc] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2017-01-18 00:40 +0100 |
| Message-ID | <t0Lw7-4Y5-35@gated-at.bofh.it> |
| In reply to | #1561106 |
On Wed, Jan 18, 2017 at 1:21 AM, Florian Fainelli <f.fainelli@gmail.com> wrote:
> Add a helper function to lookup a device reference given a class name.
> This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and
> make it more generic.
> +static int device_class_name_match(struct device *dev, void *class)
And why not const char *class?
> +{
> + if (dev->class != NULL && !strcmp(dev->class->name, class))
if (dev->class && ...)
> + return 1;
> +
> + return 0;
Perhaps even one line:
return dev->class && ...;
> +}
> +
> +/**
> + * device_find_in_class_name - device iterator for locating a particular device
> + * within the specified class name
> + * @parent: parent struct device
> + * @class_name: Class name to match against
> + *
> + * This function returns 1 if the device (specified by @parent), or one of its child
> + * is in the class whose name is specified by @class_name. Returns 0 otherwise.
> + *
> + * NOTE: you will need to drop the reference with put_device() after use.
> + */
> +struct device *device_find_in_class_name(struct device *parent,
> + char *class_name)
const char *class_name
> +{
> + if (device_class_name_match(parent, class_name)) {
> + get_device(parent);
> + return parent;
> + }
> +
> + return device_find_child(parent, class_name, device_class_name_match);
> +}
> +EXPORT_SYMBOL_GPL(device_find_in_class_name);
> +extern struct device *device_find_in_class_name(struct device *parent,
> + char *class_name);
Ditto.
--
With Best Regards,
Andy Shevchenko
[toc] | [prev] | [next] | [standalone]
| From | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| Date | 2017-01-18 01:00 +0100 |
| Subject | Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() |
| Message-ID | <t0LPs-54F-11@gated-at.bofh.it> |
| In reply to | #1561126 |
On 01/17/2017 03:34 PM, Andy Shevchenko wrote: > On Wed, Jan 18, 2017 at 1:21 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >> Add a helper function to lookup a device reference given a class name. >> This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and >> make it more generic. > > >> +static int device_class_name_match(struct device *dev, void *class) > > And why not const char *class? This was raised back in v2, and the same response applies: https://www.mail-archive.com/netdev@vger.kernel.org/msg147559.html Changing the signature of a callback is out of the scope of this patch series. -- Florian
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2017-01-18 01:10 +0100 |
| Message-ID | <t0LZ8-5nf-49@gated-at.bofh.it> |
| In reply to | #1561136 |
On Wed, Jan 18, 2017 at 2:04 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: > On 01/17/2017 04:00 PM, Andy Shevchenko wrote: >> On Wed, Jan 18, 2017 at 1:43 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >>> On 01/17/2017 03:34 PM, Andy Shevchenko wrote: >>>> On Wed, Jan 18, 2017 at 1:21 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >> But why not to use void *class_name to be consistent with callback and >> device_find_child()? > > The top-level function: device_find_in_class_name() should have a > stronger typing of its argument even if it internally uses > device_find_child() and a callback that takes a void * argument, that's > how I see it. Fair enough. >> Btw, >> return get_device(parent); > > Not sure I follow what that means here? Missed remark. Instead of get_device(parent); return parent; you can use return get_device(parent); -- With Best Regards, Andy Shevchenko
[toc] | [prev] | [next] | [standalone]
| From | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| Date | 2017-01-18 01:20 +0100 |
| Subject | Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() |
| Message-ID | <t0M8O-5qs-3@gated-at.bofh.it> |
| In reply to | #1561159 |
On 01/17/2017 04:07 PM, Andy Shevchenko wrote: > On Wed, Jan 18, 2017 at 2:04 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >> On 01/17/2017 04:00 PM, Andy Shevchenko wrote: >>> On Wed, Jan 18, 2017 at 1:43 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >>>> On 01/17/2017 03:34 PM, Andy Shevchenko wrote: >>>>> On Wed, Jan 18, 2017 at 1:21 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: > >>> But why not to use void *class_name to be consistent with callback and >>> device_find_child()? >> >> The top-level function: device_find_in_class_name() should have a >> stronger typing of its argument even if it internally uses >> device_find_child() and a callback that takes a void * argument, that's >> how I see it. > > Fair enough. > >>> Btw, >>> return get_device(parent); >> >> Not sure I follow what that means here? > > Missed remark. Instead of > > get_device(parent); > return parent; > > you can use > > return get_device(parent); Seems reasonable, if I have to respin a v5, will add that, thanks! -- Florian
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andy.shevchenko@gmail.com> |
|---|---|
| Date | 2017-01-18 01:10 +0100 |
| Message-ID | <t0LZ8-5nf-51@gated-at.bofh.it> |
| In reply to | #1561136 |
On Wed, Jan 18, 2017 at 1:43 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: > On 01/17/2017 03:34 PM, Andy Shevchenko wrote: >> On Wed, Jan 18, 2017 at 1:21 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >>> +static int device_class_name_match(struct device *dev, void *class) >> >> And why not const char *class? > > This was raised back in v2, and the same response applies: > > https://www.mail-archive.com/netdev@vger.kernel.org/msg147559.html > > Changing the signature of a callback is out of the scope of this patch > series. Ah, right. But why not to use void *class_name to be consistent with callback and device_find_child()? Btw, return get_device(parent); -- With Best Regards, Andy Shevchenko
[toc] | [prev] | [next] | [standalone]
| From | Florian Fainelli <f.fainelli@gmail.com> |
|---|---|
| Date | 2017-01-18 01:10 +0100 |
| Subject | Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() |
| Message-ID | <t0LZ8-5nf-53@gated-at.bofh.it> |
| In reply to | #1561163 |
On 01/17/2017 04:00 PM, Andy Shevchenko wrote: > On Wed, Jan 18, 2017 at 1:43 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: >> On 01/17/2017 03:34 PM, Andy Shevchenko wrote: >>> On Wed, Jan 18, 2017 at 1:21 AM, Florian Fainelli <f.fainelli@gmail.com> wrote: > >>>> +static int device_class_name_match(struct device *dev, void *class) >>> >>> And why not const char *class? >> >> This was raised back in v2, and the same response applies: >> >> https://www.mail-archive.com/netdev@vger.kernel.org/msg147559.html >> >> Changing the signature of a callback is out of the scope of this patch >> series. > > Ah, right. > > But why not to use void *class_name to be consistent with callback and > device_find_child()? The top-level function: device_find_in_class_name() should have a stronger typing of its argument even if it internally uses device_find_child() and a callback that takes a void * argument, that's how I see it. > > Btw, > > return get_device(parent); Not sure I follow what that means here? -- Florian
[toc] | [prev] | [next] | [standalone]
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Date | 2017-01-18 08:20 +0100 |
| Subject | Re: [PATCH net-next v4 05/10] drivers: base: Add device_find_in_class_name() |
| Message-ID | <t0SHf-13d-1@gated-at.bofh.it> |
| In reply to | #1561106 |
On Tue, Jan 17, 2017 at 03:21:47PM -0800, Florian Fainelli wrote: > Add a helper function to lookup a device reference given a class name. > This is a preliminary patch to remove adhoc code from net/dsa/dsa.c and > make it more generic. > > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> > --- > drivers/base/core.c | 31 +++++++++++++++++++++++++++++++ > include/linux/device.h | 2 ++ > 2 files changed, 33 insertions(+) My NAK still stands here, please give me a day or so to respond to the other thread about this... thanks, greg k-h
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web