diff mbox series

[03/15] mm/swap: fold __swap_info_get() into its sole caller

Message ID 20220509131416.17553-4-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup patches for swap | expand

Commit Message

Miaohe Lin May 9, 2022, 1:14 p.m. UTC
Fold __swap_info_get() into its sole caller to make code more clear.
Minor readability improvement.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/swapfile.c | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

Comments

David Hildenbrand May 12, 2022, 1:29 p.m. UTC | #1
On 09.05.22 15:14, Miaohe Lin wrote:
> Fold __swap_info_get() into its sole caller to make code more clear.
> Minor readability improvement.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Reviewed-by: David Hildenbrand <david@redhat.com>
Oscar Salvador May 18, 2022, 8:56 a.m. UTC | #2
On Mon, May 09, 2022 at 09:14:04PM +0800, Miaohe Lin wrote:
> Fold __swap_info_get() into its sole caller to make code more clear.
> Minor readability improvement.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>

Reviewed-by: Oscar Salvador <osalvador@suse.de>

> ---
>  mm/swapfile.c | 24 ++++++------------------
>  1 file changed, 6 insertions(+), 18 deletions(-)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 05ca79e68d63..0aee6286d6a7 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1123,7 +1123,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)
>  	return n_ret;
>  }
>  
> -static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
> +static struct swap_info_struct *_swap_info_get(swp_entry_t entry)
>  {
>  	struct swap_info_struct *p;
>  	unsigned long offset;
> @@ -1138,8 +1138,13 @@ static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
>  	offset = swp_offset(entry);
>  	if (offset >= p->max)
>  		goto bad_offset;
> +	if (data_race(!p->swap_map[swp_offset(entry)]))
> +		goto bad_free;
>  	return p;
>  
> +bad_free:
> +	pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val);
> +	goto out;
>  bad_offset:
>  	pr_err("%s: %s%08lx\n", __func__, Bad_offset, entry.val);
>  	goto out;
> @@ -1152,23 +1157,6 @@ static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
>  	return NULL;
>  }
>  
> -static struct swap_info_struct *_swap_info_get(swp_entry_t entry)
> -{
> -	struct swap_info_struct *p;
> -
> -	p = __swap_info_get(entry);
> -	if (!p)
> -		goto out;
> -	if (data_race(!p->swap_map[swp_offset(entry)]))
> -		goto bad_free;
> -	return p;
> -
> -bad_free:
> -	pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val);
> -out:
> -	return NULL;
> -}
> -
>  static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry,
>  					struct swap_info_struct *q)
>  {
> -- 
> 2.23.0
> 
>
diff mbox series

Patch

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 05ca79e68d63..0aee6286d6a7 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1123,7 +1123,7 @@  int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size)
 	return n_ret;
 }
 
-static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
+static struct swap_info_struct *_swap_info_get(swp_entry_t entry)
 {
 	struct swap_info_struct *p;
 	unsigned long offset;
@@ -1138,8 +1138,13 @@  static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
 	offset = swp_offset(entry);
 	if (offset >= p->max)
 		goto bad_offset;
+	if (data_race(!p->swap_map[swp_offset(entry)]))
+		goto bad_free;
 	return p;
 
+bad_free:
+	pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val);
+	goto out;
 bad_offset:
 	pr_err("%s: %s%08lx\n", __func__, Bad_offset, entry.val);
 	goto out;
@@ -1152,23 +1157,6 @@  static struct swap_info_struct *__swap_info_get(swp_entry_t entry)
 	return NULL;
 }
 
-static struct swap_info_struct *_swap_info_get(swp_entry_t entry)
-{
-	struct swap_info_struct *p;
-
-	p = __swap_info_get(entry);
-	if (!p)
-		goto out;
-	if (data_race(!p->swap_map[swp_offset(entry)]))
-		goto bad_free;
-	return p;
-
-bad_free:
-	pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val);
-out:
-	return NULL;
-}
-
 static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry,
 					struct swap_info_struct *q)
 {