Bart,

On 2/16/17 00:10, Bart Van Assche wrote:
> On Wed, 2017-02-15 at 11:12 +0900, Damien Le Moal wrote:
>> +                    resid = round_up(resid, sector_size);
>> +                    if (resid < good_bytes)
>> +                            good_bytes -= resid;
>> +                    else
>> +                            good_bytes = 0;
>> +                    scsi_set_resid(SCpnt, resid);
> 
> Hello Damien,
> 
> If the Data-Out buffer is smaller than a single logical block, can the above
> code cause resid to exceed the Data-Out buffer size? I think we should avoid
> to convert a residual overflow into a residual underflow. Additionally, will
> round_up() work correctly if resid is negative (residual underflow)? How
> about using the following (untested) code instead of the above?
> 
> if (resid > 0) {
>         resid = min(good_bytes, round_up(resid, sector_size));
>         good_bytes -= resid;
>         scsi_set_resid(SCpnt, resid);
> }

Indeed, that would be more solid and cover all possible weird values of
resid. I will resend a v5.

Thanks.

-- 
Damien Le Moal, Ph.D.
Sr. Manager, System Software Research Group,
Western Digital Corporation
damien.lem...@wdc.com
(+81) 0466-98-3593 (ext. 513593)
1 kirihara-cho, Fujisawa,
Kanagawa, 252-0888 Japan
www.wdc.com, www.hgst.com

Reply via email to