linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] power: clean up bin attribute read/write functions
@ 2015-07-26 21:26 Vladimir Zapolskiy
  2015-07-26 21:26 ` [PATCH 1/3] power: ds2780_battery: clean up eeprom " Vladimir Zapolskiy
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-26 21:26 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse
  Cc: linux-pm, Greg Kroah-Hartman

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.

No functional change, hopefully.

Vladimir Zapolskiy (3):
  power: ds2780_battery: clean up eeprom read/write functions
  power: ds2781_battery: clean up eeprom read/write functions
  power: olpc_battery: clean up eeprom read function

 drivers/power/ds2780_battery.c | 20 ++------------------
 drivers/power/ds2781_battery.c |  8 --------
 drivers/power/olpc_battery.c   |  7 +------
 3 files changed, 3 insertions(+), 32 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] power: ds2780_battery: clean up eeprom read/write functions
  2015-07-26 21:26 [PATCH 0/3] power: clean up bin attribute read/write functions Vladimir Zapolskiy
@ 2015-07-26 21:26 ` Vladimir Zapolskiy
  2015-07-26 21:26 ` [PATCH 2/3] power: ds2781_battery: " Vladimir Zapolskiy
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-26 21:26 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse
  Cc: linux-pm, Greg Kroah-Hartman

The change removes redundant sysfs binary file boundary checks while
reading or writing "param_eeprom" or "user_eeprom", the checks are not
needed, since this task is done on caller side in fs/sysfs/file.c

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 drivers/power/ds2780_battery.c | 20 ++------------------
 1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/drivers/power/ds2780_battery.c b/drivers/power/ds2780_battery.c
index a7a0427..d3743d0 100644
--- a/drivers/power/ds2780_battery.c
+++ b/drivers/power/ds2780_battery.c
@@ -637,10 +637,6 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
 	struct power_supply *psy = to_power_supply(dev);
 	struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
 
-	count = min_t(loff_t, count,
-		DS2780_EEPROM_BLOCK1_END -
-		DS2780_EEPROM_BLOCK1_START + 1 - off);
-
 	return ds2780_read_block(dev_info, buf,
 				DS2780_EEPROM_BLOCK1_START + off, count);
 }
@@ -655,10 +651,6 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
 	struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
 	int ret;
 
-	count = min_t(loff_t, count,
-		DS2780_EEPROM_BLOCK1_END -
-		DS2780_EEPROM_BLOCK1_START + 1 - off);
-
 	ret = ds2780_write(dev_info, buf,
 				DS2780_EEPROM_BLOCK1_START + off, count);
 	if (ret < 0)
@@ -676,7 +668,7 @@ static struct bin_attribute ds2780_param_eeprom_bin_attr = {
 		.name = "param_eeprom",
 		.mode = S_IRUGO | S_IWUSR,
 	},
-	.size = DS2780_EEPROM_BLOCK1_END - DS2780_EEPROM_BLOCK1_START + 1,
+	.size = DS2780_PARAM_EEPROM_SIZE,
 	.read = ds2780_read_param_eeprom_bin,
 	.write = ds2780_write_param_eeprom_bin,
 };
@@ -690,10 +682,6 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
 	struct power_supply *psy = to_power_supply(dev);
 	struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
 
-	count = min_t(loff_t, count,
-		DS2780_EEPROM_BLOCK0_END -
-		DS2780_EEPROM_BLOCK0_START + 1 - off);
-
 	return ds2780_read_block(dev_info, buf,
 				DS2780_EEPROM_BLOCK0_START + off, count);
 }
@@ -708,10 +696,6 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
 	struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
 	int ret;
 
-	count = min_t(loff_t, count,
-		DS2780_EEPROM_BLOCK0_END -
-		DS2780_EEPROM_BLOCK0_START + 1 - off);
-
 	ret = ds2780_write(dev_info, buf,
 				DS2780_EEPROM_BLOCK0_START + off, count);
 	if (ret < 0)
@@ -729,7 +713,7 @@ static struct bin_attribute ds2780_user_eeprom_bin_attr = {
 		.name = "user_eeprom",
 		.mode = S_IRUGO | S_IWUSR,
 	},
-	.size = DS2780_EEPROM_BLOCK0_END - DS2780_EEPROM_BLOCK0_START + 1,
+	.size = DS2780_USER_EEPROM_SIZE,
 	.read = ds2780_read_user_eeprom_bin,
 	.write = ds2780_write_user_eeprom_bin,
 };
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] power: ds2781_battery: clean up eeprom read/write functions
  2015-07-26 21:26 [PATCH 0/3] power: clean up bin attribute read/write functions Vladimir Zapolskiy
  2015-07-26 21:26 ` [PATCH 1/3] power: ds2780_battery: clean up eeprom " Vladimir Zapolskiy
@ 2015-07-26 21:26 ` Vladimir Zapolskiy
  2015-07-26 21:26 ` [PATCH 3/3] power: olpc_battery: clean up eeprom read function Vladimir Zapolskiy
  2015-07-27 14:43 ` [PATCH 0/3] power: clean up bin attribute read/write functions Sebastian Reichel
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-26 21:26 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse
  Cc: linux-pm, Greg Kroah-Hartman

The change removes redundant calculation of left space on eeprom while
reading or writing "param_eeprom" or "user_eeprom", the checks are not
needed, since this task is done on caller side in fs/sysfs/file.c

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 drivers/power/ds2781_battery.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/power/ds2781_battery.c b/drivers/power/ds2781_battery.c
index 56d583d..c368002 100644
--- a/drivers/power/ds2781_battery.c
+++ b/drivers/power/ds2781_battery.c
@@ -639,8 +639,6 @@ static ssize_t ds2781_read_param_eeprom_bin(struct file *filp,
 	struct power_supply *psy = to_power_supply(dev);
 	struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
 
-	count = min_t(loff_t, count, DS2781_PARAM_EEPROM_SIZE - off);
-
 	return ds2781_read_block(dev_info, buf,
 				DS2781_EEPROM_BLOCK1_START + off, count);
 }
@@ -655,8 +653,6 @@ static ssize_t ds2781_write_param_eeprom_bin(struct file *filp,
 	struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
 	int ret;
 
-	count = min_t(loff_t, count, DS2781_PARAM_EEPROM_SIZE - off);
-
 	ret = ds2781_write(dev_info, buf,
 				DS2781_EEPROM_BLOCK1_START + off, count);
 	if (ret < 0)
@@ -688,8 +684,6 @@ static ssize_t ds2781_read_user_eeprom_bin(struct file *filp,
 	struct power_supply *psy = to_power_supply(dev);
 	struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
 
-	count = min_t(loff_t, count, DS2781_USER_EEPROM_SIZE - off);
-
 	return ds2781_read_block(dev_info, buf,
 				DS2781_EEPROM_BLOCK0_START + off, count);
 
@@ -705,8 +699,6 @@ static ssize_t ds2781_write_user_eeprom_bin(struct file *filp,
 	struct ds2781_device_info *dev_info = to_ds2781_device_info(psy);
 	int ret;
 
-	count = min_t(loff_t, count, DS2781_USER_EEPROM_SIZE - off);
-
 	ret = ds2781_write(dev_info, buf,
 				DS2781_EEPROM_BLOCK0_START + off, count);
 	if (ret < 0)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] power: olpc_battery: clean up eeprom read function
  2015-07-26 21:26 [PATCH 0/3] power: clean up bin attribute read/write functions Vladimir Zapolskiy
  2015-07-26 21:26 ` [PATCH 1/3] power: ds2780_battery: clean up eeprom " Vladimir Zapolskiy
  2015-07-26 21:26 ` [PATCH 2/3] power: ds2781_battery: " Vladimir Zapolskiy
@ 2015-07-26 21:26 ` Vladimir Zapolskiy
  2015-07-27 14:43 ` [PATCH 0/3] power: clean up bin attribute read/write functions Sebastian Reichel
  3 siblings, 0 replies; 5+ messages in thread
From: Vladimir Zapolskiy @ 2015-07-26 21:26 UTC (permalink / raw)
  To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse
  Cc: linux-pm, Greg Kroah-Hartman

The change removes redundant sysfs binary file boundary check while
reading eeprom content from userspace, the check is done on caller
side in fs/sysfs/file.c, if binary attribute size is not zero.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
---
 drivers/power/olpc_battery.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index a944338..9e29b13 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -521,11 +521,6 @@ static ssize_t olpc_bat_eeprom_read(struct file *filp, struct kobject *kobj,
 	int ret;
 	int i;
 
-	if (off >= EEPROM_SIZE)
-		return 0;
-	if (off + count > EEPROM_SIZE)
-		count = EEPROM_SIZE - off;
-
 	for (i = 0; i < count; i++) {
 		ec_byte = EEPROM_START + off + i;
 		ret = olpc_ec_cmd(EC_BAT_EEPROM, &ec_byte, 1, &buf[i], 1);
@@ -545,7 +540,7 @@ static struct bin_attribute olpc_bat_eeprom = {
 		.name = "eeprom",
 		.mode = S_IRUGO,
 	},
-	.size = 0,
+	.size = EEPROM_SIZE,
 	.read = olpc_bat_eeprom_read,
 };
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] power: clean up bin attribute read/write functions
  2015-07-26 21:26 [PATCH 0/3] power: clean up bin attribute read/write functions Vladimir Zapolskiy
                   ` (2 preceding siblings ...)
  2015-07-26 21:26 ` [PATCH 3/3] power: olpc_battery: clean up eeprom read function Vladimir Zapolskiy
@ 2015-07-27 14:43 ` Sebastian Reichel
  3 siblings, 0 replies; 5+ messages in thread
From: Sebastian Reichel @ 2015-07-27 14:43 UTC (permalink / raw)
  To: Vladimir Zapolskiy
  Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-pm,
	Greg Kroah-Hartman

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

Hi,

On Mon, Jul 27, 2015 at 12:26:46AM +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.
> 
> No functional change, hopefully.

Thanks, queued.

-- Sebastian

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-07-27 14:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-26 21:26 [PATCH 0/3] power: clean up bin attribute read/write functions Vladimir Zapolskiy
2015-07-26 21:26 ` [PATCH 1/3] power: ds2780_battery: clean up eeprom " Vladimir Zapolskiy
2015-07-26 21:26 ` [PATCH 2/3] power: ds2781_battery: " Vladimir Zapolskiy
2015-07-26 21:26 ` [PATCH 3/3] power: olpc_battery: clean up eeprom read function Vladimir Zapolskiy
2015-07-27 14:43 ` [PATCH 0/3] power: clean up bin attribute read/write functions Sebastian Reichel

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).