Skip to contentSkip to conversation

regulator: event: Add regulator netlink event support

PATCH Superseded Naresh Solanki 2 participants 5 messages Nov 21, 2023 – Nov 27, 2023 Voltage and current regulator framework

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 regulator: event: Add regulator netlink event support

This commit introduces netlink event support to the regulator subsystem.

Changes:
- Introduce event.c and regnl.h for netlink event handling.
- Implement reg_generate_netlink_event to broadcast regulator events.
- Update Makefile to include the new event.c file.

---
 drivers/regulator/Makefile |   1 +
 drivers/regulator/core.c   |   7 +-
 drivers/regulator/event.c  | 134 +++++++++++++++++++++++++++++++++++++
 drivers/regulator/regnl.h  |   8 +++
 4 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 drivers/regulator/event.c
 create mode 100644 drivers/regulator/regnl.h
drivers/regulator/Makefile +1 -0
index b2b059b5ee56..de37144e4784 100644
@@ -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
drivers/regulator/core.c +6 -1
index 4aa9ec8c22f3..384ffe8618fd 100644
@@ -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,
drivers/regulator/event.c new file +134 -0

134 lines not on this page · raw message

drivers/regulator/regnl.h new file +8 -0
new file mode 100644
index 000000000000..0b27972bd523
@@ -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

Signature · 1 line
2.41.0
maintainer
#1 lore raw
Quoted 1 line · Naresh Solanki

This commit introduces netlink event support to the regulator subsystem.

This looks a lot nicer, there's some feedback below but nothing maissively substantial.

Quoted 1 line

+#ifdef CONFIG_NET

This is essentially the entire file - it's probably better to just put the stub functions in the header and do the building with Kconfig.

drivers/regulator/event.c line 13

Quoted 5 lines
drivers/regulator/event.c new file +5 -0
+static unsigned int reg_event_seqnum;
+struct reg_genl_event {
+	char reg_name[15];
+	u64 event;
+};

Given that this is going to get sent to userspace shouldn't it be in a uapi header? Some of the other event types don't seem to do this
though... that might be an issue with those examples though. We'll
also make the event numbers into uapi so they should go in a uapi header as well.

I'm also not clear on where the 15 byte limit comes from.

Quoted 1 line

+EXPORT_SYMBOL(reg_generate_netlink_event);

Everything else in regulator is EXPORT_SYMBOL_GPL() so this should be too - though given that the only caller is _notifier_call_chain() which is in the core does it need to be exported at all? I can't see a case for anything calling it independently of that.

#2 lore raw

Hi Mark,

Quoted 5 lines · Mark Brown
Quoted 1 line · Naresh Solanki

This commit introduces netlink event support to the regulator subsystem.

Quoted 7 lines

This looks a lot nicer, there's some feedback below but nothing maissively substantial.

Quoted 1 line

+#ifdef CONFIG_NET

This is essentially the entire file - it's probably better to just put the stub functions in the header and do the building with Kconfig.

Sure.
As I understood, Will add an option REGULATOR_NETLINK to include the event.c file during build.

Quoted 12 lines

drivers/regulator/event.c line 13

Quoted 6 lines
drivers/regulator/event.c new file +5 -0
+static unsigned int reg_event_seqnum;
+struct reg_genl_event {
+     char reg_name[15];
+     u64 event;
+};

Given that this is going to get sent to userspace shouldn't it be in a uapi header? Some of the other event types don't seem to do this
though... that might be an issue with those examples though. We'll
also make the event numbers into uapi so they should go in a uapi header as well.

Will update next revision to include uapi header.

Quoted 2 lines

I'm also not clear on where the 15 byte limit comes from.

I felt 15 characters would be sufficient for regulator names. Would need your inputs to make sure here.

Quoted 7 lines
Quoted 2 lines

+EXPORT_SYMBOL(reg_generate_netlink_event);

Everything else in regulator is EXPORT_SYMBOL_GPL() so this should be too - though given that the only caller is _notifier_call_chain() which is in the core does it need to be exported at all? I can't see a case for anything calling it independently of that.

Agree. The current scope is limited to regulator core so will remove the export.

Regards,
Naresh

maintainer
#3 lore raw
Quoted 6 lines · Naresh Solanki
Quoted 1 line · Mark Brown

I'm also not clear on where the 15 byte limit comes from.

I felt 15 characters would be sufficient for regulator names. Would need your inputs to make sure here.

It does feel like it might be a bit tight - perhaps double it?

#4 lore raw

Hi Mark,

Quoted 10 lines · Mark Brown
Quoted 6 lines · Naresh Solanki
Quoted 1 line · Mark Brown

I'm also not clear on where the 15 byte limit comes from.

I felt 15 characters would be sufficient for regulator names. Would need your inputs to make sure here.

It does feel like it might be a bit tight - perhaps double it?

Sure. Will change to 32.

Also there is a possibility of regulator name duplication. And below mechanism is already used in debugfs:

        const char *rname = rdev_get_name(rdev);
        char name[NAME_MAX];

        /* Avoid duplicate debugfs directory names */
        if (parent && rname == rdev->desc->name) {
                snprintf(name, sizeof(name), "%s-%s", dev_name(parent),
                         rname);
                rname = name;
        }

I need recommendations here.

Regards,
Naresh