Re: [PATCH 2/2] hwmon: (ina2xx) Add device tree support to pass alert polarity

From: Krzysztof Kozlowski
Date: Wed May 29 2024 - 03:09:31 EST


On 29/05/2024 08:07, Amna Waseem wrote:
>
> +static int ina2xx_set_alert_polarity(struct ina2xx_data *data,
> + unsigned long val)
> +{
> + int ret;
> +
> + if (val > INT_MAX || !(val == 0 || val == 1))
> + return -EINVAL;
> +
> + mutex_lock(&data->config_lock);

Aren't you calling it before registering sysfs interface? Why do you
need mutex?

> + ret = regmap_update_bits(data->regmap, INA226_MASK_ENABLE,
> + INA226_ALERT_POLARITY_MASK,
> + INA226_SHIFT_ALERT_POLARITY(val));
> +
> + mutex_unlock(&data->config_lock);
> + return ret;
> +}
> +
> /*
> * Calibration register is set to the best value, which eliminates
> * truncation errors on calculating current register in hardware.
> @@ -659,6 +679,14 @@ static int ina2xx_probe(struct i2c_client *client)
> if (ret)
> return dev_err_probe(dev, ret, "failed to enable vs regulator\n");
>
> + if (!of_property_read_u32(dev->of_node, "alert-polarity", &val)) {
> + ret = ina2xx_set_alert_polarity(data, val);
> + if (ret < 0)
> + return dev_err_probe(
> + dev, ret,
> + "failed to set APOL bit of Enable/Mask register\n");

That's odd wrapping. Please follow Linux coding style and align these.

Best regards,
Krzysztof