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: <3b121ab4-dd64-68b3-ee89-8571b5d3651e@amazon.com>
Date:   Tue, 13 Sep 2022 17:40:16 +0300
From:   "Farber, Eliav" <farbere@...zon.com>
To:     Andy Shevchenko <andriy.shevchenko@...el.com>
CC:     <jdelvare@...e.com>, <linux@...ck-us.net>, <robh+dt@...nel.org>,
        <p.zabel@...gutronix.de>, <rtanwar@...linear.com>,
        <linux-hwmon@...r.kernel.org>, <devicetree@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>, <hhhawa@...zon.com>,
        <jonnyc@...zon.com>, "Farber, Eliav" <farbere@...zon.com>
Subject: Re: [PATCH v5 20/21] hwmon: (mr75203) add debugfs to read and write
 temperature coefficients

On 9/13/2022 4:06 PM, Farber, Eliav wrote:
> On 9/8/2022 9:11 PM, Andy Shevchenko wrote:
>> On Thu, Sep 08, 2022 at 03:24:48PM +0000, Eliav Farber wrote:
>>> This change adds debugfs to read and write temperature sensor 
>>> coefficients
>>> - g, h, j and cal5.
>>>
>>> The coefficients can vary between product and product, so it can be 
>>> very
>>> useful to be able to modify them on the fly during the calibration
>>> process.
>>>
>>> e.g.:
>>>
>>> cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_cal5
>>> 4096
>>>
>>> echo 83000 > sys/kernel/debug/940f23d0000.pvt/ts_coeff_g
>>
>> ...
>>
>>> - Return j coefficient to use debugfs_create_file() instead of
>>>   debugfs_create_u32() because j is signed.
>>
>> You can use
>>
>> DEFINE_DEBUGFS_ATTRIBUTE(ts_coeff_j, ts_coeff_j_get, ts_coeff_j_set, 
>> "%lld\n");
>>
>> which still makes code compact. 
>
>
> I tried your suggestion to use DEFINE_DEBUGFS_ATTRIBUTE but I can't set
> j to be a negative value:
>
> root@...ine:~# cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j
> 0
> root@...ine:~# echo 100 > /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j
> root@...ine:~# cat /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j
> 100
> root@...ine:~# echo -100 > /sys/kernel/debug/940f23d0000.pvt/ts_coeff_j
> sh: write error: Invalid argument
>
> This is the code I added:
>
> static int ts_coeff_j_set(void *data, u64 val)
> {
>     struct pvt_device *pvt = data;
>
>     pvt->ts_coeff.j = val;
>     return 0;
> }
>
> static int ts_coeff_j_get(void *data, u64 *val)
> {
>     struct pvt_device *pvt = data;
>
>     *val = pvt->ts_coeff.j;
>     return 0;
> }
>
> DEFINE_DEBUGFS_ATTRIBUTE(ts_coeff_j_fops, ts_coeff_j_get,
>              ts_coeff_j_set, "%lld\n");
>
> static void devm_pvt_ts_dbgfs_remove(void *data)
> {
>     struct pvt_device *pvt = (struct pvt_device *)data;
>
>     debugfs_remove_recursive(pvt->dbgfs_dir);
>     pvt->dbgfs_dir = NULL;
> }
>
> static int pvt_ts_dbgfs_create(struct pvt_device *pvt, struct device 
> *dev)
> {
>     ...
>     debugfs_create_file("ts_coeff_j", 0644, pvt->dbgfs_dir, pvt,
>                 &ts_coeff_j_fops);
>     ...
>
> I'm using kernel 5.10.112.
> Can you please see if I'm did anything wrong? 

It seems like debugfs_attr_write() calls simple_attr_write() and it uses
kstrtoull(), which is why it fails when setting a negative value.
This is the same also in v6.0-rc5.

debugfs_attr_read() on the other hand does show the correct value also
when j is negative.

--
Regards, Eliav


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ