From: Guenter Roeck <linux@roeck-us.net>
To: Cosmo Chou <chou.cosmo@gmail.com>
Cc: robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
conor+dt@kernel.org, jdelvare@suse.com, corbet@lwn.net,
broonie@kernel.org, naresh.solanki@9elements.com,
vincent@vtremblay.dev, patrick.rudolph@9elements.com,
luca.ceresoli@bootlin.com, bhelgaas@google.com, festevam@denx.de,
alexander.stein@ew.tq-group.com, heiko@sntech.de,
jernej.skrabec@gmail.com, macromorgan@hotmail.com,
forbidden405@foxmail.com, sre@kernel.org,
linus.walleij@linaro.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
linux-doc@vger.kernel.org, cosmo.chou@quantatw.com
Subject: Re: [PATCH v5 1/1] hwmon: Add driver for Astera Labs PT5161L retimer
Date: Mon, 5 Feb 2024 19:26:04 -0800 [thread overview]
Message-ID: <a05ec2fe-cfe4-48d8-bff4-9f3689c585d3@roeck-us.net> (raw)
In-Reply-To: <CAOeEDysSZEeKt==zyexLE1GhE5ZpeDHS7sDLRfcC=4JgiogLKQ@mail.gmail.com>
On 2/5/24 19:05, Cosmo Chou wrote:
> On Tue, Feb 06, 2024 at 3:43 AM +0800, Guenter Roeck wrote:
>>
>> On Mon, Feb 05, 2024 at 11:20:13PM +0800, Cosmo Chou wrote:
>>> This driver implements support for temperature monitoring of Astera Labs
>>> PT5161L series PCIe retimer chips.
>>>
>>> This driver implementation originates from the CSDK available at
>>> Link: https://github.com/facebook/openbmc/tree/helium/common/recipes-lib/retimer-v2.14
>>> The communication protocol utilized is based on the I2C/SMBus standard.
>>>
>>> Signed-off-by: Cosmo Chou <chou.cosmo@gmail.com>
>>> ---
>> [ ... ]
>>
>>> +static ssize_t pt5161l_debugfs_read_fw_ver(struct file *file, char __user *buf,
>>> + size_t count, loff_t *ppos)
>>> +{
>>> + struct pt5161l_data *data = file->private_data;
>>> + int ret;
>>> + char ver[32];
>>> +
>>> + mutex_lock(&data->lock);
>>> + ret = pt5161l_fwsts_check(data);
>>> + mutex_unlock(&data->lock);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + ret = snprintf(ver, sizeof(ver), "%u.%u.%u\n", data->fw_ver.major,
>>> + data->fw_ver.minor, data->fw_ver.build);
>>> + if (ret < 0)
>>> + return ret;
>>> +
>>
>> You almost got me here ;-). snprintf() never returns a negative error code,
>> so checking for it is not necessary.
>>
> Oh! You're right.
>
>>> + return simple_read_from_buffer(buf, count, ppos, ver, ret + 1);
>>
>> Number of bytes written plus 1 ? Why ?
> It's just to include the string terminator '\0'.
>
If that was needed, it would be risky. snprintf() truncates the output
if the buffer is not large enough. You might want to consider using
scnprintf() instead. But then I am not sure if that is needed in the first
place. Almost all code I checked doesn't do that, and it seems to be likely
that the few drivers who do that are simply wrong. Can you explain why the
string terminator needs to be added to the output ?
Thanks,
Guenter
next prev parent reply other threads:[~2024-02-06 3:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-05 15:20 [PATCH v5 0/1] hwmon: Add driver for Astera Labs PT5161L retimer Cosmo Chou
2024-02-05 15:20 ` [PATCH v5 1/1] " Cosmo Chou
2024-02-05 15:26 ` Krzysztof Kozlowski
2024-02-05 16:15 ` Guenter Roeck
2024-02-06 7:33 ` Krzysztof Kozlowski
2024-02-06 15:19 ` Guenter Roeck
2024-02-05 19:43 ` Guenter Roeck
2024-02-06 3:05 ` Cosmo Chou
2024-02-06 3:26 ` Guenter Roeck [this message]
2024-02-06 3:53 ` Cosmo Chou
2024-02-06 4:02 ` Guenter Roeck
2024-02-06 4:16 ` Cosmo Chou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a05ec2fe-cfe4-48d8-bff4-9f3689c585d3@roeck-us.net \
--to=linux@roeck-us.net \
--cc=alexander.stein@ew.tq-group.com \
--cc=bhelgaas@google.com \
--cc=broonie@kernel.org \
--cc=chou.cosmo@gmail.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=cosmo.chou@quantatw.com \
--cc=devicetree@vger.kernel.org \
--cc=festevam@denx.de \
--cc=forbidden405@foxmail.com \
--cc=heiko@sntech.de \
--cc=jdelvare@suse.com \
--cc=jernej.skrabec@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=macromorgan@hotmail.com \
--cc=naresh.solanki@9elements.com \
--cc=patrick.rudolph@9elements.com \
--cc=robh+dt@kernel.org \
--cc=sre@kernel.org \
--cc=vincent@vtremblay.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).