lkml.org 
[lkml]   [2023]   [May]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v11 2/9] block: Add copy offload support infrastructure
On 23/05/30 01:29PM, Maurizio Lombardi wrote:
>po 22. 5. 2023 v 13:17 odesílatel Nitesh Shetty <nj.shetty@samsung.com> napsal:
>>
>> +static int __blkdev_copy_offload(struct block_device *bdev_in, loff_t pos_in,
>> + struct block_device *bdev_out, loff_t pos_out, size_t len,
>> + cio_iodone_t endio, void *private, gfp_t gfp_mask)
>> +{
>> + struct cio *cio;
>> + struct copy_ctx *ctx;
>> + struct bio *read_bio, *write_bio;
>> + struct page *token;
>> + sector_t copy_len;
>> + sector_t rem, max_copy_len;
>> +
>> + cio = kzalloc(sizeof(struct cio), GFP_KERNEL);
>> + if (!cio)
>> + return -ENOMEM;
>> + atomic_set(&cio->refcount, 0);
>> + cio->waiter = current;
>> + cio->endio = endio;
>> + cio->private = private;
>> +
>> + max_copy_len = min(bdev_max_copy_sectors(bdev_in),
>> + bdev_max_copy_sectors(bdev_out)) << SECTOR_SHIFT;
>> +
>> + cio->pos_in = pos_in;
>> + cio->pos_out = pos_out;
>> + /* If there is a error, comp_len will be set to least successfully
>> + * completed copied length
>> + */
>> + cio->comp_len = len;
>> + for (rem = len; rem > 0; rem -= copy_len) {
>> + copy_len = min(rem, max_copy_len);
>> +
>> + token = alloc_page(gfp_mask);
>> + if (unlikely(!token))
>> + goto err_token;
>
>[...]
>
>> +err_token:
>> + cio->comp_len = min_t(sector_t, cio->comp_len, (len - rem));
>> + if (!atomic_read(&cio->refcount))
>> + return -ENOMEM;
>> + /* Wait for submitted IOs to complete */
>> + return blkdev_copy_wait_completion(cio);
>> +}
>
>Suppose the first call to "token = alloc_page()" fails (and
>cio->refcount == 0), isn't "cio" going to be leaked here?
>
>Maurizio
>

Agreed, will free it in "err_token", and will update next version.

Thank you,
Nitesh Shetty
\
 
 \ /
  Last update: 2023-05-30 18:25    [W:0.092 / U:0.592 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site