From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mark Brown <broonie@kernel.org>,
linux-kernel@vger.kernel.org, driver-core@lists.linux.dev
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 3/4] regmap: Defer assignments to the later in some cases
Date: Tue, 10 Nov 2026 10:37:01 +0100 [thread overview]
Message-ID: <20261110093820.454682-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20261110093820.454682-1-andriy.shevchenko@linux.intel.com>
In some cases the assignments at the top of the certain functions
belong to smaller subset of the functionality and may be located
too far from their actual users. Defer them to the later.
This makes code robust against potential changes that may lead to
the corruption of the respected values.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/regmap/regmap.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 0617a957559b..1855b5fc76da 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -681,12 +681,14 @@ struct regmap *__regmap_init(struct device *dev,
const char *lock_name)
{
struct regmap *map;
- int ret = -EINVAL;
enum regmap_endian reg_endian, val_endian;
int i, j;
+ int ret;
- if (!config)
+ if (!config) {
+ ret = -EINVAL;
goto err;
+ }
map = kzalloc_obj(*map);
if (map == NULL) {
@@ -1604,8 +1606,7 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
{
struct regmap_range_node *range;
unsigned long flags;
- void *work_val = map->work_buf + map->format.reg_bytes +
- map->format.pad_bytes;
+ void *work_val;
void *buf;
int ret = -ENOTSUPP;
size_t len;
@@ -1688,6 +1689,7 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg,
* buffer to write. Since register syncs often generate raw
* writes of single registers optimise that case.
*/
+ work_val = map->work_buf + map->format.reg_bytes + map->format.pad_bytes;
if (val != work_val && val_len == map->format.val_bytes) {
memcpy(work_val, val, map->format.val_bytes);
val = work_val;
@@ -2291,8 +2293,8 @@ EXPORT_SYMBOL_GPL(regmap_fields_update_bits_base);
int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
size_t val_count)
{
- int ret = 0, i;
size_t val_bytes = map->format.val_bytes;
+ int ret, i;
if (!IS_ALIGNED(reg, map->reg_stride))
return -EINVAL;
@@ -2302,6 +2304,8 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
* single write operations.
*/
if (!map->write || !map->format.parse_inplace) {
+ ret = 0; /* Later error paths rely on this */
+
guard(regmap)(map);
for (i = 0; i < val_count; i++) {
@@ -2739,12 +2743,12 @@ static int _regmap_bus_read(void *context, unsigned int reg,
{
int ret;
struct regmap *map = context;
- void *work_val = map->work_buf + map->format.reg_bytes +
- map->format.pad_bytes;
+ void *work_val;
if (!map->format.parse_val)
return -EINVAL;
+ work_val = map->work_buf + map->format.reg_bytes + map->format.pad_bytes;
ret = _regmap_raw_read(map, reg, work_val, map->format.val_bytes, false);
if (ret == 0)
*val = map->format.parse_val(work_val);
--
2.50.1
next prev parent reply other threads:[~2026-11-10 9:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 9:36 [PATCH v1 0/4] regmap: a small set of cleanups Andy Shevchenko
2026-11-10 9:36 ` [PATCH v1 1/4] regmap: Switch to use kmemdup_array() Andy Shevchenko
2026-11-10 9:37 ` [PATCH v1 2/4] regmap: Drop never used devm_regmap_*_free() APIs Andy Shevchenko
2026-11-10 10:19 ` Peng Fan
2026-11-10 9:37 ` Andy Shevchenko [this message]
2026-11-10 10:20 ` [PATCH v1 3/4] regmap: Defer assignments to the later in some cases Peng Fan
2026-11-10 9:37 ` [PATCH v1 4/4] regmap: Drop duplicate ret assignment Andy Shevchenko
2026-11-10 10:22 ` Peng Fan
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=20261110093820.454682-4-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.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®