Re: [PATCH v2] mm: fix div by zero in bdi_ratio_from_pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Hildenbrand <david@xxxxxxxxxx> writes:

...

>
> I would have done it slightly differently, something like:
>
>
> diff --git a/mm/page-writeback.c b/mm/page-writeback.c
> index d213ead956750..4b02f18f7d01f 100644
> --- a/mm/page-writeback.c
> +++ b/mm/page-writeback.c
> @@ -685,13 +685,15 @@ static int bdi_check_pages_limit(unsigned long pages)
>         return 0;
>  }
>  -static unsigned long bdi_ratio_from_pages(unsigned long pages)
> +static long bdi_ratio_from_pages(unsigned long pages)
>  {
>         unsigned long background_thresh;
>         unsigned long dirty_thresh;
>         unsigned long ratio;
>           global_dirty_limits(&background_thresh, &dirty_thresh);
> +       if (!dirty_thresh)
> +               return -EINVAL;
>         ratio = div64_u64(pages * 100ULL * BDI_RATIO_SCALE, dirty_thresh);
>           return ratio;
> @@ -790,13 +792,15 @@ int bdi_set_min_bytes(struct backing_dev_info *bdi, u64 min_bytes)
>  {
>         int ret;
>         unsigned long pages = min_bytes >> PAGE_SHIFT;
> -       unsigned long min_ratio;
> +       long min_ratio;
>           ret = bdi_check_pages_limit(pages);
>         if (ret)
>                 return ret;
>           min_ratio = bdi_ratio_from_pages(pages);
> +       if (min_ratio < 0)
> +               return min_ratio;
>         return __bdi_set_min_ratio(bdi, min_ratio);
>  }
>  @@ -809,13 +813,15 @@ int bdi_set_max_bytes(struct backing_dev_info *bdi, u64
> max_bytes)
>  {
>         int ret;
>         unsigned long pages = max_bytes >> PAGE_SHIFT;
> -       unsigned long max_ratio;
> +       long max_ratio;
>           ret = bdi_check_pages_limit(pages);
>         if (ret)
>                 return ret;
>           max_ratio = bdi_ratio_from_pages(pages);
> +       if (min_ratio < 0)

I assume you meant max_ratio.


> +               return min_ratio;
>         return __bdi_set_max_ratio(bdi, max_ratio);
>  }
>  -- Cheers,
>

I'll use your recommendation for the next version of the patch.




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux