From: Dan Carpenter <dan.carpenter@linaro.org>
To: Joy Chakraborty <joychakr@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Bingbu Cao <bingbu.cao@intel.com>,
Zhihao Cheng <chengzhihao1@huawei.com>,
Jerome Brunet <jbrunet@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-iio@vger.kernel.org, linux-media@vger.kernel.org,
linux-i2c@vger.kernel.org, linux-gpio@vger.kernel.org,
linux-mtd@lists.infradead.org, linux-rtc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, linux-sunxi@lists.linux.dev,
linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org,
manugautam@google.com
Subject: Re: [PATCH v1 07/17] misc: eeprom: at25: Change nvmem reg_read/write return type
Date: Thu, 6 Jun 2024 11:41:45 +0300 [thread overview]
Message-ID: <f98a1d8f-e936-4798-8447-c642e8fe11d5@moroto.mountain> (raw)
In-Reply-To: <20240605175953.2613260-8-joychakr@google.com>
On Wed, Jun 05, 2024 at 05:59:51PM +0000, Joy Chakraborty wrote:
> @@ -195,10 +195,11 @@ static struct attribute *sernum_attrs[] = {
> };
> ATTRIBUTE_GROUPS(sernum);
>
> -static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
> +static ssize_t at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
> {
> struct at25_data *at25 = priv;
> size_t maxsz = spi_max_transfer_size(at25->spi);
> + size_t bytes_written = count;
> const char *buf = val;
> int status = 0;
> unsigned buf_size;
> @@ -313,7 +314,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
> mutex_unlock(&at25->lock);
>
> kfree(bounce);
> - return status;
> + return status < 0 ? status : bytes_written;
> }
So the original bug was that rmem_read() is returning positive values
on success instead of zero[1]. That started a discussion about partial
reads which resulted in changing the API to support partial reads[2].
That patchset broke the build. This patchset is trying to fix the
build breakage.
[1] https://lore.kernel.org/all/20240206042408.224138-1-joychakr@google.com/
[2] https://lore.kernel.org/all/20240510082929.3792559-2-joychakr@google.com/
The bug in rmem_read() is still not fixed. That needs to be fixed as
a stand alone patch. We can discuss re-writing the API separately.
These functions are used internally and exported to the user through
sysfs via bin_attr_nvmem_read/write(). For internal users partial reads
should be treated as failure. What are we supposed to do with a partial
read? I don't think anyone has asked for partial reads to be supported
from sysfs either except Greg was wondering about it while reading the
code.
Currently, a lot of drivers return -EINVAL for partial read/writes but
some return success. It is a bit messy. But this patchset doesn't
really improve anything. In at24_read() we check if it's going to be a
partial read and return -EINVAL. Below we report a partial read as a
full read. It's just a more complicated way of doing exactly what we
were doing before.
drivers/misc/eeprom/at25.c
198 static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count)
199 {
200 struct at25_data *at25 = priv;
201 size_t maxsz = spi_max_transfer_size(at25->spi);
New: size_t bytes_written = count;
^^^^^^^^^^^^^^^^^^^^^
This is not the number of bytes written.
202 const char *buf = val;
203 int status = 0;
204 unsigned buf_size;
205 u8 *bounce;
206
207 if (unlikely(off >= at25->chip.byte_len))
208 return -EFBIG;
209 if ((off + count) > at25->chip.byte_len)
210 count = at25->chip.byte_len - off;
^^^^^
This is.
211 if (unlikely(!count))
212 return -EINVAL;
213
214 /* Temp buffer starts with command and address */
215 buf_size = at25->chip.page_size;
216 if (buf_size > io_limit)
217 buf_size = io_limit;
218 bounce = kmalloc(buf_size + at25->addrlen + 1, GFP_KERNEL);
219 if (!bounce)
220 return -ENOMEM;
221
regards,
dan carpenter
next prev parent reply other threads:[~2024-06-06 8:41 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-05 17:59 [PATCH v1 00/17] nvmem: Handle change of return type in reg_read/write() definition Joy Chakraborty
2024-06-05 17:59 ` [PATCH v1 01/17] hwmon: pmbus: adm1266: Change nvmem reg_read/write return type Joy Chakraborty
2024-06-05 21:29 ` Guenter Roeck
2024-06-06 9:22 ` Joy Chakraborty
2024-06-06 7:42 ` Dan Carpenter
2024-06-05 17:59 ` [PATCH v1 02/17] media: i2c: ov2740: " Joy Chakraborty
2024-06-05 17:59 ` [PATCH v1 03/17] media: i2c: video-i2c: " Joy Chakraborty
2024-06-05 17:59 ` [PATCH v1 04/17] iio: pressure: bmp280: " Joy Chakraborty
2024-06-05 17:59 ` [PATCH v1 05/17] misc: ds1682: " Joy Chakraborty
2024-06-05 21:18 ` Guenter Roeck
2024-06-06 9:24 ` Joy Chakraborty
2024-06-05 17:59 ` [PATCH v1 06/17] misc: eeprom: at24: " Joy Chakraborty
2024-06-06 10:12 ` Dan Carpenter
2024-06-05 17:59 ` [PATCH v1 07/17] misc: eeprom: at25: " Joy Chakraborty
2024-06-06 8:41 ` Dan Carpenter [this message]
2024-06-06 9:42 ` Joy Chakraborty
2024-06-06 10:10 ` Dan Carpenter
2024-06-06 10:31 ` Joy Chakraborty
2024-06-07 15:36 ` Srinivas Kandagatla
2024-06-05 17:59 ` [PATCH v1 08/17] misc: eeprom: 93xx46: " Joy Chakraborty
2024-06-05 17:59 ` [PATCH v1 09/17] misc: mchp_pci1xxxx: " Joy Chakraborty
2024-06-05 18:12 ` [PATCH v1 00/17] nvmem: Handle change of return type in reg_read/write() definition Srinivas Kandagatla
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=f98a1d8f-e936-4798-8447-c642e8fe11d5@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bingbu.cao@intel.com \
--cc=chengzhihao1@huawei.com \
--cc=gregkh@linuxfoundation.org \
--cc=jbrunet@baylibre.com \
--cc=joychakr@google.com \
--cc=lars@metafoo.de \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-rtc@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=manugautam@google.com \
--cc=martin.blumenstingl@googlemail.com \
--cc=sakari.ailus@linux.intel.com \
--cc=srinivas.kandagatla@linaro.org \
/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