From: Rosen Penev <rosenp@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>,
Chanwoo Choi <cw00.choi@samsung.com>
Subject: [PATCH] extcon/rtk-type-c: Use flexible array member for config storage
Date: Mon, 12 Oct 2026 17:05:04 -0700 [thread overview]
Message-ID: <20261013000504.802833-1-rosenp@gmail.com> (raw)
Convert type_c_cfg from a pointer to a flexible array member embedded
in the type_c_data structure. This improves memory layout by combining
two separate allocations into one, reducing pointer indirection and
aligning with modern kernel FAM patterns.
Move device tree config retrieval earlier in probe to validate before
allocation. Allocate both type_c and type_c_cfg in a single devm_kzalloc
call using struct_size().
Assisted-by: LLM
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/extcon/extcon-rtk-type-c.c | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/drivers/extcon/extcon-rtk-type-c.c b/drivers/extcon/extcon-rtk-type-c.c
index da0b3fd3676e..ae1a4726fb63 100644
--- a/drivers/extcon/extcon-rtk-type-c.c
+++ b/drivers/extcon/extcon-rtk-type-c.c
@@ -63,7 +63,6 @@ struct type_c_data {
struct gpio_desc *rd_ctrl_gpio_desc;
/* Parameters */
- struct type_c_cfg *type_c_cfg;
u32 dfp_mode_rp_en;
u32 ufp_mode_rd_en;
u32 cc1_code;
@@ -99,6 +98,8 @@ struct type_c_data {
struct dentry *debug_dir;
struct typec_port *port;
+
+ struct type_c_cfg type_c_cfg[];
};
/* Type C register offset */
@@ -1321,10 +1322,18 @@ static int extcon_rtk_type_c_probe(struct platform_device *pdev)
const struct type_c_cfg *type_c_cfg;
int ret = 0;
- type_c = devm_kzalloc(dev, sizeof(*type_c), GFP_KERNEL);
+ type_c_cfg = of_device_get_match_data(dev);
+ if (!type_c_cfg) {
+ dev_err(dev, "type_c config are not assigned!\n");
+ return -EINVAL;
+ }
+
+ type_c = devm_kzalloc(dev, struct_size(type_c, type_c_cfg, 1), GFP_KERNEL);
if (!type_c)
return -ENOMEM;
+ memcpy(type_c->type_c_cfg, type_c_cfg, sizeof(*type_c_cfg));
+
type_c->reg_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(type_c->reg_base))
return PTR_ERR(type_c->reg_base);
@@ -1361,20 +1370,6 @@ static int extcon_rtk_type_c_probe(struct platform_device *pdev)
}
}
- type_c_cfg = of_device_get_match_data(dev);
- if (!type_c_cfg) {
- dev_err(dev, "type_c config are not assigned!\n");
- ret = -EINVAL;
- goto err;
- }
-
- type_c->type_c_cfg = devm_kzalloc(dev, sizeof(*type_c->type_c_cfg),
- GFP_KERNEL);
- if (!type_c->type_c_cfg)
- return -ENOMEM;
-
- memcpy(type_c->type_c_cfg, type_c_cfg, sizeof(*type_c_cfg));
-
if (setup_type_c_parameter(type_c)) {
dev_err(dev, "ERROR: %s to setup type c parameter!!", __func__);
ret = -EINVAL;
--
2.56.0
reply other threads:[~2026-10-13 0:05 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=20261013000504.802833-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=cw00.choi@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=myungjoo.ham@samsung.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®