From: Rosen Penev <rosenp@gmail.com>
To: mfd@lists.linux.dev
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
Andreas Kemnade <andreas@kemnade.info>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>, Lee Jones <lee@kernel.org>,
linux-omap@vger.kernel.org (open list:OMAP2+ SUPPORT),
linux-kernel@vger.kernel.org (open list)
Subject: [PATCHv2] mfd: twl-core: allocate modules with twl_private
Date: Thu, 24 Sep 2026 11:56:39 -0700 [thread overview]
Message-ID: <20260924185639.30913-1-rosenp@gmail.com> (raw)
Use a flexible array member to allocate the twl_client array together
with struct twl_private. This removes a separate devm_kcalloc() and
keeps the module data tied to the main private structure.
Can't use twl_get_num_slaves() for this as that bases its value on
twl_priv->twl_id , which is unallocated at this point.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: don't use twl_get_num_slaves().
drivers/mfd/twl-core.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index f86df356d658..0b78fe30e047 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -159,7 +159,7 @@ struct twl_private {
unsigned int twl_id;
struct twl_mapping *twl_map;
- struct twl_client *twl_modules;
+ struct twl_client twl_modules[];
};
static struct twl_private *twl_priv;
@@ -770,7 +770,9 @@ twl_probe(struct i2c_client *client)
goto out;
}
- twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private),
+ num_slaves = (id->driver_data & TWL6030_CLASS) ? 3 : 4;
+ twl_priv = devm_kzalloc(&client->dev,
+ struct_size(twl_priv, twl_modules, num_slaves),
GFP_KERNEL);
if (!twl_priv) {
status = -ENOMEM;
@@ -787,16 +789,6 @@ twl_probe(struct i2c_client *client)
twl_regmap_config = twl4030_regmap_config;
}
- num_slaves = twl_get_num_slaves();
- twl_priv->twl_modules = devm_kcalloc(&client->dev,
- num_slaves,
- sizeof(struct twl_client),
- GFP_KERNEL);
- if (!twl_priv->twl_modules) {
- status = -ENOMEM;
- goto out;
- }
-
for (i = 0; i < num_slaves; i++) {
struct twl_client *twl = &twl_priv->twl_modules[i];
--
2.55.0
reply other threads:[~2026-09-24 18:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260924185639.30913-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=aaro.koskinen@iki.fi \
--cc=andreas@kemnade.info \
--cc=khilman@baylibre.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=rogerq@kernel.org \
--cc=tony@atomide.com \
/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®