diff mbox series

[v4,5/5] hwmon: ltc2945: Convert division to DIV_ROUND_CLOSEST_ULL

Message ID 20230126-b4-ltc2945_shunt_resistor-v4-5-bb913470d8da@criticallink.com (mailing list archive)
State Accepted
Headers show
Series hwmon: ltc2945: Add binding and shunt resistor support | expand

Commit Message

Jonathan Cormier Jan. 26, 2023, 10:32 p.m. UTC
Convert division to DIV_ROUND_CLOSEST_ULL to match code
in same function.

Signed-off-by: Jonathan Cormier <jcormier@criticallink.com>
---
 drivers/hwmon/ltc2945.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Guenter Roeck Jan. 29, 2023, 7:55 p.m. UTC | #1
On Thu, Jan 26, 2023 at 05:32:27PM -0500, Jonathan Cormier wrote:
> Convert division to DIV_ROUND_CLOSEST_ULL to match code
> in same function.
> 
> Signed-off-by: Jonathan Cormier <jcormier@criticallink.comi
> ---
>  drivers/hwmon/ltc2945.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
> index 0b5e448b4f12..33341d01f1f7 100644
> --- a/drivers/hwmon/ltc2945.c
> +++ b/drivers/hwmon/ltc2945.c
> @@ -212,7 +212,7 @@ static long long ltc2945_val_to_reg(struct device *dev, u8 reg,
>  	case LTC2945_MAX_VIN_THRES_H:
>  	case LTC2945_MIN_VIN_THRES_H:
>  		/* 25 mV resolution. */
> -		val /= 25;
> +		val = DIV_ROUND_CLOSEST_ULL(val, 25);

This needs to be combined with the previous patch since that patch changes
'val' from unsigned long to unsigned long long, causing a compile failure
on 32-bit builds.

I'll do that unless some other 32 bit build failure shows up.

Guenter

>  		break;
>  	case LTC2945_ADIN_H:
>  	case LTC2945_MAX_ADIN_H:
> 
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
index 0b5e448b4f12..33341d01f1f7 100644
--- a/drivers/hwmon/ltc2945.c
+++ b/drivers/hwmon/ltc2945.c
@@ -212,7 +212,7 @@  static long long ltc2945_val_to_reg(struct device *dev, u8 reg,
 	case LTC2945_MAX_VIN_THRES_H:
 	case LTC2945_MIN_VIN_THRES_H:
 		/* 25 mV resolution. */
-		val /= 25;
+		val = DIV_ROUND_CLOSEST_ULL(val, 25);
 		break;
 	case LTC2945_ADIN_H:
 	case LTC2945_MAX_ADIN_H: