lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <046d8bed-c936-32af-d5c0-bf1c90684f39@rasmusvillemoes.dk>
Date:   Tue, 29 Nov 2022 15:13:20 +0100
From:   Rasmus Villemoes <linux@...musvillemoes.dk>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        linux-rtc@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-hwmon@...r.kernel.org
Cc:     Alessandro Zummo <a.zummo@...ertech.it>,
        Alexandre Belloni <alexandre.belloni@...tlin.com>,
        Jean Delvare <jdelvare@...e.com>,
        Guenter Roeck <linux@...ck-us.net>
Subject: Re: [PATCH v1 2/5] rtc: isl12022: Explicitly use __le16 type for
 ISL12022_REG_TEMP_L

On 26/11/2022 15.18, Andy Shevchenko wrote:
> We are reading 10-bit value in a 16-bit register in LE format.
> Make this explicit by using __le16 type for it and corresponding
> conversion function.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
>  drivers/rtc/rtc-isl12022.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
> index 44058fa27277..bf1aa6f6560d 100644
> --- a/drivers/rtc/rtc-isl12022.c
> +++ b/drivers/rtc/rtc-isl12022.c
> @@ -19,6 +19,8 @@
>  #include <linux/regmap.h>
>  #include <linux/hwmon.h>
>  
> +#include <asm/byteorder.h>
> +
>  /* ISL register offsets */
>  #define ISL12022_REG_SC		0x00
>  #define ISL12022_REG_MN		0x01
> @@ -63,17 +65,16 @@ static umode_t isl12022_hwmon_is_visible(const void *data,
>  static int isl12022_hwmon_read_temp(struct device *dev, long *mC)
>  {
>  	struct regmap *regmap = dev_get_drvdata(dev);
> -	u8 temp_buf[2];
>  	int temp, ret;
> +	__le16 buf;
>  
> -	ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L,
> -			       temp_buf, sizeof(temp_buf));
> +	ret = regmap_bulk_read(regmap, ISL12022_REG_TEMP_L, &buf, sizeof(buf));
>  	if (ret)
>  		return ret;
>  	/*
>  	 * Temperature is represented as a 10-bit number, unit half-Kelvins.
>  	 */
> -	temp = (temp_buf[1] << 8) | temp_buf[0];
> +	temp = le16_to_cpu(buf);

Makes sense. Perhaps we should throw in "& 0x3ff" just in case there
were ever any garbage bits set in the temp_h register.

With or without that,

Acked-by: Rasmus Villemoes <linux@...musvillemoes.dk>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ