Re: [PATCH 3/4] blk-crypto: make blk_crypto_attr instances const

From: John Garry

Date: Tue Mar 17 2026 - 12:30:53 EST


On 16/03/2026 22:43, Thomas Weißschuh wrote:
The blk_crypto_attrs structures are never modified, mark them as const.

Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>

With reservations, below:
Reviewed-by: John Garry <john.g.garry@xxxxxxxxxx>>
static struct blk_crypto_profile *kobj_to_crypto_profile(struct kobject *kobj)
@@ -26,39 +26,39 @@ static struct blk_crypto_profile *kobj_to_crypto_profile(struct kobject *kobj)
return container_of(kobj, struct blk_crypto_kobj, kobj)->profile;
}
-static struct blk_crypto_attr *attr_to_crypto_attr(struct attribute *attr)
+static const struct blk_crypto_attr *attr_to_crypto_attr(const struct attribute *attr)

> 80 again, FWIW

And this code is becoming very "wordy" now. Maybe someone would think that the following is better:

#define attr_to_crypto_attr(attr) \
container_of_const(attr, struct blk_crypto_attr, attr)

{
- return container_of(attr, struct blk_crypto_attr, attr);
+ return container_of_const(attr, struct blk_crypto_attr, attr);
}