mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Bolle <pebolle@tiscali.nl>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Stephen Warren <swarren@wwwdotorg.org>,
	linux-kernel@vger.kernel.org, Stephen Warren <swarren@nvidia.com>,
	Laxman Dewangan <ldewangan@nvidia.com>
Subject: Re: [PATCH] regmap: don't corrupt work buffer in _regmap_raw_write()
Date: Mon, 08 Apr 2013 12:24:22 +0200	[thread overview]
Message-ID: <1365416662.1830.86.camel@x61.thuisdomein> (raw)
In-Reply-To: <20130321190939.GI15926@opensource.wolfsonmicro.com>

On Thu, 2013-03-21 at 20:09 +0100, Mark Brown wrote:
> On Wed, Mar 20, 2013 at 05:02:02PM -0600, Stephen Warren wrote:
> > _regmap_raw_write() contains code to call regcache_write() to write
> > values to the cache. That code calls memcpy() to copy the value data to
> > the start of the work_buf. However, at least when _regmap_raw_write() is
> 
> Applied, thanks.

0) This patch ended up as mainline commit
bc8ce4afd7ee7e1421c935d24b1f879f82afdd4e, which is part of v3.9-rc6.

1) Building regmap.o now triggers this warning:
    drivers/base/regmap/regmap.c: In function ‘_regmap_raw_write’:
    drivers/base/regmap/regmap.c:946:4: warning: passing argument 1 of ‘map->format.parse_val’ discards ‘const’ qualifier from pointer target type [enabled by default]
    drivers/base/regmap/regmap.c:946:4: note: expected ‘void *’ but argument is of type ‘const void *’

2) The following (draft) patch silences this warning. I'm a bit
uncertain what the regmap_parse_*() functions are meant to do. So I'd
like to first ask whether something along these lines is acceptable.


Paul Bolle

diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index 5a22bd3..35877b7 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -38,7 +38,7 @@ struct regmap_format {
                             unsigned int reg, unsigned int val);
        void (*format_reg)(void *buf, unsigned int reg, unsigned int shift);
        void (*format_val)(void *buf, unsigned int val, unsigned int shift);
-       unsigned int (*parse_val)(void *buf);
+       unsigned int (*parse_val)(const void *buf);
 };
 
 struct regmap_async {
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index d34adef..2ca90a6 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -228,30 +228,28 @@ static void regmap_format_32_native(void *buf, unsigned int val,
        *(u32 *)buf = val << shift;
 }
 
-static unsigned int regmap_parse_8(void *buf)
+static unsigned int regmap_parse_8(const void *buf)
 {
-       u8 *b = buf;
+       const u8 *b = buf;
 
        return b[0];
 }
 
-static unsigned int regmap_parse_16_be(void *buf)
+static unsigned int regmap_parse_16_be(const void *buf)
 {
-       __be16 *b = buf;
+       const __be16 *b = buf;
 
-       b[0] = be16_to_cpu(b[0]);
-
-       return b[0];
+       return be16_to_cpu(b[0]);
 }
 
-static unsigned int regmap_parse_16_native(void *buf)
+static unsigned int regmap_parse_16_native(const void *buf)
 {
        return *(u16 *)buf;
 }
 
-static unsigned int regmap_parse_24(void *buf)
+static unsigned int regmap_parse_24(const void *buf)
 {
-       u8 *b = buf;
+       const u8 *b = buf;
        unsigned int ret = b[2];
        ret |= ((unsigned int)b[1]) << 8;
        ret |= ((unsigned int)b[0]) << 16;
@@ -259,16 +257,14 @@ static unsigned int regmap_parse_24(void *buf)
        return ret;
 }
 
-static unsigned int regmap_parse_32_be(void *buf)
+static unsigned int regmap_parse_32_be(const void *buf)
 {
-       __be32 *b = buf;
+       const __be32 *b = buf;
 
-       b[0] = be32_to_cpu(b[0]);
-
-       return b[0];
+       return be32_to_cpu(b[0]);
 }
 
-static unsigned int regmap_parse_32_native(void *buf)
+static unsigned int regmap_parse_32_native(const void *buf)
 {
        return *(u32 *)buf;
 }



  reply	other threads:[~2013-04-08 10:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 23:02 Stephen Warren
2013-03-21 19:09 ` Mark Brown
2013-04-08 10:24   ` Paul Bolle [this message]
2013-04-08 12:01     ` Mark Brown
2013-04-08 16:42       ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365416662.1830.86.camel@x61.thuisdomein \
    --to=pebolle@tiscali.nl \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=ldewangan@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=swarren@nvidia.com \
    --cc=swarren@wwwdotorg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®