Re: [PATCH] lockdep: constify usage of struct lock_class_key where possible

From: Peter Zijlstra

Date: Mon May 04 2026 - 03:28:53 EST


On Tue, Apr 28, 2026 at 11:05:25PM +0200, Heiner Kallweit wrote:
> Constify usage of struct lock_class_key where possible. This requires
> to constify also usage of struct lockdep_subclass_key in two places.
>
> Especially relevant is constification of lockdep_map.key, as it makes
> clear that the key isn't changed during lifetime of struct lockdep_map.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@xxxxxxxxx>
> ---
> include/linux/lockdep.h | 18 ++++++++++--------
> include/linux/lockdep_types.h | 2 +-
> kernel/locking/lockdep.c | 12 ++++++------
> 3 files changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index 621566345..3fa2b62f2 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -125,25 +125,27 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
> * to lockdep:
> */
>
> -extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
> +void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
> + const struct lock_class_key *key, int subclass,
> + u8 inner, u8 outer, u8 lock_type);

> @@ -252,9 +254,9 @@ static inline int lock_is_held(const struct lockdep_map *lock)
> #define lockdep_is_held(lock) lock_is_held(&(lock)->dep_map)
> #define lockdep_is_held_type(lock, r) lock_is_held_type(&(lock)->dep_map, (r))
>
> -extern void lock_set_class(struct lockdep_map *lock, const char *name,
> - struct lock_class_key *key, unsigned int subclass,
> - unsigned long ip);
> +void lock_set_class(struct lockdep_map *lock, const char *name,
> + const struct lock_class_key *key, unsigned int subclass,
> + unsigned long ip);
>

It is also silently removing extern, why?