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: <CAOoeyxW5PrvhO_cunYwAjXynLH9jZ4OQsdnju-ZONBKsrXgakg@mail.gmail.com>
Date: Fri, 22 Nov 2024 16:15:25 +0800
From: Ming Yu <a0282524688@...il.com>
To: Guenter Roeck <linux@...ck-us.net>
Cc: tmyu0@...oton.com, lee@...nel.org, linus.walleij@...aro.org, brgl@...ev.pl, 
	andi.shyti@...nel.org, mkl@...gutronix.de, mailhol.vincent@...adoo.fr, 
	andrew+netdev@...n.ch, davem@...emloft.net, edumazet@...gle.com, 
	kuba@...nel.org, pabeni@...hat.com, wim@...ux-watchdog.org, jdelvare@...e.com, 
	alexandre.belloni@...tlin.com, linux-kernel@...r.kernel.org, 
	linux-gpio@...r.kernel.org, linux-i2c@...r.kernel.org, 
	linux-can@...r.kernel.org, netdev@...r.kernel.org, 
	linux-watchdog@...r.kernel.org, linux-hwmon@...r.kernel.org, 
	linux-rtc@...r.kernel.org
Subject: Re: [PATCH v2 6/7] hwmon: Add Nuvoton NCT6694 HWMON support

Dear Guenter,

Thank you for your comments,

Guenter Roeck <linux@...ck-us.net> 於 2024年11月21日 週四 下午10:22寫道:
>
...
> > +static int nct6694_in_read(struct device *dev, u32 attr, int channel,
> > +                        long *val)
> > +{
> > +     struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> > +     unsigned char vin_en;
> > +     int ret;
> > +
> > +     guard(mutex)(&data->lock);
> > +
> > +     switch (attr) {
> > +     case hwmon_in_enable:
> > +             vin_en = data->hwmon_en[NCT6694_VIN_EN(channel / 8)];
> > +             *val = vin_en & BIT(channel % 8) ? 1 : 0;
>
> Nit: !!(vin_en & BIT(channel % 8))
>
> Not even worth mentioning, but !! is used below, so it would make sense
> to use it here as well for consistency.
>

Understood. I will make the modifications in v3.

> > +
> > +             return 0;
...
> > +static int nct6694_temp_write(struct device *dev, u32 attr, int channel,
> > +                           long val)
> > +{
> > +     struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> > +     signed char temp_max, temp_hyst;
> > +     int ret;
> > +
> > +     guard(mutex)(&data->lock);
> > +
> > +     switch (attr) {
> > +     case hwmon_temp_enable:
> > +             return nct6694_enable_channel(dev, NCT6694_TIN_EN(channel / 8),
> > +                                           channel, val);
> > +     case hwmon_temp_max:
> > +             ret = nct6694_read_msg(data->nct6694, NCT6694_HWMON_MOD,
> > +                                    NCT6694_HWMON_CMD2_OFFSET,
> > +                                    NCT6694_HWMON_CMD2_LEN,
> > +                                    data->xmit_buf);
> > +             if (ret)
> > +                     return ret;
> > +
> > +             val = clamp_val(val, -127000, 127000);
> > +             data->xmit_buf[NCT6694_TIN_HL(channel)] = temp_to_reg(val);
> > +
> > +             return nct6694_write_msg(data->nct6694, NCT6694_HWMON_MOD,
> > +                                      NCT6694_HWMON_CMD2_OFFSET,
> > +                                      NCT6694_HWMON_CMD2_LEN,
> > +                                      data->xmit_buf);
> > +     case hwmon_temp_max_hyst:
> > +             ret = nct6694_read_msg(data->nct6694, NCT6694_HWMON_MOD,
> > +                                    NCT6694_HWMON_CMD2_OFFSET,
> > +                                    NCT6694_HWMON_CMD2_LEN,
> > +                                    data->xmit_buf);
> > +
> > +             val = clamp_val(val, -127000, 127000);
> > +             temp_max = (signed char)data->xmit_buf[NCT6694_TIN_HL(channel)];
> > +             temp_hyst = (temp_max < 0) ? (temp_max + val / 1000) :
> > +                                          (temp_max - val / 1000);
> > +             if (temp_hyst < 0 || temp_hyst > 7)
> > +                     return -EINVAL;
> > +
>
> Just use clamp_val() again. Otherwise it is difficult for the user to determine
> valid ranges.
>

Understood. I will make the modifications in v3.

> > +             data->xmit_buf[NCT6694_TIN_HYST(channel)] =
> > +                    (data->xmit_buf[NCT6694_TIN_HYST(channel)] & ~NCT6694_TIN_HYST_MASK) |
> > +                    FIELD_PREP(NCT6694_TIN_HYST_MASK, temp_hyst);
> > +
> > +             return nct6694_write_msg(data->nct6694, NCT6694_HWMON_MOD,
> > +                                      NCT6694_HWMON_CMD2_OFFSET,
> > +                                      NCT6694_HWMON_CMD2_LEN,
> > +                                      data->xmit_buf);
> > +     default:
> > +             return -EOPNOTSUPP;
> > +     }
> > +}
> > +
> > +static int nct6694_fan_write(struct device *dev, u32 attr, int channel,
> > +                          long val)
> > +{
> > +     struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
> > +     int ret;
> > +
> > +     guard(mutex)(&data->lock);
> > +
> > +     switch (attr) {
> > +     case hwmon_fan_enable:
> > +             return nct6694_enable_channel(dev, NCT6694_FIN_EN(channel / 8),
> > +                                           channel, val);
> > +     case hwmon_fan_min:
> > +             if (val <= 0)
> > +                     return -EINVAL;
> > +
> I'd suggest to just use clamp_val() and drop this check.
>

Understood. I will make the modifications in v3.

Best regards,
Ming

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ