2023-11-20 19:43:45

by Naresh Solanki

[permalink] [raw]
Subject: [PATCH v1] regulator: event: Add regulator netlink event support

Signed-off-by: Naresh Solanki <[email protected]>
---
drivers/regulator/Makefile | 1 +
drivers/regulator/core.c | 7 +-
drivers/regulator/event.c | 135 +++++++++++++++++++++++++++++++++++++
drivers/regulator/regnl.h | 8 +++
4 files changed, 150 insertions(+), 1 deletion(-)
create mode 100644 drivers/regulator/event.c
create mode 100644 drivers/regulator/regnl.h

diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index b2b059b5ee56..de37144e4784 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -5,6 +5,7 @@


obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o irq_helpers.o
+obj-$(CONFIG_REGULATOR) += event.o
obj-$(CONFIG_OF) += of_regulator.o
obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 4aa9ec8c22f3..384ffe8618fd 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -33,6 +33,7 @@

#include "dummy.h"
#include "internal.h"
+#include "regnl.h"

static DEFINE_WW_CLASS(regulator_ww_class);
static DEFINE_MUTEX(regulator_nesting_mutex);
@@ -4854,7 +4855,11 @@ static int _notifier_call_chain(struct regulator_dev *rdev,
unsigned long event, void *data)
{
/* call rdev chain first */
- return blocking_notifier_call_chain(&rdev->notifier, event, data);
+ int ret = blocking_notifier_call_chain(&rdev->notifier, event, data);
+
+ reg_generate_netlink_event(rdev_get_name(rdev), event);
+
+ return ret;
}

int _regulator_bulk_get(struct device *dev, int num_consumers,
diff --git a/drivers/regulator/event.c b/drivers/regulator/event.c
new file mode 100644
index 000000000000..ba72a705f09e
--- /dev/null
+++ b/drivers/regulator/event.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <net/netlink.h>
+#include <net/genetlink.h>
+
+#include "regnl.h"
+
+#ifdef CONFIG_NET
+static unsigned int reg_event_seqnum;
+struct reg_genl_event {
+ char reg_name[15];
+ u64 event;
+};
+
+/* attributes of reg_genl_family */
+enum {
+ REG_GENL_ATTR_UNSPEC,
+ REG_GENL_ATTR_EVENT, /* reg event info needed by user space */
+ __REG_GENL_ATTR_MAX,
+};
+
+#define REG_GENL_ATTR_MAX (__REG_GENL_ATTR_MAX - 1)
+
+/* commands supported by the reg_genl_family */
+enum {
+ REG_GENL_CMD_UNSPEC,
+ REG_GENL_CMD_EVENT, /* kernel->user notifications for reg events */
+ __REG_GENL_CMD_MAX,
+};
+
+#define REG_GENL_CMD_MAX (__REG_GENL_CMD_MAX - 1)
+
+#define REG_GENL_FAMILY_NAME "reg_event"
+#define REG_GENL_VERSION 0x01
+#define REG_GENL_MCAST_GROUP_NAME "reg_mc_group"
+
+static const struct genl_multicast_group reg_event_mcgrps[] = {
+ { .name = REG_GENL_MCAST_GROUP_NAME, },
+};
+
+static struct genl_family reg_event_genl_family __ro_after_init = {
+ .module = THIS_MODULE,
+ .name = REG_GENL_FAMILY_NAME,
+ .version = REG_GENL_VERSION,
+ .maxattr = REG_GENL_ATTR_MAX,
+ .mcgrps = reg_event_mcgrps,
+ .n_mcgrps = ARRAY_SIZE(reg_event_mcgrps),
+};
+
+int reg_generate_netlink_event(const char *reg_name, u64 event)
+{
+ struct sk_buff *skb;
+ struct nlattr *attr;
+ struct reg_genl_event *edata;
+ void *msg_header;
+ int size;
+
+ /* allocate memory */
+ size = nla_total_size(sizeof(struct reg_genl_event)) +
+ nla_total_size(0);
+
+ skb = genlmsg_new(size, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ /* add the genetlink message header */
+ msg_header = genlmsg_put(skb, 0, reg_event_seqnum++,
+ &reg_event_genl_family, 0,
+ REG_GENL_CMD_EVENT);
+ if (!msg_header) {
+ nlmsg_free(skb);
+ return -ENOMEM;
+ }
+
+ /* fill the data */
+ attr = nla_reserve(skb, REG_GENL_ATTR_EVENT, sizeof(struct reg_genl_event));
+ if (!attr) {
+ nlmsg_free(skb);
+ return -EINVAL;
+ }
+
+ edata = nla_data(attr);
+ memset(edata, 0, sizeof(struct reg_genl_event));
+
+ strscpy(edata->reg_name, reg_name, sizeof(edata->reg_name));
+ edata->event = event;
+
+ /* send multicast genetlink message */
+ genlmsg_end(skb, msg_header);
+ size = genlmsg_multicast(&reg_event_genl_family, skb, 0, 0, GFP_ATOMIC);
+
+ pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
+ if (size == -ESRCH)
+ pr_debug("multicast message sent, but nobody was listening...\n");
+ else if (size)
+ pr_debug("failed to send multicast genl message\n");
+ else
+ pr_debug("multicast message sent %d\n", reg_event_seqnum);
+
+ return 0;
+}
+EXPORT_SYMBOL(reg_generate_netlink_event);
+
+static int __init reg_event_genetlink_init(void)
+{
+ return genl_register_family(&reg_event_genl_family);
+}
+
+#else
+int reg_generate_netlink_event(const char *device_class, const char *bus_id, u8 type, int data)
+{
+ return 0;
+}
+EXPORT_SYMBOL(reg_generate_netlink_event);
+
+static int reg_event_genetlink_init(void)
+{
+ return -ENODEV;
+}
+#endif
+
+static int __init reg_event_init(void)
+{
+ int error;
+
+ /* create genetlink for acpi event */
+ error = reg_event_genetlink_init();
+ dev_err(NULL, "%s Loaded", __func__);
+ if (error)
+ pr_warn("Failed to create genetlink family for reg event\n");
+
+ return 0;
+}
+
+fs_initcall(reg_event_init);
diff --git a/drivers/regulator/regnl.h b/drivers/regulator/regnl.h
new file mode 100644
index 000000000000..0b27972bd523
--- /dev/null
+++ b/drivers/regulator/regnl.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __REGULATOR_EVENT_H
+#define __REGULATOR_EVENT_H
+
+int reg_generate_netlink_event(const char *reg_name, u64 event);
+
+#endif

base-commit: 753e4d5c433da57da75dd4c3e1aececc8e874a62
--
2.41.0


2023-11-21 04:33:17

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1] regulator: event: Add regulator netlink event support

Hi Naresh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 753e4d5c433da57da75dd4c3e1aececc8e874a62]

url: https://github.com/intel-lab-lkp/linux/commits/Naresh-Solanki/regulator-event-Add-regulator-netlink-event-support/20231121-034604
base: 753e4d5c433da57da75dd4c3e1aececc8e874a62
patch link: https://lore.kernel.org/r/20231120194311.3581036-1-naresh.solanki%409elements.com
patch subject: [PATCH v1] regulator: event: Add regulator netlink event support
config: arm-randconfig-003-20231121 (https://download.01.org/0day-ci/archive/20231121/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231121/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:31,
from include/linux/skbuff.h:13,
from include/linux/netlink.h:7,
from include/net/netlink.h:6,
from drivers/regulator/event.c:3:
drivers/regulator/event.c: In function 'reg_generate_netlink_event':
>> drivers/regulator/event.c:92:18: warning: format '%lx' expects argument of type 'long unsigned int', but argument 4 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/printk.h:345:21: note: in definition of macro 'pr_fmt'
345 | #define pr_fmt(fmt) fmt
| ^~~
include/linux/dynamic_debug.h:248:9: note: in expansion of macro '__dynamic_func_call_cls'
248 | __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:250:9: note: in expansion of macro '_dynamic_func_call_cls'
250 | _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:269:9: note: in expansion of macro '_dynamic_func_call'
269 | _dynamic_func_call(fmt, __dynamic_pr_debug, \
| ^~~~~~~~~~~~~~~~~~
include/linux/printk.h:579:9: note: in expansion of macro 'dynamic_pr_debug'
579 | dynamic_pr_debug(fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~
drivers/regulator/event.c:92:9: note: in expansion of macro 'pr_debug'
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ^~~~~~~~
drivers/regulator/event.c:92:27: note: format string is defined here
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ~~^
| |
| long unsigned int
| %llx
>> drivers/regulator/event.c:92:18: warning: format '%x' expects a matching 'unsigned int' argument [-Wformat=]
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/printk.h:345:21: note: in definition of macro 'pr_fmt'
345 | #define pr_fmt(fmt) fmt
| ^~~
include/linux/dynamic_debug.h:248:9: note: in expansion of macro '__dynamic_func_call_cls'
248 | __dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:250:9: note: in expansion of macro '_dynamic_func_call_cls'
250 | _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~
include/linux/dynamic_debug.h:269:9: note: in expansion of macro '_dynamic_func_call'
269 | _dynamic_func_call(fmt, __dynamic_pr_debug, \
| ^~~~~~~~~~~~~~~~~~
include/linux/printk.h:579:9: note: in expansion of macro 'dynamic_pr_debug'
579 | dynamic_pr_debug(fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~
drivers/regulator/event.c:92:9: note: in expansion of macro 'pr_debug'
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ^~~~~~~~
drivers/regulator/event.c:92:40: note: format string is defined here
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ~^
| |
| unsigned int


vim +92 drivers/regulator/event.c

49
50 int reg_generate_netlink_event(const char *reg_name, u64 event)
51 {
52 struct sk_buff *skb;
53 struct nlattr *attr;
54 struct reg_genl_event *edata;
55 void *msg_header;
56 int size;
57
58 /* allocate memory */
59 size = nla_total_size(sizeof(struct reg_genl_event)) +
60 nla_total_size(0);
61
62 skb = genlmsg_new(size, GFP_ATOMIC);
63 if (!skb)
64 return -ENOMEM;
65
66 /* add the genetlink message header */
67 msg_header = genlmsg_put(skb, 0, reg_event_seqnum++,
68 &reg_event_genl_family, 0,
69 REG_GENL_CMD_EVENT);
70 if (!msg_header) {
71 nlmsg_free(skb);
72 return -ENOMEM;
73 }
74
75 /* fill the data */
76 attr = nla_reserve(skb, REG_GENL_ATTR_EVENT, sizeof(struct reg_genl_event));
77 if (!attr) {
78 nlmsg_free(skb);
79 return -EINVAL;
80 }
81
82 edata = nla_data(attr);
83 memset(edata, 0, sizeof(struct reg_genl_event));
84
85 strscpy(edata->reg_name, reg_name, sizeof(edata->reg_name));
86 edata->event = event;
87
88 /* send multicast genetlink message */
89 genlmsg_end(skb, msg_header);
90 size = genlmsg_multicast(&reg_event_genl_family, skb, 0, 0, GFP_ATOMIC);
91
> 92 pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
93 if (size == -ESRCH)
94 pr_debug("multicast message sent, but nobody was listening...\n");
95 else if (size)
96 pr_debug("failed to send multicast genl message\n");
97 else
98 pr_debug("multicast message sent %d\n", reg_event_seqnum);
99
100 return 0;
101 }
102 EXPORT_SYMBOL(reg_generate_netlink_event);
103

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2023-11-21 05:54:51

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1] regulator: event: Add regulator netlink event support

Hi Naresh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 753e4d5c433da57da75dd4c3e1aececc8e874a62]

url: https://github.com/intel-lab-lkp/linux/commits/Naresh-Solanki/regulator-event-Add-regulator-netlink-event-support/20231121-034604
base: 753e4d5c433da57da75dd4c3e1aececc8e874a62
patch link: https://lore.kernel.org/r/20231120194311.3581036-1-naresh.solanki%409elements.com
patch subject: [PATCH v1] regulator: event: Add regulator netlink event support
config: x86_64-buildonly-randconfig-001-20231121 (https://download.01.org/0day-ci/archive/20231121/[email protected]/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231121/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:31,
from include/linux/skbuff.h:13,
from include/linux/netlink.h:7,
from include/net/netlink.h:6,
from drivers/regulator/event.c:3:
drivers/regulator/event.c: In function 'reg_generate_netlink_event':
>> include/linux/kern_levels.h:5:18: warning: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:427:11: note: in definition of macro 'printk_index_wrap'
427 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:129:3: note: in expansion of macro 'printk'
129 | printk(fmt, ##__VA_ARGS__); \
| ^~~~~~
include/linux/printk.h:585:2: note: in expansion of macro 'no_printk'
585 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~
include/linux/kern_levels.h:15:20: note: in expansion of macro 'KERN_SOH'
15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
| ^~~~~~~~
include/linux/printk.h:585:12: note: in expansion of macro 'KERN_DEBUG'
585 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
drivers/regulator/event.c:92:2: note: in expansion of macro 'pr_debug'
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ^~~~~~~~
drivers/regulator/event.c:92:20: note: format string is defined here
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ~~^
| |
| long unsigned int
| %llx
In file included from include/linux/kernel.h:31,
from include/linux/skbuff.h:13,
from include/linux/netlink.h:7,
from include/net/netlink.h:6,
from drivers/regulator/event.c:3:
>> include/linux/kern_levels.h:5:18: warning: format '%x' expects a matching 'unsigned int' argument [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:427:11: note: in definition of macro 'printk_index_wrap'
427 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:129:3: note: in expansion of macro 'printk'
129 | printk(fmt, ##__VA_ARGS__); \
| ^~~~~~
include/linux/printk.h:585:2: note: in expansion of macro 'no_printk'
585 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~
include/linux/kern_levels.h:15:20: note: in expansion of macro 'KERN_SOH'
15 | #define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
| ^~~~~~~~
include/linux/printk.h:585:12: note: in expansion of macro 'KERN_DEBUG'
585 | no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~~~
drivers/regulator/event.c:92:2: note: in expansion of macro 'pr_debug'
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ^~~~~~~~
drivers/regulator/event.c:92:33: note: format string is defined here
92 | pr_debug("%s -> %lx , ret: %x %x", reg_name, event, size);
| ~^
| |
| unsigned int


vim +5 include/linux/kern_levels.h

314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2023-11-21 08:48:01

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v1] regulator: event: Add regulator netlink event support

Hi Naresh,

kernel test robot noticed the following build errors:

[auto build test ERROR on 753e4d5c433da57da75dd4c3e1aececc8e874a62]

url: https://github.com/intel-lab-lkp/linux/commits/Naresh-Solanki/regulator-event-Add-regulator-netlink-event-support/20231121-034604
base: 753e4d5c433da57da75dd4c3e1aececc8e874a62
patch link: https://lore.kernel.org/r/20231120194311.3581036-1-naresh.solanki%409elements.com
patch subject: [PATCH v1] regulator: event: Add regulator netlink event support
config: loongarch-randconfig-r071-20231121 (https://download.01.org/0day-ci/archive/20231121/[email protected]/config)
compiler: loongarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231121/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/regulator/event.c:110:5: error: conflicting types for 'reg_generate_netlink_event'; have 'int(const char *, const char *, u8, int)' {aka 'int(const char *, const char *, unsigned char, int)'}
110 | int reg_generate_netlink_event(const char *device_class, const char *bus_id, u8 type, int data)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from drivers/regulator/event.c:6:
drivers/regulator/regnl.h:6:5: note: previous declaration of 'reg_generate_netlink_event' with type 'int(const char *, u64)' {aka 'int(const char *, long long unsigned int)'}
6 | int reg_generate_netlink_event(const char *reg_name, u64 event);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from include/linux/linkage.h:7,
from include/linux/kernel.h:18,
from include/linux/skbuff.h:13,
from include/linux/netlink.h:7,
from include/net/netlink.h:6,
from drivers/regulator/event.c:3:
drivers/regulator/event.c:114:15: error: conflicting types for 'reg_generate_netlink_event'; have 'int(const char *, const char *, u8, int)' {aka 'int(const char *, const char *, unsigned char, int)'}
114 | EXPORT_SYMBOL(reg_generate_netlink_event);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/export.h:74:28: note: in definition of macro '__EXPORT_SYMBOL'
74 | extern typeof(sym) sym; \
| ^~~
include/linux/export.h:86:41: note: in expansion of macro '_EXPORT_SYMBOL'
86 | #define EXPORT_SYMBOL(sym) _EXPORT_SYMBOL(sym, "")
| ^~~~~~~~~~~~~~
drivers/regulator/event.c:114:1: note: in expansion of macro 'EXPORT_SYMBOL'
114 | EXPORT_SYMBOL(reg_generate_netlink_event);
| ^~~~~~~~~~~~~
drivers/regulator/regnl.h:6:5: note: previous declaration of 'reg_generate_netlink_event' with type 'int(const char *, u64)' {aka 'int(const char *, long long unsigned int)'}
6 | int reg_generate_netlink_event(const char *reg_name, u64 event);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~


vim +110 drivers/regulator/event.c

108
109 #else
> 110 int reg_generate_netlink_event(const char *device_class, const char *bus_id, u8 type, int data)
111 {
112 return 0;
113 }
114 EXPORT_SYMBOL(reg_generate_netlink_event);
115

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki