* [PATCH] regmap: Fix the size calculation for map->format.buf_size
@ 2012-06-01 0:10 Fabio Estevam
2012-06-01 0:17 ` Joe Perches
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Fabio Estevam @ 2012-06-01 0:10 UTC (permalink / raw)
To: broonie; +Cc: gregkh, marc, philippe.retornaz, linux-kernel, Fabio Estevam
From: Fabio Estevam <fabio.estevam@freescale.com>
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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
drivers/base/regmap/regmap.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 2aa076e..25c3d12 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -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;
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] regmap: Fix the size calculation for map->format.buf_size
2012-06-01 0:10 [PATCH] regmap: Fix the size calculation for map->format.buf_size Fabio Estevam
@ 2012-06-01 0:17 ` Joe Perches
2012-06-01 1:07 ` [PATCH v2] " Fabio Estevam
2012-06-03 12:28 ` [PATCH] " Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2012-06-01 0:17 UTC (permalink / raw)
To: Fabio Estevam
Cc: broonie, gregkh, marc, philippe.retornaz, linux-kernel, Fabio Estevam
On Thu, 2012-05-31 at 21:10 -0300, Fabio Estevam wrote:
> 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.
[]
> diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
[]
> @@ -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/ ?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] regmap: Fix the size calculation for map->format.buf_size
2012-06-01 0:10 [PATCH] regmap: Fix the size calculation for map->format.buf_size Fabio Estevam
2012-06-01 0:17 ` Joe Perches
@ 2012-06-01 1:07 ` Fabio Estevam
2012-06-03 12:28 ` [PATCH] " Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Fabio Estevam @ 2012-06-01 1:07 UTC (permalink / raw)
To: broonie; +Cc: gregkh, marc, philippe.retornaz, linux-kernel, joe, Fabio Estevam
From: Fabio Estevam <fabio.estevam@freescale.com>
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.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v1:
- Use BITS_PER_BYTE annotation
drivers/base/regmap/regmap.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 2aa076e..9d6b2f8 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -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
--
1.7.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] regmap: Fix the size calculation for map->format.buf_size
2012-06-01 0:10 [PATCH] regmap: Fix the size calculation for map->format.buf_size Fabio Estevam
2012-06-01 0:17 ` Joe Perches
2012-06-01 1:07 ` [PATCH v2] " Fabio Estevam
@ 2012-06-03 12:28 ` Mark Brown
2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-06-03 12:28 UTC (permalink / raw)
To: Fabio Estevam
Cc: gregkh, marc, philippe.retornaz, linux-kernel, Fabio Estevam
[-- Attachment #1: Type: text/plain, Size: 382 bytes --]
On Thu, May 31, 2012 at 09:10:30PM -0300, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
>
> 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.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-06-03 12:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-01 0:10 [PATCH] regmap: Fix the size calculation for map->format.buf_size Fabio Estevam
2012-06-01 0:17 ` Joe Perches
2012-06-01 1:07 ` [PATCH v2] " Fabio Estevam
2012-06-03 12:28 ` [PATCH] " Mark Brown
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).