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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220905221037.GA3694440@roeck-us.net>
Date:   Mon, 5 Sep 2022 15:10:37 -0700
From:   Guenter Roeck <linux@...ck-us.net>
To:     Alexandru Gagniuc <mr.nuke.me@...il.com>
Cc:     linux-hwmon@...r.kernel.org, robert.marko@...tura.hr,
        luka.perkov@...tura.hr, jdelvare@...e.com, dev@...ehler.at,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/3] hwmon: (tps23861) fix byte order in resistance
 register

On Mon, Sep 05, 2022 at 09:28:04AM -0500, Alexandru Gagniuc wrote:
> The tps23861 registers are little-endian, and regmap_read_bulk() does
> not do byte order conversion. On BE machines, the bytes were swapped,
> and the interpretation of the resistance value was incorrect.
> 
> To make it work on both big and little-endian machines, use
> le16_to_cpu() to convert the resitance register to host byte order.
> 
> Signed-off-by: Alexandru Gagniuc <mr.nuke.me@...il.com>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/tps23861.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/tps23861.c b/drivers/hwmon/tps23861.c
> index 42762e87b014..f7c59ff7ae8e 100644
> --- a/drivers/hwmon/tps23861.c
> +++ b/drivers/hwmon/tps23861.c
> @@ -493,18 +493,20 @@ static char *tps23861_port_poe_plus_status(struct tps23861_data *data, int port)
>  
>  static int tps23861_port_resistance(struct tps23861_data *data, int port)
>  {
> -	u16 regval;
> +	unsigned int raw_val;
> +	__le16 regval;
>  
>  	regmap_bulk_read(data->regmap,
>  			 PORT_1_RESISTANCE_LSB + PORT_N_RESISTANCE_LSB_OFFSET * (port - 1),
>  			 &regval,
>  			 2);
>  
> -	switch (FIELD_GET(PORT_RESISTANCE_RSN_MASK, regval)) {
> +	raw_val = le16_to_cpu(regval);
> +	switch (FIELD_GET(PORT_RESISTANCE_RSN_MASK, raw_val)) {
>  	case PORT_RESISTANCE_RSN_OTHER:
> -		return (FIELD_GET(PORT_RESISTANCE_MASK, regval) * RESISTANCE_LSB) / 10000;
> +		return (FIELD_GET(PORT_RESISTANCE_MASK, raw_val) * RESISTANCE_LSB) / 10000;
>  	case PORT_RESISTANCE_RSN_LOW:
> -		return (FIELD_GET(PORT_RESISTANCE_MASK, regval) * RESISTANCE_LSB_LOW) / 10000;
> +		return (FIELD_GET(PORT_RESISTANCE_MASK, raw_val) * RESISTANCE_LSB_LOW) / 10000;
>  	case PORT_RESISTANCE_RSN_SHORT:
>  	case PORT_RESISTANCE_RSN_OPEN:
>  	default:

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ