Re: [PATCH] blk-throttle: fix divide-by-zero on legacy iops limit of 0

From: Tao Cui

Date: Thu Jul 16 2026 - 11:50:26 EST




于 2026年7月15日 GMT+08:00 23:01:09,David Laight <david.laight.linux@xxxxxxxxx> 写道:
>On Wed, 15 Jul 2026 20:44:19 +0800
>Tao Cui <cui.tao@xxxxxxxxx> wrote:
>
>> 在 2026/7/14 19:37, David Laight 写道:
>...
>> >> tg_update_slice(tg, rw);
>> >> @@ -1386,7 +1391,8 @@ static ssize_t tg_set_conf(struct kernfs_open_file *of,
>> >> if (is_u64)
>> >> *(u64 *)((void *)tg + of_cft(of)->private) = v;
>> >> else
>> >> - *(unsigned int *)((void *)tg + of_cft(of)->private) = v;
>> >> + *(unsigned int *)((void *)tg + of_cft(of)->private) =
>> >> + min_t(u64, v, UINT_MAX);
>> >
>> > The LHS casts look horrid - there has to be a nicer way to do that.
>> >
>> > And you don't need min_t() a plain min() will be fine.
>> >
>> Hi David,
>>
>> Both done in v2 — introduced a void *field local so the writes read
>> *(u64 *)field / *(unsigned int *)field, and switched to
>> min(v, (u64)UINT_MAX).
>
>You don't need the cast either.

Noted, this will be done in the next version.

Thanks,
Tao
>
> David
>
>>
>> Thanks,
>> Tao
>> > David
>> >
>> >
>> >
>> >>
>> >> tg_conf_updated(tg, false);
>> >> ret = 0;
>> >
>>
>