[RH7] ploop: Fix crash in purge_lru_warn()

Submitted by Kirill Tkhai on Nov. 10, 2020, 2:47 p.m.

Details

Message ID 160501964389.393252.7960881273539498568.stgit@localhost.localdomain
State New
Series "ploop: Fix crash in purge_lru_warn()"
Headers show

Commit Message

Kirill Tkhai Nov. 10, 2020, 2:47 p.m.
do_div() works wrong in case of the second argument is long.
We don't need remainder, so we don't need do_div() at all.

https://jira.sw.ru/browse/PSBM-122035

Reported-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/io_direct_map.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/io_direct_map.c b/drivers/block/ploop/io_direct_map.c
index 5528e86aab43..8f09ab083315 100644
--- a/drivers/block/ploop/io_direct_map.c
+++ b/drivers/block/ploop/io_direct_map.c
@@ -377,7 +377,7 @@  static inline void purge_lru_warn(struct extent_map_tree *tree)
 	loff_t ratio = i_size_read(tree->mapping->host) * 100;
 	long images_size = atomic_long_read(&ploop_io_images_size) ? : 1;
 
-	do_div(ratio, images_size);
+	ratio /= images_size;
 
 	printk(KERN_WARNING "Purging lru entry from extent tree for inode %ld "
 	       "(map_size=%d ratio=%lld%%)\n",

Comments

Evgenii Shatokhin Nov. 10, 2020, 4:29 p.m.
On 10.11.2020 17:47, Kirill Tkhai wrote:
> do_div() works wrong in case of the second argument is long.
> We don't need remainder, so we don't need do_div() at all.
> 
> https://jira.sw.ru/browse/PSBM-122035
> 
> Reported-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
> ---
>   drivers/block/ploop/io_direct_map.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/block/ploop/io_direct_map.c b/drivers/block/ploop/io_direct_map.c
> index 5528e86aab43..8f09ab083315 100644
> --- a/drivers/block/ploop/io_direct_map.c
> +++ b/drivers/block/ploop/io_direct_map.c
> @@ -377,7 +377,7 @@ static inline void purge_lru_warn(struct extent_map_tree *tree)
>   	loff_t ratio = i_size_read(tree->mapping->host) * 100;
>   	long images_size = atomic_long_read(&ploop_io_images_size) ? : 1;
>   
> -	do_div(ratio, images_size);
> +	ratio /= images_size;
>   
>   	printk(KERN_WARNING "Purging lru entry from extent tree for inode %ld "
>   	       "(map_size=%d ratio=%lld%%)\n",
> 
> 
> .
> 

Looks good to me. The simpler the better.

Reviewed-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
Andrey Ryabinin Nov. 10, 2020, 5:30 p.m.
On 11/10/20 5:47 PM, Kirill Tkhai wrote:
> do_div() works wrong in case of the second argument is long.
> We don't need remainder, so we don't need do_div() at all.
> 
> https://jira.sw.ru/browse/PSBM-122035
> 
> Reported-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
> Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>

Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>