public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] regmap: Reorganise internal read/write functions.
@ 2012-05-31 14:11 Krystian Garbaciak
  2012-05-31 16:41 ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Krystian Garbaciak @ 2012-05-31 14:11 UTC (permalink / raw)
  To: Mark Brown; +Cc: Greg Kroah-Hartman, linux-kernel, Anthony Olech

Extract from _regmap_raw_write() and _regmap_raw_read() code responsible
for data formatting and bus access and place it in separate functions:
_regmap_bus_write() and _regmap_bus_read().

Signed-off-by: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
---
 drivers/base/regmap/regmap.c |   80 +++++++++++++++++++++++++-----------------
 1 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index bb80853..a365aa8 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -396,40 +396,11 @@ void regmap_exit(struct regmap *map)
 }
 EXPORT_SYMBOL_GPL(regmap_exit);
 
-static int _regmap_raw_write(struct regmap *map, unsigned int reg,
-			     const void *val, size_t val_len)
+static int _regmap_bus_write(struct regmap *map, unsigned int reg,
+			     void *val, size_t val_len)
 {
 	u8 *u8 = map->work_buf;
-	void *buf;
 	int ret = -ENOTSUPP;
-	size_t len;
-	int i;
-
-	/* Check for unwritable registers before we start */
-	if (map->writeable_reg)
-		for (i = 0; i < val_len / map->format.val_bytes; i++)
-			if (!map->writeable_reg(map->dev, reg + i))
-				return -EINVAL;
-
-	if (!map->cache_bypass && map->format.parse_val) {
-		unsigned int ival;
-		int val_bytes = map->format.val_bytes;
-		for (i = 0; i < val_len / val_bytes; i++) {
-			memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
-			ival = map->format.parse_val(map->work_buf);
-			ret = regcache_write(map, reg + i, ival);
-			if (ret) {
-				dev_err(map->dev,
-				   "Error in caching of register: %u ret: %d\n",
-					reg + i, ret);
-				return ret;
-			}
-		}
-		if (map->cache_only) {
-			map->cache_dirty = true;
-			return 0;
-		}
-	}
 
 	map->format.format_reg(map->work_buf, reg);
 
@@ -456,6 +427,9 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
 
 	/* If that didn't work fall back on linearising by hand. */
 	if (ret == -ENOTSUPP) {
+		void *buf;
+		size_t len;
+
 		len = map->format.reg_bytes + map->format.pad_bytes + val_len;
 		buf = kzalloc(len, GFP_KERNEL);
 		if (!buf)
@@ -475,6 +449,42 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,
 	return ret;
 }
 
+static int _regmap_raw_write(struct regmap *map, unsigned int reg,
+			     const void *val, size_t val_len)
+{
+	void *_val = (void *)val;
+	int i;
+	int ret;
+
+	/* Check for unwritable registers before we start */
+	if (map->writeable_reg)
+		for (i = 0; i < val_len / map->format.val_bytes; i++)
+			if (!map->writeable_reg(map->dev, reg + i))
+				return -EINVAL;
+
+	if (!map->cache_bypass && map->format.parse_val) {
+		unsigned int ival;
+		int val_bytes = map->format.val_bytes;
+		for (i = 0; i < val_len / map->format.val_bytes; i++) {
+			memcpy(map->work_buf, val + (i * val_bytes), val_bytes);
+			ival = map->format.parse_val(map->work_buf);
+			ret = regcache_write(map, reg + i, ival);
+			if (ret) {
+				dev_err(map->dev,
+				   "Error in caching of register: %u ret: %d\n",
+					reg + i, ret);
+				return ret;
+			}
+		}
+		if (map->cache_only) {
+			map->cache_dirty = true;
+			return 0;
+		}
+	}
+
+	return _regmap_bus_write(map, reg, _val, val_len);
+}
+
 int _regmap_write(struct regmap *map, unsigned int reg,
 		  unsigned int val)
 {
@@ -620,7 +630,7 @@ out:
 }
 EXPORT_SYMBOL_GPL(regmap_bulk_write);
 
-static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
+static int _regmap_bus_read(struct regmap *map, unsigned int reg, void *val,
 			    unsigned int val_len)
 {
 	u8 *u8 = map->work_buf;
@@ -649,6 +659,12 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
 	return ret;
 }
 
+static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
+			    unsigned int val_len)
+{
+	return _regmap_bus_read(map, reg, val, val_len);
+}
+
 static int _regmap_read(struct regmap *map, unsigned int reg,
 			unsigned int *val)
 {
-- 
1.7.0.4


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

* Re: [PATCH 1/4] regmap: Reorganise internal read/write functions.
  2012-05-31 14:11 [PATCH 1/4] regmap: Reorganise internal read/write functions Krystian Garbaciak
@ 2012-05-31 16:41 ` Mark Brown
  2012-05-31 17:53   ` Krystian Garbaciak
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2012-05-31 16:41 UTC (permalink / raw)
  To: Krystian Garbaciak; +Cc: Greg Kroah-Hartman, linux-kernel, Anthony Olech

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

On Thu, May 31, 2012 at 04:11:12PM +0200, Krystian Garbaciak wrote:

> +static int _regmap_raw_write(struct regmap *map, unsigned int reg,
> +			     const void *val, size_t val_len)
> +{
> +	void *_val = (void *)val;

This is scary...  why are we casting away const here?

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

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

* RE: [PATCH 1/4] regmap: Reorganise internal read/write functions.
  2012-05-31 16:41 ` Mark Brown
@ 2012-05-31 17:53   ` Krystian Garbaciak
  2012-05-31 17:57     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Krystian Garbaciak @ 2012-05-31 17:53 UTC (permalink / raw)
  To: Mark Brown
  Cc: Greg Kroah-Hartman, linux-kernel@vger.kernel.org, Anthony Olech

> On Thu, May 31, 2012 at 04:11:12PM +0200, Krystian Garbaciak wrote:
> 
> > +static int _regmap_raw_write(struct regmap *map, unsigned int reg,
> > +			     const void *val, size_t val_len) {
> > +	void *_val = (void *)val;
> 
> This is scary...  why are we casting away const here?

I will remove it from here.
However, on next patch I need to pass *val for reading and writing to the same function. I will put casting there and comment it.

Legal Disclaimer: This e-mail communication (and any attachment/s) is confidential and contains proprietary information, 
some or all of which may be legally privileged. It is intended solely for the use of the individual or entity to which it
is addressed. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, 
copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.

Please consider the environment before printing this e-mail

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

* Re: [PATCH 1/4] regmap: Reorganise internal read/write functions.
  2012-05-31 17:53   ` Krystian Garbaciak
@ 2012-05-31 17:57     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-05-31 17:57 UTC (permalink / raw)
  To: Krystian Garbaciak
  Cc: Greg Kroah-Hartman, linux-kernel@vger.kernel.org, Anthony Olech

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

On Thu, May 31, 2012 at 05:53:16PM +0000, Krystian Garbaciak wrote:

> However, on next patch I need to pass *val for reading and writing to
> the same function. I will put casting there and comment it.

No, let's do something type safe for this.

[-- 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-05-31 17:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-31 14:11 [PATCH 1/4] regmap: Reorganise internal read/write functions Krystian Garbaciak
2012-05-31 16:41 ` Mark Brown
2012-05-31 17:53   ` Krystian Garbaciak
2012-05-31 17:57     ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox