Re: [PATCH 3/4] block: add IOC_PR_READ_KEYS ioctl

Krzysztof Kozlowski
2025-11-29T14:31:57Z

On 26/11/2025 17:35, Stefan Hajnoczi wrote:
> +
> #define PR_FL_IGNORE_KEY (1 << 0) /* ignore existing key */
>
> #define IOC_PR_REGISTER _IOW('p', 200, struct pr_registration)
> @@ -64,5 +70,6 @@ struct pr_clear {
> #define IOC_PR_PREEMPT _IOW('p', 203, struct pr_preempt)
> #define IOC_PR_PREEMPT_ABORT _IOW('p', 204, struct pr_preempt)
> #define IOC_PR_CLEAR _IOW('p', 205, struct pr_clear)
> +#define IOC_PR_READ_KEYS _IOWR('p', 206, struct pr_read_keys)
>
> #endif /* _UAPI_PR_H */
> diff --git a/block/ioctl.c b/block/ioctl.c
> index d7489a56b33c3..e87c424c15ae9 100644
> --- a/block/ioctl.c
> +++ b/block/ioctl.c
> @@ -1,5 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
> #include <linux/capability.h>
> +#include <linux/cleanup.h>
> #include <linux/compat.h>
> #include <linux/blkdev.h>
> #include <linux/export.h>
> @@ -423,6 +424,54 @@ static int blkdev_pr_clear(struct block_device *bdev, blk_mode_t mode,
> return ops->pr_clear(bdev, c.key);
> }
>
> +static int blkdev_pr_read_keys(struct block_device *bdev, blk_mode_t mode,
> + struct pr_read_keys __user *arg)
> +{
> + const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
> + struct pr_keys *keys_info __free(kfree) = NULL;

This is an undesired syntax explicitly documented as one to avoid. You
need here proper assignment, not NULL. Please don't use cleanup.h if you
do not intend to follow it because it does not make the code simpler.

Best regards,
Krzysztof