]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: hsr: constify hsr_ops and prp_ops protocol operation structures
authorLuka Gejak <luka.gejak@linux.dev>
Thu, 26 Mar 2026 17:45:59 +0000 (18:45 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sun, 29 Mar 2026 21:37:50 +0000 (14:37 -0700)
The hsr_ops and prp_ops structures are assigned to hsr->proto_ops during
device initialization and are never modified at runtime. Declaring them
as const allows the compiler to place these structures in read-only
memory, which improves security by preventing accidental or malicious
modification of the function pointers they contain.

The proto_ops field in struct hsr_priv is also updated to a const
pointer to maintain type consistency.

Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Reviewed-by: Felix Maurer <fmaurer@redhat.com>
Link: https://patch.msgid.link/20260326174600.136232-2-luka.gejak@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/hsr/hsr_device.c
net/hsr/hsr_main.h

index 5c3eca2235ce7d74ae8f624534d750de88d55541..90236028817dbabd4017225489938f3da37ff759 100644 (file)
@@ -616,7 +616,7 @@ static const struct device_type hsr_type = {
        .name = "hsr",
 };
 
-static struct hsr_proto_ops hsr_ops = {
+static const struct hsr_proto_ops hsr_ops = {
        .send_sv_frame = send_hsr_supervision_frame,
        .create_tagged_frame = hsr_create_tagged_frame,
        .get_untagged_frame = hsr_get_untagged_frame,
@@ -626,7 +626,7 @@ static struct hsr_proto_ops hsr_ops = {
        .register_frame_out = hsr_register_frame_out,
 };
 
-static struct hsr_proto_ops prp_ops = {
+static const struct hsr_proto_ops prp_ops = {
        .send_sv_frame = send_prp_supervision_frame,
        .create_tagged_frame = prp_create_tagged_frame,
        .get_untagged_frame = prp_get_untagged_frame,
index 33b0d2460c9bcd5886bf7b20dfc6b8c8ca7e1741..134e4f3fff603625bd0de3862a7a3c8891ee7ada 100644 (file)
@@ -202,7 +202,7 @@ struct hsr_priv {
        enum hsr_version prot_version;  /* Indicate if HSRv0, HSRv1 or PRPv1 */
        spinlock_t seqnr_lock;  /* locking for sequence_nr */
        spinlock_t list_lock;   /* locking for node list */
-       struct hsr_proto_ops    *proto_ops;
+       const struct hsr_proto_ops      *proto_ops;
 #define PRP_LAN_ID     0x5     /* 0x1010 for A and 0x1011 for B. Bit 0 is set
                                 * based on SLAVE_A or SLAVE_B
                                 */