Skip to content

Commit 2bb4765

Browse files
committed
hwmon: (ina2xx) Mark regmap_config as const
Recent versions of checkpatch complain that struct regmap_config should be declared as const. WARNING: struct regmap_config should normally be const Doing so reveals a potential problem in the driver: If both supported chips are present in a single system, the maximum number of registers may race when devices are instantiated since max_registers is updated in the probe function. Solve the problem by setting .max_registers to the maximum register address of all supported chips. This does not make a practical difference while fixing the potential race condition and reducing code complexity. Reviewed-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 232177a commit 2bb4765

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

drivers/hwmon/ina2xx.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@
5050
#define INA226_ALERT_LIMIT 0x07
5151
#define INA226_DIE_ID 0xFF
5252

53-
/* register count */
54-
#define INA219_REGISTERS 6
55-
#define INA226_REGISTERS 8
56-
5753
#define INA2XX_MAX_REGISTERS 8
5854

5955
/* settings - depend on use case */
@@ -95,17 +91,17 @@
9591
*/
9692
#define INA226_TOTAL_CONV_TIME_DEFAULT 2200
9793

98-
static struct regmap_config ina2xx_regmap_config = {
94+
static const struct regmap_config ina2xx_regmap_config = {
9995
.reg_bits = 8,
10096
.val_bits = 16,
97+
.max_register = INA2XX_MAX_REGISTERS,
10198
};
10299

103100
enum ina2xx_ids { ina219, ina226 };
104101

105102
struct ina2xx_config {
106103
u16 config_default;
107104
int calibration_value;
108-
int registers;
109105
int shunt_div;
110106
int bus_voltage_shift;
111107
int bus_voltage_lsb; /* uV */
@@ -128,7 +124,6 @@ static const struct ina2xx_config ina2xx_config[] = {
128124
[ina219] = {
129125
.config_default = INA219_CONFIG_DEFAULT,
130126
.calibration_value = 4096,
131-
.registers = INA219_REGISTERS,
132127
.shunt_div = 100,
133128
.bus_voltage_shift = 3,
134129
.bus_voltage_lsb = 4000,
@@ -137,7 +132,6 @@ static const struct ina2xx_config ina2xx_config[] = {
137132
[ina226] = {
138133
.config_default = INA226_CONFIG_DEFAULT,
139134
.calibration_value = 2048,
140-
.registers = INA226_REGISTERS,
141135
.shunt_div = 400,
142136
.bus_voltage_shift = 0,
143137
.bus_voltage_lsb = 1250,
@@ -646,8 +640,6 @@ static int ina2xx_probe(struct i2c_client *client)
646640

647641
ina2xx_set_shunt(data, val);
648642

649-
ina2xx_regmap_config.max_register = data->config->registers;
650-
651643
data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config);
652644
if (IS_ERR(data->regmap)) {
653645
dev_err(dev, "failed to allocate register map\n");

0 commit comments

Comments
 (0)