devlink: Create generic devlink health reporter search function
authorVladyslav Tarasiuk <vladyslavt@mellanox.com>
Fri, 10 Jul 2020 12:25:09 +0000 (15:25 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 10 Jul 2020 21:32:02 +0000 (14:32 -0700)
Add a generic __devlink_health_reporter_find_by_name() that can be used
with arbitrary devlink health reporter list.

Signed-off-by: Vladyslav Tarasiuk <vladyslavt@mellanox.com>
Reviewed-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/devlink.c

index b85f2113398d87de1026ffce74f4e2c4dc1e6b8d..4e995de65b36d109eb8db9a8856085eea2563cc5 100644 (file)
@@ -5309,18 +5309,28 @@ devlink_health_reporter_priv(struct devlink_health_reporter *reporter)
 EXPORT_SYMBOL_GPL(devlink_health_reporter_priv);
 
 static struct devlink_health_reporter *
-devlink_health_reporter_find_by_name(struct devlink *devlink,
-                                    const char *reporter_name)
+__devlink_health_reporter_find_by_name(struct list_head *reporter_list,
+                                      struct mutex *list_lock,
+                                      const char *reporter_name)
 {
        struct devlink_health_reporter *reporter;
 
-       lockdep_assert_held(&devlink->reporters_lock);
-       list_for_each_entry(reporter, &devlink->reporter_list, list)
+       lockdep_assert_held(list_lock);
+       list_for_each_entry(reporter, reporter_list, list)
                if (!strcmp(reporter->ops->name, reporter_name))
                        return reporter;
        return NULL;
 }
 
+static struct devlink_health_reporter *
+devlink_health_reporter_find_by_name(struct devlink *devlink,
+                                    const char *reporter_name)
+{
+       return __devlink_health_reporter_find_by_name(&devlink->reporter_list,
+                                                     &devlink->reporters_lock,
+                                                     reporter_name);
+}
+
 static struct devlink_health_reporter *
 __devlink_health_reporter_create(struct devlink *devlink,
                                 const struct devlink_health_reporter_ops *ops,