Messages in this thread Patch in this message |  | | From | Piyush Patle <> | | Subject | [PATCH v11 09/11] iio: adc: hx711: localize loop iterators in hx711_read | | Date | Thu, 4 Jun 2026 00:18:57 +0530 |
| |
Tighten the scope of the loop variables in hx711_read() now that trailing-pulse selection is already handled by the callers.
Also replace the 24-bit loop bound with a named constant while touching the same code.
Suggested-by: Andy Shevchenko <andy@kernel.org> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> --- drivers/iio/adc/hx711.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index 4ccb0bf2d71f..e5d842853b71 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -23,6 +23,8 @@ #include <linux/gpio/consumer.h> #include <linux/regulator/consumer.h> +#define HX711_DATA_BITS 24 + /* gain to pulse and scale conversion */ #define HX711_GAIN_MAX 3 #define HX711_RESET_GAIN 128 @@ -157,16 +159,16 @@ static int hx711_cycle(struct hx711_data *hx711_data) static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses) { - int i, ret; int value = 0; int val; + int ret; /* we double check if it's really down */ val = gpiod_get_value(hx711_data->gpiod_dout); if (val) return -EIO; - for (i = 0; i < 24; i++) { + for (int i = 0; i < HX711_DATA_BITS; i++) { value <<= 1; ret = hx711_cycle(hx711_data); if (ret) @@ -175,7 +177,7 @@ static int hx711_read(struct hx711_data *hx711_data, int trailing_pulses) value ^= 0x800000; - for (i = 0; i < trailing_pulses; i++) + for (int i = 0; i < trailing_pulses; i++) hx711_cycle(hx711_data); return value; -- 2.43.0
|  |