dt-bindings: hwmon: chipcap2: Add label property
PATCH v2 1/2 dt-bindings: hwmon: chipcap2: Add label property
Add support for an optional label property similar to other hwmon devices. This allows, in case of boards with multiple CHIPCAP2 sensors, to assign distinct names to each instance.
---
Changes in v2:
- Implement suggestion from Javier Carrasco as proposed by Krzysztof Kozlowski.
- Link to v1: https://lore.kernel.org/all/[email protected]/
.../devicetree/bindings/hwmon/amphenol,chipcap2.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml +6 -0
@@ -45,6 +45,8 @@ properties: - const: low - const: high + label: true + vdd-supply: description: Dedicated, controllable supply-regulator to reset the device and
@@ -55,6 +57,9 @@ required: - reg - vdd-supply +allOf: + - $ref: hwmon-common.yaml# + additionalProperties: false examples:
@@ -72,6 +77,7 @@ examples: <5 IRQ_TYPE_EDGE_RISING>, <6 IRQ_TYPE_EDGE_RISING>; interrupt-names = "ready", "low", "high"; + label = "Room"; vdd-supply = <®_vdd>; }; };
Signature · 1 line
2.34.1
PATCH v2 2/2 hwmon: (chipcap2) Add support for label
Add support for label sysfs attribute similar to other hwmon devices. This is particularly useful for systems with multiple sensors on the same board, where identifying individual sensors is much easier since labels can be defined via device tree.
---
Changes in v2:
- No change for this patch in the patch series.
- Link to v1: https://lore.kernel.org/all/[email protected]/
Documentation/hwmon/chipcap2.rst | 2 ++ drivers/hwmon/chipcap2.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
Documentation/hwmon/chipcap2.rst +2 -0
@@ -70,4 +70,6 @@ humidity1_min_hyst: RW humidity low hystersis humidity1_max_hyst: RW humidity high hystersis humidity1_min_alarm: RO humidity low alarm indicator humidity1_max_alarm: RO humidity high alarm indicator +humidity1_label: RO descriptive name for the sensor +temp1_label: RO descriptive name for the sensor =============================== ======= ========================================
drivers/hwmon/chipcap2.c +23 -2
@@ -22,6 +22,8 @@#include <linux/irq.h> #include <linux/module.h> #include <linux/regulator/consumer.h> +#include <linux/mod_devicetable.h> +#include <linux/property.h> #define CC2_START_CM 0xA0#define CC2_START_NOM 0x80
@@ -83,6 +85,7 @@ struct cc2_data {struct i2c_client *client;struct regulator *regulator;const char *name; +const char *label;int irq_ready;int irq_low;int irq_high;
@@ -449,6 +452,8 @@ static umode_t cc2_is_visible(const void *data, enum hwmon_sensor_types type,switch (attr) {case hwmon_humidity_input:return 0444 ; +case hwmon_humidity_label: +return cc2->label ?0444 :0 ;case hwmon_humidity_min_alarm:return cc2->rh_alarm.low_alarm_visible ?0444 :0 ;case hwmon_humidity_max_alarm:
@@ -466,6 +471,8 @@ static umode_t cc2_is_visible(const void *data, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:return 0444 ; +case hwmon_temp_label: +return cc2->label ?0444 :0 ;default :return 0 ; }
@@ -552,6 +559,16 @@ static int cc2_humidity_max_alarm_status(struct cc2_data *data, long *val)return 0 ; } +static int cc2_read_string (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,const char **str) +{ +struct cc2_data *data =dev_get_drvdata (dev); + + *str = data->label; + +return 0 ; +} +static int cc2_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) {
@@ -670,8 +687,9 @@ static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) }static const struct hwmon_channel_info *cc2_info[] = { -HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT ), -HWMON_CHANNEL_INFO (humidity,HWMON_H_INPUT |HWMON_H_MIN |HWMON_H_MAX | +HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT |HWMON_T_LABEL ), +HWMON_CHANNEL_INFO (humidity,HWMON_H_INPUT |HWMON_H_LABEL | +HWMON_H_MIN |HWMON_H_MAX |HWMON_H_MIN_HYST |HWMON_H_MAX_HYST |HWMON_H_MIN_ALARM |HWMON_H_MAX_ALARM ),NULL
@@ -680,6 +698,7 @@ static const struct hwmon_channel_info *cc2_info[] = {static const struct hwmon_ops cc2_hwmon_ops = { .is_visible = cc2_is_visible, .read = cc2_read, + .read_string = cc2_read_string, .write = cc2_write, };
@@ -710,6 +729,8 @@ static int cc2_probe(struct i2c_client *client)return dev_err_probe (dev,PTR_ERR (data->regulator),"Failed to get regulator\n" ); +device_property_read_string (dev,"label" , &data->label); + ret =cc2_request_ready_irq (data, dev);if (ret)return dev_err_probe (dev, ret,"Failed to request ready irq\n" );
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 2/2] hwmon: (chipcap2) Add support for label
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Add support for label sysfs attribute similar to other hwmon devices. This is particularly useful for systems with multiple sensors on the same board, where identifying individual sensors is much easier since labels can be defined via device tree.
Signed-off-by Flaviu Nistor <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v2 2/2] hwmon: (chipcap2) Add support for label
In reply to Flaviu NistorQuoted 103 lines · Flaviu Nistor
Add support for label sysfs attribute similar to other hwmon devices. This is particularly useful for systems with multiple sensors on the same board, where identifying individual sensors is much easier since labels can be defined via device tree.
Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- No change for this patch in the patch series.
- Link to v1: https://lore.kernel.org/all/[email protected]/Documentation/hwmon/chipcap2.rst | 2 ++ drivers/hwmon/chipcap2.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)Documentation/hwmon/chipcap2.rst +2
-0@@ -70,4 +70,6 @@ humidity1_min_hyst: RW humidity low hystersis humidity1_max_hyst: RW humidity high hystersis humidity1_min_alarm: RO humidity low alarm indicator humidity1_max_alarm: RO humidity high alarm indicator +humidity1_label: RO descriptive name for the sensor +temp1_label: RO descriptive name for the sensor =============================== ======= ========================================drivers/hwmon/chipcap2.c +21
-2@@ -22,6 +22,8 @@#include <linux/irq.h> #include <linux/module.h> #include <linux/regulator/consumer.h> +#include <linux/mod_devicetable.h> +#include <linux/property.h> #define CC2_START_CM 0xA0#define CC2_START_NOM 0x80@@ -83,6 +85,7 @@ struct cc2_data {struct i2c_client *client;struct regulator *regulator;const char *name; +const char *label;int irq_ready;int irq_low;int irq_high;@@ -449,6 +452,8 @@ static umode_t cc2_is_visible(const void *data, enum hwmon_sensor_types type,switch (attr) {case hwmon_humidity_input:return 0444 ; +case hwmon_humidity_label: +return cc2->label ?0444 :0 ;case hwmon_humidity_min_alarm:return cc2->rh_alarm.low_alarm_visible ?0444 :0 ;case hwmon_humidity_max_alarm:@@ -466,6 +471,8 @@ static umode_t cc2_is_visible(const void *data, enum hwmon_sensor_types type,switch (attr) {case hwmon_temp_input:return 0444 ; +case hwmon_temp_label: +return cc2->label ?0444 :0 ;default :return 0 ; }@@ -552,6 +559,16 @@ static int cc2_humidity_max_alarm_status(struct cc2_data *data, long *val)return 0 ; } +static int cc2_read_string (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,const char **str) +{ +struct cc2_data *data =dev_get_drvdata (dev); + + *str = data->label; + +return 0 ; +} +static int cc2_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) {@@ -670,8 +687,9 @@ static int cc2_request_alarm_irqs(struct cc2_data *data, struct device *dev) }static const struct hwmon_channel_info *cc2_info[] = { -HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT ), -HWMON_CHANNEL_INFO (humidity,HWMON_H_INPUT |HWMON_H_MIN |HWMON_H_MAX | +HWMON_CHANNEL_INFO (temp,HWMON_T_INPUT |HWMON_T_LABEL ), +HWMON_CHANNEL_INFO (humidity,HWMON_H_INPUT |HWMON_H_LABEL | +HWMON_H_MIN |HWMON_H_MAX |HWMON_H_MIN_HYST |HWMON_H_MAX_HYST |HWMON_H_MIN_ALARM |HWMON_H_MAX_ALARM ),NULL @@ -680,6 +698,7 @@ static const struct hwmon_channel_info *cc2_info[] = {static const struct hwmon_ops cc2_hwmon_ops = { .is_visible = cc2_is_visible, .read = cc2_read, + .read_string = cc2_read_string, .write = cc2_write, };
drivers/hwmon/chipcap2.c static int cc2_probe(struct i2c_client *client) · line 736
Quoted 8 lines
drivers/hwmon/chipcap2.c +2
-0@@ -710,6 +729,8 @@ static int cc2_probe(struct i2c_client *client)return dev_err_probe (dev,PTR_ERR (data->regulator),"Failed to get regulator\n" ); +device_property_read_string (dev,"label" , &data->label); + ret =cc2_request_ready_irq (data, dev);if (ret)return dev_err_probe (dev, ret,"Failed to request ready irq\n" );
Re: [PATCH v2 2/2] hwmon: (chipcap2) Add support for label
In reply to Flaviu NistorQuoted 7 lines · Flaviu Nistor
Add support for label sysfs attribute similar to other hwmon devices. This is particularly useful for systems with multiple sensors on the same board, where identifying individual sensors is much easier since labels can be defined via device tree.
Signed-off-by Flaviu Nistor <[email protected]>Reviewed-by Javier Carrasco <[email protected]>
Applied.
Thanks,
Guenter
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The threaded interrupt handlers modify alarm state flags without locking, creating a race condition with sysfs reads that can result in lost alarm events. --
commit 7c977021bab8a6a8bb249ac3b4ad711dbe88c4ff
Author: Flaviu Nistor <[email protected]>
dt-bindings: hwmon: chipcap2: Add label property
This commit adds support for an optional label property similar to other hwmon devices. This allows assigning distinct names to each CHIPCAP2 sensor instance on boards with multiple sensors.
Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml properties: · line 50
Quoted 11 lines
Documentation/devicetree/bindings/hwmon/amphenol,chipcap2.yaml +2
-0@@ -45,6 +45,8 @@ properties: - const: low - const: high + label: true + vdd-supply:
[ ... ]
While reviewing the hwmon driver code for this hardware, I noticed a potential locking issue in the interrupt handling.
Quoted 2 lines
drivers/hwmon/chipcap2.c +0
-0
[ ... ]
Quoted 8 lines
static
irqreturn_tcc2_low_interrupt(int irq, void *data){ struct cc2_data *cc2 = data; if (cc2->process_irqs) { hwmon_notify_event(cc2->hwmon, hwmon_humidity, hwmon_humidity_min_alarm, CC2_CHAN_HUMIDITY); cc2->rh_alarm.low_alarm = true;
^^^^
[Severity: High]
This isn't a bug introduced by this patch, but the threaded interrupt handler modifies the min alarm flag without acquiring a lock. Could this create a race condition where an active alarm gets overwritten?
Quoted 5 lines
} return IRQ_HANDLED; }
Quoted 8 lines
static
irqreturn_tcc2_high_interrupt(int irq, void *data){ struct cc2_data *cc2 = data; if (cc2->process_irqs) { hwmon_notify_event(cc2->hwmon, hwmon_humidity, hwmon_humidity_max_alarm, CC2_CHAN_HUMIDITY); cc2->rh_alarm.high_alarm = true;
^^^^
[Severity: High]
This is a pre-existing issue, but the max alarm flag is also modified here without locking.
Quoted 6 lines
} return IRQ_HANDLED; }static int
cc2_humidity_min_alarm_status(struct cc2_data *data, long *val)
Quoted 12 lines
{
long measurement, min_hyst;
int ret;
ret = cc2_read_hyst_and_measure(data, CC2_R_ALARM_L_OFF, &min_hyst,
&measurement);
if (ret < 0)
return ret;
if (data->rh_alarm.low_alarm) {
*val = (measurement < min_hyst) ? 1 : 0;
data->rh_alarm.low_alarm = *val;^^^^
[Severity: High]
This isn't a bug introduced by this patch, but the sysfs read thread performs an unprotected read-modify-write on the alarm state flag here.
If a sysfs read of the alarm status evaluates the current measurement over the I2C bus, and cc2_low_interrupt() concurrently receives an alarm setting low_alarm to true, could the sysfs thread subsequently overwrite the active alarm flag with 0 based on stale measurement data?
The hwmon subsystem documentation mentions that hwmon_lock() or custom locking should be used to serialize sysfs operations with interrupt handling.
Quoted 8 lines
} else { *val = 0; } return 0; }static int
cc2_humidity_max_alarm_status(struct cc2_data *data, long *val)
Quoted 12 lines
{
long measurement, max_hyst;
int ret;
ret = cc2_read_hyst_and_measure(data, CC2_R_ALARM_H_OFF, &max_hyst,
&measurement);
if (ret < 0)
return ret;
if (data->rh_alarm.high_alarm) {
*val = (measurement > max_hyst) ? 1 : 0;
data->rh_alarm.high_alarm = *val;^^^^
[Severity: High]
This is a pre-existing issue, but the max alarm sysfs read also writes back the max alarm flag without locking. Does this present the same risk of lost alarm events if cc2_high_interrupt() runs concurrently?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 4 lines · Flaviu Nistor
Add support for an optional label property similar to other hwmon devices. This allows, in case of boards with multiple CHIPCAP2 sensors, to assign distinct names to each instance.
Quoted 8 lines
Signed-off-by Flaviu Nistor <[email protected]>---
Changes in v2:
- Implement suggestion from Javier Carrasco as proposed by Krzysztof Kozlowski.
- Link to v1: https://lore.kernel.org/all/[email protected]/.../devicetree/bindings/hwmon/amphenol,chipcap2.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Best regards,
Krzysztof
Quoted 6 lines · Flaviu Nistor
Add support for an optional label property similar to other hwmon devices. This allows, in case of boards with multiple CHIPCAP2 sensors, to assign distinct names to each instance.
Signed-off-by Flaviu Nistor <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>
Applied.
Thanks,
Guenter