linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M()
@ 2022-05-22 14:18 Christophe JAILLET
  2022-05-23 13:48 ` David Vernet
  2022-05-23 13:55 ` Muchun Song
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-05-22 14:18 UTC (permalink / raw)
  To: dan.carpenter, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Shakeel Butt, Muchun Song, Tejun Heo, Zefan Li, Shuah Khan,
	David Vernet, Andrew Morton
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, cgroups,
	linux-mm, linux-kselftest

If the first goto is taken, 'fd' is not opened yet (and is un-initialized).
So a direct return is safer.

Fixes: c1a31a2f7a9c ("cgroup: fix racy check in alloc_pagecache_max_30M() helper function")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 tools/testing/selftests/cgroup/test_memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
index c3d0d5f7b19c..8833359556f3 100644
--- a/tools/testing/selftests/cgroup/test_memcontrol.c
+++ b/tools/testing/selftests/cgroup/test_memcontrol.c
@@ -448,7 +448,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg)
 	high = cg_read_long(cgroup, "memory.high");
 	max = cg_read_long(cgroup, "memory.max");
 	if (high != MB(30) && max != MB(30))
-		goto cleanup;
+		return -1;
 
 	fd = get_temp_fd();
 	if (fd < 0)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M()
  2022-05-22 14:18 [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M() Christophe JAILLET
@ 2022-05-23 13:48 ` David Vernet
  2022-05-23 13:55 ` Muchun Song
  1 sibling, 0 replies; 3+ messages in thread
From: David Vernet @ 2022-05-23 13:48 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: dan.carpenter, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Shakeel Butt, Muchun Song, Tejun Heo, Zefan Li, Shuah Khan,
	Andrew Morton, linux-kernel, kernel-janitors, cgroups, linux-mm,
	linux-kselftest

On Sun, May 22, 2022 at 04:18:51PM +0200, Christophe JAILLET wrote:
> If the first goto is taken, 'fd' is not opened yet (and is un-initialized).
> So a direct return is safer.
> 
> Fixes: c1a31a2f7a9c ("cgroup: fix racy check in alloc_pagecache_max_30M() helper function")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  tools/testing/selftests/cgroup/test_memcontrol.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c
> index c3d0d5f7b19c..8833359556f3 100644
> --- a/tools/testing/selftests/cgroup/test_memcontrol.c
> +++ b/tools/testing/selftests/cgroup/test_memcontrol.c
> @@ -448,7 +448,7 @@ static int alloc_pagecache_max_30M(const char *cgroup, void *arg)
>  	high = cg_read_long(cgroup, "memory.high");
>  	max = cg_read_long(cgroup, "memory.max");
>  	if (high != MB(30) && max != MB(30))
> -		goto cleanup;
> +		return -1;
>  
>  	fd = get_temp_fd();
>  	if (fd < 0)
> -- 
> 2.34.1
> 

Acked-by: David Vernet <void@manifault.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M()
  2022-05-22 14:18 [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M() Christophe JAILLET
  2022-05-23 13:48 ` David Vernet
@ 2022-05-23 13:55 ` Muchun Song
  1 sibling, 0 replies; 3+ messages in thread
From: Muchun Song @ 2022-05-23 13:55 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: dan.carpenter, Johannes Weiner, Michal Hocko, Roman Gushchin,
	Shakeel Butt, Tejun Heo, Zefan Li, Shuah Khan, David Vernet,
	Andrew Morton, linux-kernel, kernel-janitors, cgroups, linux-mm,
	linux-kselftest

On Sun, May 22, 2022 at 04:18:51PM +0200, Christophe JAILLET wrote:
> If the first goto is taken, 'fd' is not opened yet (and is un-initialized).
> So a direct return is safer.
> 
> Fixes: c1a31a2f7a9c ("cgroup: fix racy check in alloc_pagecache_max_30M() helper function")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Muchun Song <songmuchun@bytedance.com>

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-23 13:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-22 14:18 [PATCH] cgroup: Fix an error handling path in alloc_pagecache_max_30M() Christophe JAILLET
2022-05-23 13:48 ` David Vernet
2022-05-23 13:55 ` Muchun Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).