[PATCH v2 3/4] block: add IOC_PR_READ_KEYS ioctl
Christoph Hellwig
hch at lst.de
Sun Nov 30 22:40:16 PST 2025
On Thu, Nov 27, 2025 at 10:54:23AM -0500, Stefan Hajnoczi wrote:
> +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;
Please avoid the use of the __free mess and write readable and maintainable
code instead.
> + struct pr_read_keys inout;
Inout is not a very good variable name, as it doesn't really have much
of meaning.
> + if (copy_from_user(&inout, arg, sizeof(inout)))
> + return -EFAULT;
> +
> + /*
> + * 64-bit hosts could handle more keys than 32-bit hosts, but this
> + * limit is more than enough in practice.
> + */
> + if (inout.num_keys > (U32_MAX - sizeof(*keys_info)) /
> + sizeof(keys_info->keys[0]))
> + return -EINVAL;
> +
> + keys_info_len = struct_size(keys_info, keys, inout.num_keys);
Do the size check on the calculate len here?
> + return ret;
> +
> + /* Copy out individual keys */
> + keys_ptr = u64_to_user_ptr(inout.keys_ptr);
> + num_copy_keys = min(inout.num_keys, keys_info->num_keys);
> + keys_copy_len = num_copy_keys * sizeof(keys_info->keys[0]);
num_copy_keys is only used once, so maybe drop it?
More information about the Linux-nvme
mailing list