From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 3/3] ratp: make ratp commands const
Date: Mon, 07 Apr 2025 09:29:55 +0200 [thread overview]
Message-ID: <20250407-ratp-fixes-v1-3-4c2501a83bca@pengutronix.de> (raw)
In-Reply-To: <20250407-ratp-fixes-v1-0-4c2501a83bca@pengutronix.de>
The ratp commands are placed in the readonly data section, but are
written to due to the list entry in the command.
Make the ratp commands actually const by moving the list entry to a
separate container struct.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/ratp/ratp.c | 34 ++++++++++++++++++++++------------
include/ratp_bb.h | 3 +--
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c
index 925e1d637f..a59dd56265 100644
--- a/common/ratp/ratp.c
+++ b/common/ratp/ratp.c
@@ -30,8 +30,6 @@
static LIST_HEAD(ratp_command_list);
-#define for_each_ratp_command(cmd) list_for_each_entry(cmd, &ratp_command_list, list)
-
struct ratp_bb_command_return {
uint32_t errno;
};
@@ -56,30 +54,42 @@ struct ratp_ctx {
bool wq_registered;
};
+struct ratp_command_entry {
+ struct list_head list;
+ const struct ratp_command *cmd;
+};
+
static int compare_ratp_command(struct list_head *a, struct list_head *b)
{
- int id_a = list_entry(a, struct ratp_command, list)->request_id;
- int id_b = list_entry(b, struct ratp_command, list)->request_id;
+ int id_a = list_entry(a, const struct ratp_command_entry, list)->cmd->request_id;
+ int id_b = list_entry(b, const struct ratp_command_entry, list)->cmd->request_id;
return (id_a - id_b);
}
-int register_ratp_command(struct ratp_command *cmd)
+int register_ratp_command(const struct ratp_command *cmd)
{
+ struct ratp_command_entry *entry;
+
debug("register ratp command: request %hu, response %hu\n",
cmd->request_id, cmd->response_id);
- list_add_sort(&cmd->list, &ratp_command_list, compare_ratp_command);
+
+ entry = xzalloc(sizeof(*entry));
+ entry->cmd = cmd;
+
+ list_add_sort(&entry->list, &ratp_command_list, compare_ratp_command);
+
return 0;
}
EXPORT_SYMBOL(register_ratp_command);
-static struct ratp_command *find_ratp_request(uint16_t request_id)
+static const struct ratp_command *find_ratp_request(uint16_t request_id)
{
- struct ratp_command *cmdtp;
+ struct ratp_command_entry *entry;
- for_each_ratp_command(cmdtp)
- if (request_id == cmdtp->request_id)
- return cmdtp;
+ list_for_each_entry(entry, &ratp_command_list, list)
+ if (request_id == entry->cmd->request_id)
+ return entry->cmd;
return NULL; /* not found */
}
@@ -210,7 +220,7 @@ static int ratp_bb_dispatch(struct ratp_ctx *ctx, const void *buf, int len)
int dlen = len - sizeof(struct ratp_bb);
int ret = 0;
uint16_t type = be16_to_cpu(rbb->type);
- struct ratp_command *cmd;
+ const struct ratp_command *cmd;
struct ratp_work *rw;
/* See if there's a command registered to this type */
diff --git a/include/ratp_bb.h b/include/ratp_bb.h
index c6c7c4bc23..746f6155dd 100644
--- a/include/ratp_bb.h
+++ b/include/ratp_bb.h
@@ -50,7 +50,6 @@ int barebox_ratp_fs_mount(const char *path);
*/
struct ratp_command {
- struct list_head list;
uint16_t request_id;
uint16_t response_id;
int (*cmd)(const struct ratp_bb *req,
@@ -67,6 +66,6 @@ const struct ratp_command __barebox_ratp_cmd_##_name \
#define BAREBOX_RATP_CMD_END \
};
-int register_ratp_command(struct ratp_command *cmd);
+int register_ratp_command(const struct ratp_command *cmd);
#endif /* __RATP_BB_H */
--
2.39.5
next prev parent reply other threads:[~2025-04-07 7:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 7:29 [PATCH 0/3] ratp: fixes Sascha Hauer
2025-04-07 7:29 ` [PATCH 1/3] ratp: Drop wrong alignment annotation Sascha Hauer
2025-04-07 7:59 ` Ahmad Fatoum
2025-04-07 13:10 ` Sascha Hauer
2025-04-07 7:29 ` [PATCH 2/3] ratp: do not export ratp command list Sascha Hauer
2025-04-07 7:29 ` Sascha Hauer [this message]
2025-04-07 13:09 ` [PATCH 0/3] ratp: fixes Sascha Hauer
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=20250407-ratp-fixes-v1-3-4c2501a83bca@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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