Re: [PATCH v2 06/21] block, blksnap: module management interface functions

From: Pankaj Raghav
Date: Tue Jan 03 2023 - 10:34:22 EST


On Fri, Dec 09, 2022 at 03:23:16PM +0100, Sergei Shtepa wrote:
> +static int ioctl_tracker_mark_dirty_blocks(unsigned long arg)
> +{
> + int ret = 0;
> + struct blk_snap_tracker_mark_dirty_blocks karg;
> + struct blk_snap_block_range *dirty_blocks_array;
> +
> + if (copy_from_user(&karg, (void *)arg, sizeof(karg))) {
> + pr_err("Unable to mark dirty blocks: invalid user buffer\n");
> + return -ENODATA;
> + }
> +
> + dirty_blocks_array = kcalloc(
> + karg.count, sizeof(struct blk_snap_block_range), GFP_KERNEL);
> + if (!dirty_blocks_array)
> + return -ENOMEM;
> +
> + if (copy_from_user(dirty_blocks_array, (void *)karg.dirty_blocks_array,
> + karg.count * sizeof(struct blk_snap_block_range))) {
> + pr_err("Unable to mark dirty blocks: invalid user buffer\n");
> + ret = -ENODATA;

Minor nit:
The following could be done to keep it consistent with other functions:

if (copy_from_user(dirty_blocks_array, (void *)karg.dirty_blocks_array,
karg.count * sizeof(struct blk_snap_block_range))) {
pr_err("Unable to mark dirty blocks: invalid user buffer\n");
ret = -ENODATA;
goto out;
}

if (karg.dev_id.mj == snapimage_major())
ret = snapshot_mark_dirty_blocks(
MKDEV(karg.dev_id.mj, karg.dev_id.mn),
dirty_blocks_array, karg.count);
else
ret = tracker_mark_dirty_blocks(
MKDEV(karg.dev_id.mj, karg.dev_id.mn),
dirty_blocks_array, karg.count);
out:
kfree(dirty_blocks_array);

return ret;
}


> + } else {
> + if (karg.dev_id.mj == snapimage_major())
> + ret = snapshot_mark_dirty_blocks(
> + MKDEV(karg.dev_id.mj, karg.dev_id.mn),
> + dirty_blocks_array, karg.count);
> + else
> + ret = tracker_mark_dirty_blocks(
> + MKDEV(karg.dev_id.mj, karg.dev_id.mn),
> + dirty_blocks_array, karg.count);
> + }
> +
> + kfree(dirty_blocks_array);
> +
> + return ret;
> +}
> +
--
Pankaj Raghav