lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220706104024.3118590-3-pawel.kallas@intel.com>
Date:   Wed,  6 Jul 2022 12:40:23 +0200
From:   "Kallas, Pawel" <pawel.kallas@...el.com>
To:     linux@...ck-us.net, jdelvare@...e.com, corbet@....net,
        linux-hwmon@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-doc@...r.kernel.org
Cc:     iwona.winiarska@...el.com, pawel.kallas@...el.com
Subject: [PATCH 2/3] hwmon: (pmbus) refactor sensor initialization

Introduce separate function to initialize pmbus sensor attributes.
It can be used to initialize different sensor types.

Signed-off-by: Kallas, Pawel <pawel.kallas@...el.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 37 ++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 4bcb70ab9b598..6e3ec6a223b92 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -1168,6 +1168,26 @@ static int pmbus_add_boolean(struct pmbus_data *data,
 	return pmbus_add_attribute(data, &a->dev_attr.attr);
 }
 
+static void pmbus_sensor_init(struct pmbus_sensor *sensor, const char *name, const char *type,
+			      int seq, int page, int phase, int reg,
+			      enum pmbus_sensor_classes class, bool update, bool convert)
+{
+	if (type)
+		snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s",
+			 name, seq, type);
+	else
+		snprintf(sensor->name, sizeof(sensor->name), "%s%d",
+			 name, seq);
+
+	sensor->page = page;
+	sensor->phase = phase;
+	sensor->reg = reg;
+	sensor->class = class;
+	sensor->update = update;
+	sensor->convert = convert;
+	sensor->data = -ENODATA;
+}
+
 static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
 					     const char *name, const char *type,
 					     int seq, int page, int phase,
@@ -1182,25 +1202,14 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
 	sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
 	if (!sensor)
 		return NULL;
-	a = &sensor->attribute;
 
-	if (type)
-		snprintf(sensor->name, sizeof(sensor->name), "%s%d_%s",
-			 name, seq, type);
-	else
-		snprintf(sensor->name, sizeof(sensor->name), "%s%d",
-			 name, seq);
+	pmbus_sensor_init(sensor, name, type, seq, page, phase, reg, class, update, convert);
 
 	if (data->flags & PMBUS_WRITE_PROTECTED)
 		readonly = true;
 
-	sensor->page = page;
-	sensor->phase = phase;
-	sensor->reg = reg;
-	sensor->class = class;
-	sensor->update = update;
-	sensor->convert = convert;
-	sensor->data = -ENODATA;
+	a = &sensor->attribute;
+
 	pmbus_dev_attr_init(a, sensor->name,
 			    readonly ? 0444 : 0644,
 			    pmbus_show_sensor, pmbus_set_sensor);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ