<div dir="auto">I got what you meant. I"ll fix it</div><div class="gmail_extra"><br><div class="gmail_quote">El dia 20/04/2017 08:47, "Oscar Salvador" <<a href="mailto:osalvador.vilardaga@gmail.com">osalvador.vilardaga@gmail.com</a>> va escriure:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Karol,<br>
<br>
I don't get what you mean with return due to fallthrough. I mean, I<br>
know what is it, but I don't see how I can do it there.<br>
Moving the check before the switch looks like that:<br>
<br>
        if (!iccsense)<br>
                return 0;<br>
<br>
        switch (attr) {<br>
        case hwmon_power_input:<br>
                if (iccsense->data_valid &&<br>
                        !list_empty(&iccsense->rails))<br>
                        return 0444;<br>
        case hwmon_power_max:<br>
                if (iccsense->power_w_max)<br>
                        return 0444;<br>
        case hwmon_power_crit:<br>
                if (iccsense->power_w_crit)<br>
                        return 0444;<br>
        default:<br>
                return 0;<br>
        }<br>
<br>
Could you drop me a hint?<br>
<br>
<br>
On 18 April 2017 at 09:56, Karol Herbst <<a href="mailto:karolherbst@gmail.com">karolherbst@gmail.com</a>> wrote:<br>
> 2017-04-17 9:47 GMT+02:00 Oscar Salvador <<a href="mailto:osalvador.vilardaga@gmail.com">osalvador.vilardaga@gmail.com</a><wbr>>:<br>
>> This patch introduces the nouveau_hwmon_ops structure, sets up<br>
>> .is_visible and .read_string operations and adds all the functions<br>
>> for these operations.<br>
>> This is also a preparation for the next patches, where most of the<br>
>> work is being done.<br>
>> This code doesn't interacture with the old one.<br>
>> It's just to make easier the review of all patches.<br>
>> ---<br>
>>  drivers/gpu/drm/nouveau/<wbr>nouveau_hwmon.c | 166 ++++++++++++++++++++++++++++++<wbr>++<br>
>>  1 file changed, 166 insertions(+)<br>
>><br>
>> diff --git a/drivers/gpu/drm/nouveau/<wbr>nouveau_hwmon.c b/drivers/gpu/drm/nouveau/<wbr>nouveau_hwmon.c<br>
>> index 24b40c5..9b6423c 100644<br>
>> --- a/drivers/gpu/drm/nouveau/<wbr>nouveau_hwmon.c<br>
>> +++ b/drivers/gpu/drm/nouveau/<wbr>nouveau_hwmon.c<br>
>> @@ -764,6 +764,172 @@ static const struct hwmon_channel_info *nouveau_info[] = {<br>
>>         &nouveau_power,<br>
>>         NULL<br>
>>  };<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_chip_is_visible(const void *data, u32 attr, int channel)<br>
>> +{<br>
>> +       switch (attr) {<br>
>> +       case hwmon_chip_update_interval:<br>
>> +               return 0444;<br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_power_is_visible(<wbr>const void *data, u32 attr, int channel)<br>
>> +{<br>
>> +       struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);<br>
>> +       struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.<wbr>device);<br>
>> +<br>
>> +       switch (attr) {<br>
>> +       case hwmon_power_input:<br>
>> +               if (iccsense &&<br>
><br>
> move the pointer check before the switch, because you need to check it<br>
> in every case (or move it to every case, but doing it once is<br>
> simplier/cleaner)<br>
><br>
>> +                       iccsense->data_valid &&<br>
>> +                       !list_empty(&iccsense->rails))<br>
>> +                       return 0444;<br>
><br>
> add return due to fallthrough<br>
><br>
>> +       case hwmon_power_max:<br>
>> +               if (iccsense->power_w_max)<br>
>> +                       return 0444;<br>
><br>
> add return due to fallthrough<br>
><br>
>> +       case hwmon_power_crit:<br>
>> +               if (iccsense->power_w_crit)<br>
>> +                       return 0444;<br>
><br>
> add return due to fallthrough<br>
><br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_temp_is_visible(const void *data, u32 attr, int channel)<br>
>> +{<br>
>> +       struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);<br>
>> +       struct nvkm_therm *therm = nvxx_therm(&drm->client.<wbr>device);<br>
>> +<br>
>> +       if (therm &&<br>
>> +               therm->attr_get &&<br>
>> +               therm->attr_set &&<br>
>> +               nvkm_therm_temp_get(therm) < 0)<br>
>> +               return 0;<br>
>> +<br>
>> +       switch (attr) {<br>
>> +       case hwmon_temp_input:<br>
>> +       case hwmon_temp_max:<br>
>> +       case hwmon_temp_max_hyst:<br>
>> +       case hwmon_temp_crit:<br>
>> +       case hwmon_temp_crit_hyst:<br>
>> +       case hwmon_temp_emergency:<br>
>> +       case hwmon_temp_emergency_hyst:<br>
>> +               return 0444;<br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_pwm_is_visible(const void *data, u32 attr, int channel)<br>
>> +{<br>
>> +       struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);<br>
>> +       struct nvkm_therm *therm = nvxx_therm(&drm->client.<wbr>device);<br>
>> +<br>
>> +       if (therm &&<br>
>> +               therm->attr_get &&<br>
>> +               therm->fan_get &&<br>
>> +               therm->fan_get(therm) < 0)<br>
>> +               return 0;<br>
>> +<br>
>> +       switch (attr) {<br>
>> +       case hwmon_pwm_enable:<br>
>> +       case hwmon_pwm_input:<br>
>> +               return 0644;<br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_input_is_visible(<wbr>const void *data, u32 attr, int channel)<br>
>> +{<br>
>> +       struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);<br>
>> +       struct nvkm_volt *volt = nvxx_volt(&drm->client.device)<wbr>;<br>
>> +<br>
>> +       if (!volt || nvkm_volt_get(volt) < 0)<br>
>> +               return 0;<br>
>> +<br>
>> +       switch (attr) {<br>
>> +       case hwmon_in_input:<br>
>> +       case hwmon_in_label:<br>
>> +       case hwmon_in_min:<br>
>> +       case hwmon_in_max:<br>
>> +               return 0444;<br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_fan_is_visible(const void *data, u32 attr, int channel)<br>
>> +{<br>
>> +       struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data);<br>
>> +       struct nvkm_therm *therm = nvxx_therm(&drm->client.<wbr>device);<br>
>> +<br>
>> +       if (!therm || !therm->attr_get || nvkm_therm_fan_sense(therm) < 0)<br>
>> +               return 0;<br>
>> +<br>
>> +       switch (attr) {<br>
>> +       case hwmon_fan_input:<br>
>> +               return 0444;<br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static umode_t<br>
>> +nouveau_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr,<br>
>> +                                                               int channel)<br>
>> +{<br>
>> +       switch (type) {<br>
>> +       case hwmon_chip:<br>
>> +               return nouveau_chip_is_visible(data, attr, channel);<br>
>> +       case hwmon_temp:<br>
>> +               return nouveau_temp_is_visible(data, attr, channel);<br>
>> +       case hwmon_fan:<br>
>> +               return nouveau_fan_is_visible(data, attr, channel);<br>
>> +       case hwmon_in:<br>
>> +               return nouveau_input_is_visible(data, attr, channel);<br>
>> +       case hwmon_pwm:<br>
>> +               return nouveau_pwm_is_visible(data, attr, channel);<br>
>> +       case hwmon_power:<br>
>> +               return nouveau_power_is_visible(data, attr, channel);<br>
>> +       default:<br>
>> +               return 0;<br>
>> +       }<br>
>> +}<br>
>> +<br>
>> +static char *input_label = "GPU core";<br>
>> +<br>
>> +static int<br>
>> +nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,<br>
>> +                                                       int channel, char **buf)<br>
>> +{<br>
>> +       if (type == hwmon_in && attr == hwmon_in_label) {<br>
>> +               *buf = input_label;<br>
>> +               return 0;<br>
>> +       }<br>
>> +<br>
>> +       return -EOPNOTSUPP;<br>
>> +}<br>
>> +<br>
>> +static const struct hwmon_ops nouveau_hwmon_ops = {<br>
>> +       .is_visible = nouveau_is_visible,<br>
>> +       .read = NULL,<br>
>> +       .read_string = nouveau_read_string,<br>
>> +       .write = NULL,<br>
>> +};<br>
>> +<br>
>> +static const struct hwmon_chip_info nouveau_chip_info = {<br>
>> +       .ops = &nouveau_hwmon_ops,<br>
>> +       .info = nouveau_info,<br>
>> +};<br>
>>  #endif<br>
>><br>
>>  int<br>
>> --<br>
>> 2.1.4<br>
>><br>
>> ______________________________<wbr>_________________<br>
>> Nouveau mailing list<br>
>> <a href="mailto:Nouveau@lists.freedesktop.org">Nouveau@lists.freedesktop.org</a><br>
>> <a href="https://lists.freedesktop.org/mailman/listinfo/nouveau" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/nouveau</a><br>
</blockquote></div></div>