[PATCH] rapidio: Constify struct rio_switch_ops
From: Christophe JAILLET
Date: Sat Nov 14 2026 - 06:13:44 EST
'struct rio_switch_ops' is not modified in these drivers.
Constifying these structures moves some data to a read-only section, so
increases overall security, especially when the structure holds some
function pointers.
On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
6365 1512 0 7877 1ec5 drivers/rapidio/switches/idtcps.o
After:
=====
text data bss dec hex filename
6461 1416 0 7877 1ec5 drivers/rapidio/switches/idtcps.o
Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
---
Compile tested only.
---
drivers/rapidio/rio.c | 6 +++---
drivers/rapidio/switches/idt_gen2.c | 2 +-
drivers/rapidio/switches/idt_gen3.c | 2 +-
drivers/rapidio/switches/idtcps.c | 2 +-
include/linux/rio.h | 2 +-
5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index f45e58b0971f..7df739276a45 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -1615,7 +1615,7 @@ int rio_route_add_entry(struct rio_dev *rdev,
u16 table, u16 route_destid, u8 route_port, int lock)
{
int rc = -EINVAL;
- struct rio_switch_ops *ops = rdev->rswitch->ops;
+ const struct rio_switch_ops *ops = rdev->rswitch->ops;
if (lock) {
rc = rio_lock_device(rdev->net->hport, rdev->destid,
@@ -1668,7 +1668,7 @@ int rio_route_get_entry(struct rio_dev *rdev, u16 table,
u16 route_destid, u8 *route_port, int lock)
{
int rc = -EINVAL;
- struct rio_switch_ops *ops = rdev->rswitch->ops;
+ const struct rio_switch_ops *ops = rdev->rswitch->ops;
if (lock) {
rc = rio_lock_device(rdev->net->hport, rdev->destid,
@@ -1716,7 +1716,7 @@ EXPORT_SYMBOL_GPL(rio_route_get_entry);
int rio_route_clr_table(struct rio_dev *rdev, u16 table, int lock)
{
int rc = -EINVAL;
- struct rio_switch_ops *ops = rdev->rswitch->ops;
+ const struct rio_switch_ops *ops = rdev->rswitch->ops;
if (lock) {
rc = rio_lock_device(rdev->net->hport, rdev->destid,
diff --git a/drivers/rapidio/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
index 8a89bba17d39..b1b58a4a94bf 100644
--- a/drivers/rapidio/switches/idt_gen2.c
+++ b/drivers/rapidio/switches/idt_gen2.c
@@ -402,7 +402,7 @@ static int idtg2_sysfs(struct rio_dev *rdev, bool create)
return err;
}
-static struct rio_switch_ops idtg2_switch_ops = {
+static const struct rio_switch_ops idtg2_switch_ops = {
.owner = THIS_MODULE,
.add_entry = idtg2_route_add_entry,
.get_entry = idtg2_route_get_entry,
diff --git a/drivers/rapidio/switches/idt_gen3.c b/drivers/rapidio/switches/idt_gen3.c
index d7537e62119e..25d9c710cb49 100644
--- a/drivers/rapidio/switches/idt_gen3.c
+++ b/drivers/rapidio/switches/idt_gen3.c
@@ -258,7 +258,7 @@ idtg3_em_handler(struct rio_dev *rdev, u8 pnum)
return 0;
}
-static struct rio_switch_ops idtg3_switch_ops = {
+static const struct rio_switch_ops idtg3_switch_ops = {
.owner = THIS_MODULE,
.add_entry = idtg3_route_add_entry,
.get_entry = idtg3_route_get_entry,
diff --git a/drivers/rapidio/switches/idtcps.c b/drivers/rapidio/switches/idtcps.c
index c825728eb0ee..ee34b7cd41dc 100644
--- a/drivers/rapidio/switches/idtcps.c
+++ b/drivers/rapidio/switches/idtcps.c
@@ -115,7 +115,7 @@ idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
return 0;
}
-static struct rio_switch_ops idtcps_switch_ops = {
+static const struct rio_switch_ops idtcps_switch_ops = {
.owner = THIS_MODULE,
.add_entry = idtcps_route_add_entry,
.get_entry = idtcps_route_get_entry,
diff --git a/include/linux/rio.h b/include/linux/rio.h
index f42379775ce8..b7c10f3ef275 100644
--- a/include/linux/rio.h
+++ b/include/linux/rio.h
@@ -98,7 +98,7 @@ struct rio_switch {
struct list_head node;
u8 *route_table;
u32 port_ok;
- struct rio_switch_ops *ops;
+ const struct rio_switch_ops *ops;
spinlock_t lock;
struct rio_dev *nextdev[];
};
--
2.56.0