diff options
author | Charles Keepax <ckeepax@opensource.cirrus.com> | 2018-02-22 07:59:10 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-02-26 06:00:30 -0500 |
commit | 0812d8ffa9955251ba0077488d4408d8987ec091 (patch) | |
tree | 8c2fc9f9cae2b6690684b85002eeb1c77c5f996f | |
parent | 2936e846c4e6df2df0dd6bcade3d269e17a707d1 (diff) |
regmap: Format data for raw write in regmap_bulk_write
In the case were the bulk transaction is split up into smaller chunks
data is passed directly to regmap_raw_write. However regmap_bulk_write
uses data in host endian and regmap_raw_write expects data in device
endian. As such if the host and device differ in endian the wrong data
will be written to the device. Correct this issue using a similar
approach to the single raw write case below it, duplicate the data
into a new buffer and use parse_inplace to format the data correctly.
Fixes: adaac459759d ("regmap: Introduce max_raw_read/write for regmap_bulk_read/write")
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/base/regmap/regmap.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index f5d653663626..8fe6e08fa41e 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c | |||
@@ -2003,6 +2003,17 @@ out: | |||
2003 | int chunk_stride = map->reg_stride; | 2003 | int chunk_stride = map->reg_stride; |
2004 | size_t chunk_size = val_bytes; | 2004 | size_t chunk_size = val_bytes; |
2005 | size_t chunk_count = val_count; | 2005 | size_t chunk_count = val_count; |
2006 | void *wval; | ||
2007 | |||
2008 | if (!val_count) | ||
2009 | return -EINVAL; | ||
2010 | |||
2011 | wval = kmemdup(val, val_count * val_bytes, map->alloc_flags); | ||
2012 | if (!wval) | ||
2013 | return -ENOMEM; | ||
2014 | |||
2015 | for (i = 0; i < val_count * val_bytes; i += val_bytes) | ||
2016 | map->format.parse_inplace(wval + i); | ||
2006 | 2017 | ||
2007 | if (!map->use_single_write) { | 2018 | if (!map->use_single_write) { |
2008 | chunk_size = map->max_raw_write; | 2019 | chunk_size = map->max_raw_write; |
@@ -2017,7 +2028,7 @@ out: | |||
2017 | for (i = 0; i < chunk_count; i++) { | 2028 | for (i = 0; i < chunk_count; i++) { |
2018 | ret = _regmap_raw_write(map, | 2029 | ret = _regmap_raw_write(map, |
2019 | reg + (i * chunk_stride), | 2030 | reg + (i * chunk_stride), |
2020 | val + (i * chunk_size), | 2031 | wval + (i * chunk_size), |
2021 | chunk_size); | 2032 | chunk_size); |
2022 | if (ret) | 2033 | if (ret) |
2023 | break; | 2034 | break; |
@@ -2026,10 +2037,12 @@ out: | |||
2026 | /* Write remaining bytes */ | 2037 | /* Write remaining bytes */ |
2027 | if (!ret && chunk_size * i < total_size) { | 2038 | if (!ret && chunk_size * i < total_size) { |
2028 | ret = _regmap_raw_write(map, reg + (i * chunk_stride), | 2039 | ret = _regmap_raw_write(map, reg + (i * chunk_stride), |
2029 | val + (i * chunk_size), | 2040 | wval + (i * chunk_size), |
2030 | total_size - i * chunk_size); | 2041 | total_size - i * chunk_size); |
2031 | } | 2042 | } |
2032 | map->unlock(map->lock_arg); | 2043 | map->unlock(map->lock_arg); |
2044 | |||
2045 | kfree(wval); | ||
2033 | } else { | 2046 | } else { |
2034 | void *wval; | 2047 | void *wval; |
2035 | 2048 | ||