Skip to contentSkip to conversation

regmap: Fix the size calculation for map->format.buf_size

PATCH Applied Fabio Estevam 3 participants 4 messages Jun 1, 2012 – Jun 3, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regmap: Fix the size calculation for map->format.buf_size

From: Fabio Estevam <[email protected]>

The word to be transmitted/received via regmap is composed by the following parts:

config->reg_bits
config->val_bits
config->pad_bits

,so the total size should be calculated by summing up the number of bits of each element and using a DIV_ROUND_UP to return the number of bytes.

---
 drivers/base/regmap/regmap.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/base/regmap/regmap.c +2 -2
index 2aa076e..25c3d12 100644
@@ -246,11 +246,11 @@ struct regmap *regmap_init(struct device *dev,
 		map->lock = regmap_lock_mutex;
 		map->unlock = regmap_unlock_mutex;
 	}
-	map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
 	map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
 	map->format.pad_bytes = config->pad_bits / 8;
 	map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
-	map->format.buf_size += map->format.pad_bytes;
+	map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
+			config->val_bits + config->pad_bits, 8);
 	map->reg_shift = config->pad_bits % 8;
 	if (config->reg_stride)
 		map->reg_stride = config->reg_stride;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 2 lines · Fabio Estevam

the total size should be calculated by summing up the number of bits of each element and using a DIV_ROUND_UP to return the number of bytes.

[]

drivers/base/regmap/regmap.c

Quoted 1 line
drivers/base/regmap/regmap.c +0 -0

[]

drivers/base/regmap/regmap.c struct regmap *regmap_init(struct device *dev, · line 254

Quoted 12 lines
drivers/base/regmap/regmap.c +2 -2
@@ -246,11 +246,11 @@ struct regmap *regmap_init(struct device *dev,
 		map->lock = regmap_lock_mutex;
 		map->unlock = regmap_unlock_mutex;
 	}
-	map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
 	map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
 	map->format.pad_bytes = config->pad_bits / 8;
 	map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
-	map->format.buf_size += map->format.pad_bytes;
+	map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
+			config->val_bits + config->pad_bits, 8);
 	map->reg_shift = config->pad_bits % 8;

s/8/BITS_PER_BYTE/ ?

#2 lore raw

PATCH v2 1/1 regmap: Fix the size calculation for map->format.buf_size

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

The word to be transmitted/received via regmap is composed by the following parts:

config->reg_bits
config->val_bits
config->pad_bits

,so the total size should be calculated by summing up the number of bits of each element and using a DIV_ROUND_UP to return the number of bytes.

While at it also use BITS_PER_BYTE annotation.

---
Changes since v1:
- Use BITS_PER_BYTE annotation

 drivers/base/regmap/regmap.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/base/regmap/regmap.c +6 -6
index 2aa076e..9d6b2f8 100644
@@ -246,12 +246,12 @@ struct regmap *regmap_init(struct device *dev,
 		map->lock = regmap_lock_mutex;
 		map->unlock = regmap_unlock_mutex;
 	}
-	map->format.buf_size = (config->reg_bits + config->val_bits) / 8;
-	map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, 8);
-	map->format.pad_bytes = config->pad_bits / 8;
-	map->format.val_bytes = DIV_ROUND_UP(config->val_bits, 8);
-	map->format.buf_size += map->format.pad_bytes;
-	map->reg_shift = config->pad_bits % 8;
+	map->format.reg_bytes = DIV_ROUND_UP(config->reg_bits, BITS_PER_BYTE);
+	map->format.pad_bytes = config->pad_bits / BITS_PER_BYTE;
+	map->format.val_bytes = DIV_ROUND_UP(config->val_bits, BITS_PER_BYTE);
+	map->format.buf_size = DIV_ROUND_UP(config->reg_bits +
+			config->val_bits + config->pad_bits, BITS_PER_BYTE);
+	map->reg_shift = config->pad_bits % BITS_PER_BYTE;
 	if (config->reg_stride)
 		map->reg_stride = config->reg_stride;
 	else
Signature · 1 line
1.7.1
Applied
#3 lore raw
In reply to Fabio Estevam
Quoted 4 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

The word to be transmitted/received via regmap is composed by the following parts:

Applied, thanks. The BITS_PER_BYTE thing isn't an entirely bad idea but I'd like to go through the entire codebase and do that rather than do a little bit at a time.