This change removes a number of redundant checks on bin attribute
client's side, the same checks are done by sysfs_kf_bin_read() or
sysfs_kf_bin_write() caller from fs/sysfs/file.c.
Note, drivers/misc/pch_phub.c and drivers/misc/c2port/core.c may be
updated in a similar way, however this task is not done due to more
complicated read()/write() callbacks.
No functional change, hopefully.
Vladimir Zapolskiy (8):
misc: cxl: clean up afu_read_config()
misc: ds1682: clean up ds1682_eeprom_read() and ds1682_eeprom_write()
misc: eeprom: 93xx46: clean up eeprom_93xx46_bin_read/write
misc: eeprom: clean up eeprom_read()
misc: eeprom: max6875: clean up max6875_read()
misc: eeprom: at24: clean up at24_bin_write()
misc: eeprom: at25: move eeprom boundary checks to mem_read/mem_write
misc: eeprom: sunxi_sid: clean up sid_read()
drivers/misc/cxl/sysfs.c | 7 +------
drivers/misc/ds1682.c | 12 ------------
drivers/misc/eeprom/at24.c | 3 ---
drivers/misc/eeprom/at25.c | 28 ++++++++++++++--------------
drivers/misc/eeprom/eeprom.c | 5 -----
drivers/misc/eeprom/eeprom_93xx46.c | 14 --------------
drivers/misc/eeprom/max6875.c | 6 ------
drivers/misc/eeprom/sunxi_sid.c | 5 -----
8 files changed, 15 insertions(+), 65 deletions(-)
--
2.1.4
The sanity checks for overflow are not needed, because this is done on
caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
Cc: [email protected]
Cc: Ian Munsie <[email protected]>
Cc: Michael Neuling <[email protected]>
---
drivers/misc/cxl/sysfs.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c
index 31f38bc..87cd747 100644
--- a/drivers/misc/cxl/sysfs.c
+++ b/drivers/misc/cxl/sysfs.c
@@ -443,12 +443,7 @@ static ssize_t afu_read_config(struct file *filp, struct kobject *kobj,
struct afu_config_record *cr = to_cr(kobj);
struct cxl_afu *afu = to_cxl_afu(container_of(kobj->parent, struct device, kobj));
- u64 i, j, val, size = afu->crs_len;
-
- if (off > size)
- return 0;
- if (off + count > size)
- count = size - off;
+ u64 i, j, val;
for (i = 0; i < count;) {
val = cxl_afu_cr_read64(afu, cr->cr, off & ~0x7);
--
2.1.4
The change removes redundant sysfs binary file boundary checks, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
drivers/misc/ds1682.c | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/drivers/misc/ds1682.c b/drivers/misc/ds1682.c
index b909fb3..c711227 100644
--- a/drivers/misc/ds1682.c
+++ b/drivers/misc/ds1682.c
@@ -148,12 +148,6 @@ static ssize_t ds1682_eeprom_read(struct file *filp, struct kobject *kobj,
dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
buf, off, count);
- if (off >= DS1682_EEPROM_SIZE)
- return 0;
-
- if (off + count > DS1682_EEPROM_SIZE)
- count = DS1682_EEPROM_SIZE - off;
-
rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
count, buf);
if (rc < 0)
@@ -171,12 +165,6 @@ static ssize_t ds1682_eeprom_write(struct file *filp, struct kobject *kobj,
dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
buf, off, count);
- if (off >= DS1682_EEPROM_SIZE)
- return -ENOSPC;
-
- if (off + count > DS1682_EEPROM_SIZE)
- count = DS1682_EEPROM_SIZE - off;
-
/* Write out to the device */
if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
count, buf) < 0)
--
2.1.4
The change removes redundant sysfs binary file boundary checks, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
drivers/misc/eeprom/eeprom_93xx46.c | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/drivers/misc/eeprom/eeprom_93xx46.c b/drivers/misc/eeprom/eeprom_93xx46.c
index 9ebeacd..a6bd9e3 100644
--- a/drivers/misc/eeprom/eeprom_93xx46.c
+++ b/drivers/misc/eeprom/eeprom_93xx46.c
@@ -48,13 +48,6 @@ eeprom_93xx46_bin_read(struct file *filp, struct kobject *kobj,
dev = container_of(kobj, struct device, kobj);
edev = dev_get_drvdata(dev);
- if (unlikely(off >= edev->bin.size))
- return 0;
- if ((off + count) > edev->bin.size)
- count = edev->bin.size - off;
- if (unlikely(!count))
- return count;
-
cmd_addr = OP_READ << edev->addrlen;
if (edev->addrlen == 7) {
@@ -200,13 +193,6 @@ eeprom_93xx46_bin_write(struct file *filp, struct kobject *kobj,
dev = container_of(kobj, struct device, kobj);
edev = dev_get_drvdata(dev);
- if (unlikely(off >= edev->bin.size))
- return -EFBIG;
- if ((off + count) > edev->bin.size)
- count = edev->bin.size - off;
- if (unlikely(!count))
- return count;
-
/* only write even number of bytes on 16-bit devices */
if (edev->addrlen == 6) {
step = 2;
--
2.1.4
The change removes redundant sysfs binary file boundary check, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
Cc: Jean Delvare <[email protected]>
---
drivers/misc/eeprom/eeprom.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
index b432873..7342fd6 100644
--- a/drivers/misc/eeprom/eeprom.c
+++ b/drivers/misc/eeprom/eeprom.c
@@ -88,11 +88,6 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
struct eeprom_data *data = i2c_get_clientdata(client);
u8 slice;
- if (off > EEPROM_SIZE)
- return 0;
- if (off + count > EEPROM_SIZE)
- count = EEPROM_SIZE - off;
-
/* Only refresh slices which contain requested bytes */
for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++)
eeprom_update_client(client, slice);
--
2.1.4
The change removes redundant sysfs binary file boundary check, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
drivers/misc/eeprom/max6875.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/drivers/misc/eeprom/max6875.c b/drivers/misc/eeprom/max6875.c
index 580ff9d..9aa4332 100644
--- a/drivers/misc/eeprom/max6875.c
+++ b/drivers/misc/eeprom/max6875.c
@@ -114,12 +114,6 @@ static ssize_t max6875_read(struct file *filp, struct kobject *kobj,
struct max6875_data *data = i2c_get_clientdata(client);
int slice, max_slice;
- if (off > USER_EEPROM_SIZE)
- return 0;
-
- if (off + count > USER_EEPROM_SIZE)
- count = USER_EEPROM_SIZE - off;
-
/* refresh slices which contain requested bytes */
max_slice = (off + count - 1) >> SLICE_BITS;
for (slice = (off >> SLICE_BITS); slice <= max_slice; slice++)
--
2.1.4
The change removes redundant sysfs binary file boundary check, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
Cc: [email protected]
Cc: Wolfram Sang <[email protected]>
---
drivers/misc/eeprom/at24.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2d3db81..6ded3dc 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -438,9 +438,6 @@ static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj,
{
struct at24_data *at24;
- if (unlikely(off >= attr->size))
- return -EFBIG;
-
at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
return at24_write(at24, buf, off, count);
}
--
2.1.4
The sanity checks for overflow over eeprom size are not needed, if
eeprom is accessed from userspace over sysfs interface, because this
is handled by fs/sysfs/file.c, however in case of reading or writing
within the kernel it might be still reasonable to pass the check.
The change moves these checks from shared at25_ee_read() and
at25_ee_write() directly to at25_mem_read() and at25_mem_write(), no
functional change.
Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
drivers/misc/eeprom/at25.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c
index 0a1af93..c4f5c4a 100644
--- a/drivers/misc/eeprom/at25.c
+++ b/drivers/misc/eeprom/at25.c
@@ -77,13 +77,6 @@ at25_ee_read(
struct spi_message m;
u8 instr;
- if (unlikely(offset >= at25->bin.size))
- return 0;
- if ((offset + count) > at25->bin.size)
- count = at25->bin.size - offset;
- if (unlikely(!count))
- return count;
-
cp = command;
instr = AT25_READ;
@@ -155,13 +148,6 @@ at25_ee_write(struct at25_data *at25, const char *buf, loff_t off,
unsigned buf_size;
u8 *bounce;
- if (unlikely(off >= at25->bin.size))
- return -EFBIG;
- if ((off + count) > at25->bin.size)
- count = at25->bin.size - off;
- if (unlikely(!count))
- return count;
-
/* Temp buffer starts with command and address */
buf_size = at25->chip.page_size;
if (buf_size > io_limit)
@@ -288,6 +274,13 @@ static ssize_t at25_mem_read(struct memory_accessor *mem, char *buf,
{
struct at25_data *at25 = container_of(mem, struct at25_data, mem);
+ if (unlikely(offset >= at25->bin.size))
+ return 0;
+ if ((offset + count) > at25->bin.size)
+ count = at25->bin.size - offset;
+ if (unlikely(!count))
+ return count;
+
return at25_ee_read(at25, buf, offset, count);
}
@@ -296,7 +289,13 @@ static ssize_t at25_mem_write(struct memory_accessor *mem, const char *buf,
{
struct at25_data *at25 = container_of(mem, struct at25_data, mem);
+ if (unlikely(offset >= at25->bin.size))
+ return -EFBIG;
+ if ((offset + count) > at25->bin.size)
+ count = at25->bin.size - offset;
+ if (unlikely(!count))
+ return count;
+
return at25_ee_write(at25, buf, offset, count);
}
--
2.1.4
The change removes redundant sysfs binary file boundary checks, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
Cc: [email protected]
Cc: Maxime Ripard <[email protected]>
---
drivers/misc/eeprom/sunxi_sid.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
index 8385177..26ce99d 100644
--- a/drivers/misc/eeprom/sunxi_sid.c
+++ b/drivers/misc/eeprom/sunxi_sid.c
@@ -70,11 +70,6 @@ static ssize_t sid_read(struct file *fd, struct kobject *kobj,
pdev = to_platform_device(kobj_to_dev(kobj));
sid_data = platform_get_drvdata(pdev);
- if (pos < 0 || pos >= sid_data->keysize)
- return 0;
- if (size > sid_data->keysize - pos)
- size = sid_data->keysize - pos;
-
for (i = 0; i < size; i++)
buf[i] = sunxi_sid_read_byte(sid_data, pos + i);
--
2.1.4
Hi,
Reviewed-by: Daniel Axtens <[email protected]>
FWIW, Ian is on leave for 2 weeks and Mikey for 1 week. However, as one
of the other CXL developers I'm very happy for this patch to go in.
Regards,
Daniel
On Mon, 2015-07-27 at 00:18 +0300, Vladimir Zapolskiy wrote:
> The sanity checks for overflow are not needed, because this is done on
> caller side in fs/sysfs/file.c
>
> Signed-off-by: Vladimir Zapolskiy <[email protected]>
> Cc: [email protected]
> Cc: Ian Munsie <[email protected]>
> Cc: Michael Neuling <[email protected]>
> ---
> drivers/misc/cxl/sysfs.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c
> index 31f38bc..87cd747 100644
> --- a/drivers/misc/cxl/sysfs.c
> +++ b/drivers/misc/cxl/sysfs.c
> @@ -443,12 +443,7 @@ static ssize_t afu_read_config(struct file *filp, struct kobject *kobj,
> struct afu_config_record *cr = to_cr(kobj);
> struct cxl_afu *afu = to_cxl_afu(container_of(kobj->parent, struct device, kobj));
>
> - u64 i, j, val, size = afu->crs_len;
> -
> - if (off > size)
> - return 0;
> - if (off + count > size)
> - count = size - off;
> + u64 i, j, val;
>
> for (i = 0; i < count;) {
> val = cxl_afu_cr_read64(afu, cr->cr, off & ~0x7);
On Mon, Jul 27, 2015 at 12:18:51AM +0300, Vladimir Zapolskiy wrote:
> The change removes redundant sysfs binary file boundary check, since
> this task is already done on caller side in fs/sysfs/file.c
>
> Signed-off-by: Vladimir Zapolskiy <[email protected]>
> Cc: [email protected]
> Cc: Wolfram Sang <[email protected]>
Applied to for-current, thanks!
On Mon, 27 Jul 2015 00:18:49 +0300, Vladimir Zapolskiy wrote:
> The change removes redundant sysfs binary file boundary check, since
> this task is already done on caller side in fs/sysfs/file.c
>
> Signed-off-by: Vladimir Zapolskiy <[email protected]>
> Cc: Jean Delvare <[email protected]>
> ---
> drivers/misc/eeprom/eeprom.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/drivers/misc/eeprom/eeprom.c b/drivers/misc/eeprom/eeprom.c
> index b432873..7342fd6 100644
> --- a/drivers/misc/eeprom/eeprom.c
> +++ b/drivers/misc/eeprom/eeprom.c
> @@ -88,11 +88,6 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
> struct eeprom_data *data = i2c_get_clientdata(client);
> u8 slice;
>
> - if (off > EEPROM_SIZE)
> - return 0;
> - if (off + count > EEPROM_SIZE)
> - count = EEPROM_SIZE - off;
> -
> /* Only refresh slices which contain requested bytes */
> for (slice = off >> 5; slice <= (off + count - 1) >> 5; slice++)
> eeprom_update_client(client, slice);
Thanks for the clean-up.
Reviewed-by: Jean Delvare <[email protected]>
--
Jean Delvare
SUSE L3 Support
On Mon, 2015-07-27 at 00:18 +0300, Vladimir Zapolskiy wrote:
> The sanity checks for overflow are not needed, because this is done on
> caller side in fs/sysfs/file.c
>
> Signed-off-by: Vladimir Zapolskiy <[email protected]>
> Cc: [email protected]
> Cc: Ian Munsie <[email protected]>
> Cc: Michael Neuling <[email protected]>
Acked-by: Michael Neuling <[email protected]>
> ---
> drivers/misc/cxl/sysfs.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/misc/cxl/sysfs.c b/drivers/misc/cxl/sysfs.c
> index 31f38bc..87cd747 100644
> --- a/drivers/misc/cxl/sysfs.c
> +++ b/drivers/misc/cxl/sysfs.c
> @@ -443,12 +443,7 @@ static ssize_t afu_read_config(struct file *filp, struct kobject *kobj,
> struct afu_config_record *cr = to_cr(kobj);
> struct cxl_afu *afu = to_cxl_afu(container_of(kobj->parent, struct device, kobj));
>
> - u64 i, j, val, size = afu->crs_len;
> -
> - if (off > size)
> - return 0;
> - if (off + count > size)
> - count = size - off;
> + u64 i, j, val;
>
> for (i = 0; i < count;) {
> val = cxl_afu_cr_read64(afu, cr->cr, off & ~0x7);
Vladimir,
On Mon, Jul 27, 2015 at 12:18:22AM +0300, Vladimir Zapolskiy wrote:
> This change removes a number of redundant checks on bin attribute
> client's side, the same checks are done by sysfs_kf_bin_read() or
> sysfs_kf_bin_write() caller from fs/sysfs/file.c.
>
> Note, drivers/misc/pch_phub.c and drivers/misc/c2port/core.c may be
> updated in a similar way, however this task is not done due to more
> complicated read()/write() callbacks.
Can you resend the patches which touch i2c drivers with me on cc? I'd
like to take care of them.
Thanks,
Wolfram
Hi Wolfram,
On 07.08.2015 19:10, Wolfram Sang wrote:
> Vladimir,
>
> On Mon, Jul 27, 2015 at 12:18:22AM +0300, Vladimir Zapolskiy wrote:
>> This change removes a number of redundant checks on bin attribute
>> client's side, the same checks are done by sysfs_kf_bin_read() or
>> sysfs_kf_bin_write() caller from fs/sysfs/file.c.
>>
>> Note, drivers/misc/pch_phub.c and drivers/misc/c2port/core.c may be
>> updated in a similar way, however this task is not done due to more
>> complicated read()/write() callbacks.
>
> Can you resend the patches which touch i2c drivers with me on cc? I'd
> like to take care of them.
if we're talking about this particular series, you should have them in
your mailbox, since you have them applied in wsa/i2c/for-next:
commit d12c0aaf3780c5b26b4ea9e795252381f586c063
Author: Vladimir Zapolskiy <[email protected]>
Date: Mon Jul 27 00:18:51 2015 +0300
misc: eeprom: at24: clean up at24_bin_write()
The change removes redundant sysfs binary file boundary check, since
this task is already done on caller side in fs/sysfs/file.c
Signed-off-by: Vladimir Zapolskiy <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
commit 1f023297f7f77d434ecc221018d2e181eac0ae36
Author: Vladimir Zapolskiy <[email protected]>
Date: Mon Jul 27 00:16:31 2015 +0300
i2c: slave eeprom: clean up sysfs bin attribute read()/write()
The change removes redundant sysfs binary file boundary checks,
since this task is already done on caller side in fs/sysfs/file.c
Note, on file size overflow read() now returns 0, and this is a
correct and expected EOF notification according to POSIX.
Signed-off-by: Vladimir Zapolskiy <[email protected]>
Signed-off-by: Wolfram Sang <[email protected]>
Do you want me to send them to you again anyway?
--
With best wishes,
Vladimir
> if we're talking about this particular series, you should have them in
> your mailbox, since you have them applied in wsa/i2c/for-next:
Those are already in linus tree. I mean all drivers which use struct
i2c_driver. Or do you prefer they go via Greg? I am fine with both.
Hi Wolfram,
On 08.08.2015 01:34, Wolfram Sang wrote:
>
>> if we're talking about this particular series, you should have them in
>> your mailbox, since you have them applied in wsa/i2c/for-next:
>
> Those are already in linus tree. I mean all drivers which use struct
> i2c_driver. Or do you prefer they go via Greg? I am fine with both.
>
I think you may find most of the changes applied by Greg into
misc/char-misc-next branch.
The only change from the series, which is not found in
misc/char-misc-next or i2c/for-next is related to at25 driver (IC is
sitting on SPI):
https://lkml.org/lkml/2015/7/26/101
Change 8/8 for sunxi is outdated due to accepted NVMEM framework.
With best wishes,
Vladimir
On Sat, Aug 08, 2015 at 03:51:54PM +0300, Vladimir Zapolskiy wrote:
> Hi Wolfram,
>
> On 08.08.2015 01:34, Wolfram Sang wrote:
> >
> >> if we're talking about this particular series, you should have them in
> >> your mailbox, since you have them applied in wsa/i2c/for-next:
> >
> > Those are already in linus tree. I mean all drivers which use struct
> > i2c_driver. Or do you prefer they go via Greg? I am fine with both.
> >
>
> I think you may find most of the changes applied by Greg into
> misc/char-misc-next branch.
Great, thanks for the heads up!