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: <5d65ccfd.1c69fb81.95798.20d8@mx.google.com>
Date:   Tue, 27 Aug 2019 17:38:20 -0700
From:   Stephen Boyd <swboyd@...omium.org>
To:     Amit Kucheria <amit.kucheria@...aro.org>,
        Daniel Lezcano <daniel.lezcano@...aro.org>,
        Mark Rutland <mark.rutland@....com>,
        Rob Herring <robh+dt@...nel.org>,
        Zhang Rui <rui.zhang@...el.com>, agross@...nel.org,
        bjorn.andersson@...aro.org, edubezval@...il.com,
        linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org,
        marc.w.gonzalez@...e.fr, masneyb@...tation.org
Cc:     linux-pm@...r.kernel.org
Subject: Re: [PATCH v2 14/15] drivers: thermal: tsens: Create function to return sign-extended temperature

Quoting Amit Kucheria (2019-08-27 05:14:10)
> diff --git a/drivers/thermal/qcom/tsens-common.c b/drivers/thermal/qcom/tsens-common.c
> index ea2c46cc6a66a..06b44cfd5eab9 100644
> --- a/drivers/thermal/qcom/tsens-common.c
> +++ b/drivers/thermal/qcom/tsens-common.c
> @@ -84,13 +84,43 @@ static inline int code_to_degc(u32 adc_code, const struct tsens_sensor *s)
>         return degc;
>  }
>  
> +/**
> + * tsens_hw_to_mC - Return sign-extended temperature in mCelsius.
> + * @s:     Pointer to sensor struct

sensor? This isn't golang!

> + * @field: Index into regmap_field array pointing to temperature data
> + *
> + * This function handles temperature returned in ADC code or deciCelsius
> + * depending on IP version.
> + *
> + * Return: Temperature in milliCelsius on success, a negative errno will
> + * be returned in error cases
> + */
> +static int tsens_hw_to_mC(struct tsens_sensor *s, int field)
> +{
> +       struct tsens_priv *priv = s->priv;
> +       u32 temp = 0;
> +       int ret;
> +
> +       ret = regmap_field_read(priv->rf[field], &temp);
> +       if (ret)
> +               return ret;
> +
> +       if (priv->feat->adc) {
> +               /* Convert temperature from ADC code to milliCelsius */

Nitpick: Move this comment above the if and drop the braces.

> +               return code_to_degc(temp, s) * 1000;
> +       }
> +
> +       /* deciCelsius -> milliCelsius along with sign extension */
> +       return sign_extend32(temp, priv->tempres) * 100;
> +}
> +
>  int get_temp_tsens_valid(struct tsens_sensor *s, int *temp)
>  {
>         struct tsens_priv *priv = s->priv;
>         int hw_id = s->hw_id;
>         u32 temp_idx = LAST_TEMP_0 + hw_id;
>         u32 valid_idx = VALID_0 + hw_id;
> -       u32 last_temp = 0, valid, mask;
> +       u32 valid;
>         int ret;
>  
>         ret = regmap_field_read(priv->rf[valid_idx], &valid);
> @@ -310,6 +328,10 @@ int __init init_common(struct tsens_priv *priv)
>                         goto err_put_device;
>                 }
>         }
> +
> +       /* Save away resolution of signed temperature value for this IP */
> +       priv->tempres = priv->fields[LAST_TEMP_0].msb - priv->fields[LAST_TEMP_0].lsb;
> +

Why not just calculate this in the function that uses it? Is there a
reason to stash it away in the struct?

>         for (i = 0, j = VALID_0; i < priv->feat->max_sensors; i++, j++) {
>                 priv->rf[j] = devm_regmap_field_alloc(dev, priv->tm_map,
>                                                       priv->fields[j]);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ