Skip to contentSkip to conversation

clk: keystone: Fix discarded const qualifiers

PATCH Applied Adrian Barnaś 3 participants 3 messages Oct 28, 2025 – Nov 14, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: keystone: Fix discarded const qualifiers

Add const qualifiers to the pointers returned from 'container_of' macro to prevent breaking the const promise on const struct pointers from parameters.

Once you have a mutable container structure pointer, you can change structure fields through it, which violates the const guarantee.

---
 drivers/clk/keystone/sci-clk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/keystone/sci-clk.c +2 -2
index a4b42811de55..9d5071223f4c 100644
@@ -496,8 +496,8 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
 static int _cmp_sci_clk_list(void *priv, const struct list_head *a,
 			     const struct list_head *b)
 {
-	struct sci_clk *ca = container_of(a, struct sci_clk, node);
-	struct sci_clk *cb = container_of(b, struct sci_clk, node);
+	const struct sci_clk *ca = container_of(a, struct sci_clk, node);
+	const struct sci_clk *cb = container_of(b, struct sci_clk, node);
 
 	return _cmp_sci_clk(ca, &cb);
 }
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Adrian Barnaś

Add const qualifiers to the pointers returned from 'container_of' macro to prevent breaking the const promise on const struct pointers from parameters.

Once you have a mutable container structure pointer, you can change structure fields through it, which violates the const guarantee.

---
 drivers/clk/keystone/sci-clk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/keystone/sci-clk.c +2 -2
index a4b42811de55..9d5071223f4c 100644
@@ -496,8 +496,8 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
 static int _cmp_sci_clk_list(void *priv, const struct list_head *a,
 			     const struct list_head *b)
 {
-	struct sci_clk *ca = container_of(a, struct sci_clk, node);
-	struct sci_clk *cb = container_of(b, struct sci_clk, node);
+	const struct sci_clk *ca = container_of(a, struct sci_clk, node);
+	const struct sci_clk *cb = container_of(b, struct sci_clk, node);
 
 	return _cmp_sci_clk(ca, &cb);
 }
Signature · 1 line
2.51.1.851.g4ebd6896fd-goog
Signature · 4 lines
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource
maintainer Applied
#2 lore raw
In reply to Adrian Barnaś

Quoting Adrian Barnaś (2025-10-28 09:16:42)

Quoted 9 lines

Add const qualifiers to the pointers returned from 'container_of' macro to prevent breaking the const promise on const struct pointers from parameters.

Once you have a mutable container structure pointer, you can change structure fields through it, which violates the const guarantee.

---

Applied to clk-next