perf/x86/uncore: clean up const mismatch
Subsystems (2)
PATCH 1/1 perf/x86/uncore: clean up const mismatch
In some cmp functions, a const pointer is cast out to a non-const pointer by using container_of() which is not correct. Fix this up by properly marking the pointers as const, which preserves the correct type of the pointer passed into the functions.
--- arch/x86/events/intel/uncore_discovery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/uncore_discovery.c +3 -3
@@ -52,7 +52,7 @@ static int get_device_die_id(struct pci_dev *dev)static inline int __type_cmp (const void *key,const struct rb_node *b) { -struct intel_uncore_discovery_type *type_b =__node_2_type (b); +const struct intel_uncore_discovery_type *type_b =__node_2_type (b);const u16 *type_id = key;if (type_b->type > *type_id)
@@ -115,7 +115,7 @@ get_uncore_discovery_type(struct uncore_unit_discovery *unit)static inline int pmu_idx_cmp (const void *key,const struct rb_node *b) { -struct intel_uncore_discovery_unit *unit; +const struct intel_uncore_discovery_unit *unit;const unsigned int *id = key; unit = rb_entry(b, struct intel_uncore_discovery_unit, node);
@@ -173,7 +173,7 @@ int intel_uncore_find_discovery_unit_id(struct rb_root *units, int die,static inline bool unit_less (struct rb_node *a,const struct rb_node *b) { -struct intel_uncore_discovery_unit *a_node, *b_node; +const struct intel_uncore_discovery_unit *a_node, *b_node; a_node = rb_entry(a, struct intel_uncore_discovery_unit, node); b_node = rb_entry(b, struct intel_uncore_discovery_unit, node);
Signature · 1 line
2.52.0
Peter Zijlstra
maintainerQuoted 4 lines · Greg Kroah-Hartman
In some cmp functions, a const pointer is cast out to a non-const pointer by using
container_of()which is not correct. Fix this up by properly marking the pointers as const, which preserves the correct type of the pointer passed into the functions.
How did you find this? My builds do not complain and all that.
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Greg Kroah-Hartman
In some cmp functions, a const pointer is cast out to a non-const pointer by using
container_of()which is not correct. Fix this up by properly marking the pointers as const, which preserves the correct type of the pointer passed into the functions.How did you find this? My builds do not complain and all that.
I have a local change that turns container_of() into container_of_const():
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=container_of_const_mess&id=ea8cab3db2b5a56c5ef63d0e32accce58eb9bb2c
that I'm using to sweep the tree and fix up all of the places we have gotten this wrong. And wow, have we gotten it wrong in so many places...
It's a slow grind, I'll get there eventually and then will merge a patch that forces container_of() to catch this type of thing so it will not come back in the future. Maybe a year or so, no real rush :)
thanks,
greg k-h
Peter Zijlstra
maintainerQuoted 10 lines · Greg Kroah-Hartman
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Greg Kroah-Hartman
In some cmp functions, a const pointer is cast out to a non-const pointer by using
container_of()which is not correct. Fix this up by properly marking the pointers as const, which preserves the correct type of the pointer passed into the functions.How did you find this? My builds do not complain and all that.
I have a local change that turns
container_of()intocontainer_of_const():
Quoted 8 lines
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=container_of_const_mess&id=ea8cab3db2b5a56c5ef63d0e32accce58eb9bb2cthat I'm using to sweep the tree and fix up all of the places we have gotten this wrong. And wow, have we gotten it wrong in so many places...
It's a slow grind, I'll get there eventually and then will merge a patch that forces
container_of()to catch this type of thing so it will not come back in the future. Maybe a year or so, no real rush :)
OK, meanwhile I'll see this patch is merged :-)
Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Greg Kroah-Hartman
Quoted 7 lines · Peter Zijlstra
Quoted 4 lines · Greg Kroah-Hartman
In some cmp functions, a const pointer is cast out to a non-const pointer by using
container_of()which is not correct. Fix this up by properly marking the pointers as const, which preserves the correct type of the pointer passed into the functions.How did you find this? My builds do not complain and all that.
I have a local change that turns
container_of()intocontainer_of_const():https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/commit/?h=container_of_const_mess&id=ea8cab3db2b5a56c5ef63d0e32accce58eb9bb2cthat I'm using to sweep the tree and fix up all of the places we have gotten this wrong. And wow, have we gotten it wrong in so many places...
Quoted 5 lines
Quoted 3 lines
It's a slow grind, I'll get there eventually and then will merge a patch that forces
container_of()to catch this type of thing so it will not come back in the future. Maybe a year or so, no real rush :)OK, meanwhile I'll see this patch is merged :-)
Thanks!
The following commit has been merged into the perf/core branch of tip:
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 632d89b030f1dac8d91875cd56a08adededba349 Gitweb: https://git.kernel.org/tip/632d89b030f1dac8d91875cd56a08adededba349 Author: Greg Kroah-Hartman <[email protected]> AuthorDate: Wed, 17 Dec 2025 13:42:41 +01:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 06 Jan 2026 16:34:23 +01:00
perf/x86/uncore: clean up const mismatch
In some cmp functions, a const pointer is cast out to a non-const pointer by using container_of() which is not correct. Fix this up by properly marking the pointers as const, which preserves the correct type of the pointer passed into the functions.
--- arch/x86/events/intel/uncore_discovery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/uncore_discovery.c +3 -3
@@ -52,7 +52,7 @@ static int get_device_die_id(struct pci_dev *dev)static inline int __type_cmp (const void *key,const struct rb_node *b) { -struct intel_uncore_discovery_type *type_b =__node_2_type (b); +const struct intel_uncore_discovery_type *type_b =__node_2_type (b);const u16 *type_id = key;if (type_b->type > *type_id)
@@ -115,7 +115,7 @@ get_uncore_discovery_type(struct uncore_unit_discovery *unit)static inline int pmu_idx_cmp (const void *key,const struct rb_node *b) { -struct intel_uncore_discovery_unit *unit; +const struct intel_uncore_discovery_unit *unit;const unsigned int *id = key; unit = rb_entry(b, struct intel_uncore_discovery_unit, node);
@@ -173,7 +173,7 @@ int intel_uncore_find_discovery_unit_id(struct rb_root *units, int die,static inline bool unit_less (struct rb_node *a,const struct rb_node *b) { -struct intel_uncore_discovery_unit *a_node, *b_node; +const struct intel_uncore_discovery_unit *a_node, *b_node; a_node = rb_entry(a, struct intel_uncore_discovery_unit, node); b_node = rb_entry(b, struct intel_uncore_discovery_unit, node);