Skip to content

Commit d499436

Browse files
author
CKI Backport Bot
committed
hwmon: Add static visibility member to struct hwmon_ops
JIRA: https://issues.redhat.com/browse/RHEL-105091 commit 79bc0af Author: Heiner Kallweit <hkallweit1@gmail.com> Date: Thu Oct 10 21:35:42 2024 +0200 hwmon: Add static visibility member to struct hwmon_ops Several drivers return the same static value in their is_visible callback, what results in code duplication. Therefore add an option for drivers to specify a static visibility directly. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Message-ID: <89690b81-2c73-47ae-9ae9-45c77b45ca0c@gmail.com> groeck: Renamed hwmon_ops_is_visible -> hwmon_is_visible Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 234e7c1 commit d499436

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

drivers/hwmon/hwmon.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ static const struct class hwmon_class = {
145145

146146
static DEFINE_IDA(hwmon_ida);
147147

148+
static umode_t hwmon_is_visible(const struct hwmon_ops *ops,
149+
const void *drvdata,
150+
enum hwmon_sensor_types type,
151+
u32 attr, int channel)
152+
{
153+
if (ops->visible)
154+
return ops->visible;
155+
156+
return ops->is_visible(drvdata, type, attr, channel);
157+
}
158+
148159
/* Thermal zone handling */
149160

150161
/*
@@ -267,8 +278,8 @@ static int hwmon_thermal_register_sensors(struct device *dev)
267278
int err;
268279

269280
if (!(info[i]->config[j] & HWMON_T_INPUT) ||
270-
!chip->ops->is_visible(drvdata, hwmon_temp,
271-
hwmon_temp_input, j))
281+
!hwmon_is_visible(chip->ops, drvdata, hwmon_temp,
282+
hwmon_temp_input, j))
272283
continue;
273284

274285
err = hwmon_thermal_add_sensor(dev, j);
@@ -506,7 +517,7 @@ static struct attribute *hwmon_genattr(const void *drvdata,
506517
const char *name;
507518
bool is_string = is_string_attr(type, attr);
508519

509-
mode = ops->is_visible(drvdata, type, attr, index);
520+
mode = hwmon_is_visible(ops, drvdata, type, attr, index);
510521
if (!mode)
511522
return ERR_PTR(-ENOENT);
512523

@@ -1033,7 +1044,7 @@ hwmon_device_register_with_info(struct device *dev, const char *name,
10331044
if (!dev || !name || !chip)
10341045
return ERR_PTR(-EINVAL);
10351046

1036-
if (!chip->ops || !chip->ops->is_visible || !chip->info)
1047+
if (!chip->ops || !(chip->ops->visible || chip->ops->is_visible) || !chip->info)
10371048
return ERR_PTR(-EINVAL);
10381049

10391050
return __hwmon_device_register(dev, name, drvdata, chip, extra_groups);

include/linux/hwmon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ enum hwmon_intrusion_attributes {
368368

369369
/**
370370
* struct hwmon_ops - hwmon device operations
371-
* @is_visible: Callback to return attribute visibility. Mandatory.
371+
* @visible: Static visibility. If non-zero, 'is_visible' is ignored.
372+
* @is_visible: Callback to return attribute visibility. Mandatory unless
373+
* 'visible' is non-zero.
372374
* Parameters are:
373375
* @const void *drvdata:
374376
* Pointer to driver-private data structure passed
@@ -412,6 +414,7 @@ enum hwmon_intrusion_attributes {
412414
* The function returns 0 on success or a negative error number.
413415
*/
414416
struct hwmon_ops {
417+
umode_t visible;
415418
umode_t (*is_visible)(const void *drvdata, enum hwmon_sensor_types type,
416419
u32 attr, int channel);
417420
int (*read)(struct device *dev, enum hwmon_sensor_types type,

0 commit comments

Comments
 (0)