From: Luka Gejak 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 --- net/hsr/hsr_device.c | 4 ++-- net/hsr/hsr_main.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c index 5c3eca2235ce..90236028817d 100644 --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -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, diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h index 33b0d2460c9b..134e4f3fff60 100644 --- a/net/hsr/hsr_main.h +++ b/net/hsr/hsr_main.h @@ -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 */ -- 2.53.0 From: Luka Gejak Replace two instances of the legacy '/* Fall through */' comment with the standardized 'fallthrough;' macro in hsr_get_node_status() and hsr_get_node_list(). The kernel has standardized on the fallthrough macro since the migration from comment-based annotations, which provides compiler-level verification of intentional case fall-throughs. Signed-off-by: Luka Gejak --- net/hsr/hsr_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c index db0b0af7a692..32c1b77cf84b 100644 --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -433,7 +433,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info) nla_put_failure: kfree_skb(skb_out); - /* Fall through */ + fallthrough; fail: rcu_read_unlock(); @@ -524,7 +524,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info) nla_put_failure: nlmsg_free(skb_out); - /* Fall through */ + fallthrough; fail: rcu_read_unlock(); -- 2.53.0 From: Luka Gejak Remove the trailing 'return;' from the end of the void function send_hsr_supervision_frame() per checkpatch recommendations. Signed-off-by: Luka Gejak --- net/hsr/hsr_device.c | 1 - 1 file changed, 1 deletion(-) diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c index 90236028817d..6ffecc3f0004 100644 --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -363,7 +363,6 @@ static void send_hsr_supervision_frame(struct hsr_port *port, hsr_forward_skb(skb, port); spin_unlock_bh(&hsr->seqnr_lock); - return; } static void send_prp_supervision_frame(struct hsr_port *master, -- 2.53.0 From: Luka Gejak Replace the hardcoded string "hsr_get_untagged_frame" with the standard __func__ macro in netdev_warn_once() call to make the code more robust to refactoring. Signed-off-by: Luka Gejak --- net/hsr/hsr_forward.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c index aefc9b6936ba..0aca859c88cb 100644 --- a/net/hsr/hsr_forward.c +++ b/net/hsr/hsr_forward.c @@ -184,7 +184,7 @@ struct sk_buff *hsr_get_untagged_frame(struct hsr_frame_info *frame, create_stripped_skb_hsr(frame->skb_hsr, frame); else netdev_warn_once(port->dev, - "Unexpected frame received in hsr_get_untagged_frame()\n"); + "Unexpected frame received in %s()\n", __func__); if (!frame->skb_std) return NULL; -- 2.53.0 From: Luka Gejak Remove the unnecessary curly braces around the single statement for loop body in hsr_add_node() as per kernel coding style. Signed-off-by: Luka Gejak --- net/hsr/hsr_framereg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/hsr/hsr_framereg.c b/net/hsr/hsr_framereg.c index 577fb588bc2f..9c3b7381788e 100644 --- a/net/hsr/hsr_framereg.c +++ b/net/hsr/hsr_framereg.c @@ -182,9 +182,8 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr, * as initialization. (0 could trigger an spurious ring error warning). */ now = jiffies; - for (i = 0; i < HSR_PT_PORTS; i++) { + for (i = 0; i < HSR_PT_PORTS; i++) new_node->time_in[i] = now; - } if (san && hsr->proto_ops->handle_san_frame) hsr->proto_ops->handle_san_frame(san, rx_port, new_node); -- 2.53.0 From: Luka Gejak Add missing blank lines after the inline function declarations to comply with the kernel coding style guidelines. Signed-off-by: Luka Gejak --- net/hsr/hsr_main.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h index 134e4f3fff60..202dc90bd2ab 100644 --- a/net/hsr/hsr_main.h +++ b/net/hsr/hsr_main.h @@ -143,6 +143,7 @@ static inline void set_prp_lan_id(struct prp_rct *rct, u16 lan_id) rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) & 0x0FFF) | (lan_id << 12)); } + static inline void set_prp_LSDU_size(struct prp_rct *rct, u16 LSDU_size) { rct->lan_id_and_LSDU_size = htons((ntohs(rct->lan_id_and_LSDU_size) & @@ -277,24 +278,36 @@ static inline bool prp_check_lsdu_size(struct sk_buff *skb, } #if IS_ENABLED(CONFIG_DEBUG_FS) + void hsr_debugfs_rename(struct net_device *dev); void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev); void hsr_debugfs_term(struct hsr_priv *priv); void hsr_debugfs_create_root(void); void hsr_debugfs_remove_root(void); + #else + static inline void hsr_debugfs_rename(struct net_device *dev) { } + static inline void hsr_debugfs_init(struct hsr_priv *priv, struct net_device *hsr_dev) -{} +{ +} + static inline void hsr_debugfs_term(struct hsr_priv *priv) -{} +{ +} + static inline void hsr_debugfs_create_root(void) -{} +{ +} + static inline void hsr_debugfs_remove_root(void) -{} +{ +} + #endif #endif /* __HSR_PRIVATE_H */ -- 2.53.0 From: Luka Gejak Replace the explicit bit shift (1 << HSR_SEQ_BLOCK_SHIFT) with the standardized BIT() macro for defining HSR_SEQ_BLOCK_SIZE. This improves readability and aligns with kernel coding conventions. Signed-off-by: Luka Gejak --- net/hsr/hsr_framereg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h index c65ecb925734..cb731ee0ce5c 100644 --- a/net/hsr/hsr_framereg.h +++ b/net/hsr/hsr_framereg.h @@ -79,7 +79,7 @@ struct hsr_seq_block *hsr_get_seq_block(struct hsr_node *node, u16 block_idx); #endif #define HSR_SEQ_BLOCK_SHIFT 7 /* 128 bits */ -#define HSR_SEQ_BLOCK_SIZE (1 << HSR_SEQ_BLOCK_SHIFT) +#define HSR_SEQ_BLOCK_SIZE BIT(HSR_SEQ_BLOCK_SHIFT) #define HSR_SEQ_BLOCK_MASK (HSR_SEQ_BLOCK_SIZE - 1) #define HSR_MAX_SEQ_BLOCKS 64 -- 2.53.0