[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251201064016.GC19461@lst.de>
Date: Mon, 1 Dec 2025 07:40:16 +0100
From: Christoph Hellwig <hch@....de>
To: Stefan Hajnoczi <stefanha@...hat.com>
Cc: linux-block@...r.kernel.org, Keith Busch <kbusch@...nel.org>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
linux-kernel@...r.kernel.org,
"James E.J. Bottomley" <James.Bottomley@...senPartnership.com>,
Christoph Hellwig <hch@....de>,
Mike Christie <michael.christie@...cle.com>,
linux-nvme@...ts.infradead.org, Jens Axboe <axboe@...nel.dk>,
linux-scsi@...r.kernel.org, Sagi Grimberg <sagi@...mberg.me>
Subject: Re: [PATCH v2 3/4] block: add IOC_PR_READ_KEYS ioctl
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?
Powered by blists - more mailing lists