linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: remove incorrect check on the return value of css_alloc
@ 2018-01-22 13:38 Xiongwei Song
  2018-01-22 15:55 ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Xiongwei Song @ 2018-01-22 13:38 UTC (permalink / raw)
  To: tj, guro, longman, davem, akpm; +Cc: linux-kernel, sxwjean

The function css_alloc never return NULL, it may return normal pointer or
error codes that made by ERR_PTR, so !css is always false, we need use
IS_ERR to check it, and if this is true, we should use ERR_CAST handle it.

Signed-off-by: Xiongwei Song <sxwjean@me.com>
---
 kernel/cgroup/cgroup.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index adac5b91d2b8..a442fd9ad744 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -4728,10 +4728,8 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp,
 	lockdep_assert_held(&cgroup_mutex);
 
 	css = ss->css_alloc(parent_css);
-	if (!css)
-		css = ERR_PTR(-ENOMEM);
 	if (IS_ERR(css))
-		return css;
+		return ERR_CAST(css);
 
 	init_and_link_css(css, ss, cgrp);
 
-- 
2.15.1

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

* Re: [PATCH] cgroup: remove incorrect check on the return value of css_alloc
  2018-01-22 13:38 [PATCH] cgroup: remove incorrect check on the return value of css_alloc Xiongwei Song
@ 2018-01-22 15:55 ` Tejun Heo
  2018-01-22 23:21   ` Xiongwei Song
  0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2018-01-22 15:55 UTC (permalink / raw)
  To: Xiongwei Song; +Cc: guro, longman, davem, akpm, linux-kernel, sxwjean

Hello,

On Mon, Jan 22, 2018 at 09:38:51PM +0800, Xiongwei Song wrote:
> The function css_alloc never return NULL, it may return normal pointer or

It's a calling a controller implemented method.  I'd much rather keep
the extra protection.

> error codes that made by ERR_PTR, so !css is always false, we need use
> IS_ERR to check it, and if this is true, we should use ERR_CAST handle it.

It's of the same type.  Why would it need casting?

Thanks.

-- 
tejun

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

* Re: [PATCH] cgroup: remove incorrect check on the return value of css_alloc
  2018-01-22 15:55 ` Tejun Heo
@ 2018-01-22 23:21   ` Xiongwei Song
  0 siblings, 0 replies; 3+ messages in thread
From: Xiongwei Song @ 2018-01-22 23:21 UTC (permalink / raw)
  To: Tejun Heo; +Cc: guro, longman, davem, akpm, linux-kernel, sxwjean


> On 22 Jan 2018, at 11:55 PM, Tejun Heo <tj@kernel.org> wrote:
> 
> Hello,
> 
> On Mon, Jan 22, 2018 at 09:38:51PM +0800, Xiongwei Song wrote:
>> The function css_alloc never return NULL, it may return normal pointer or
> 
> It's a calling a controller implemented method.  I'd much rather keep
> the extra protection.
> 
>> error codes that made by ERR_PTR, so !css is always false, we need use
>> IS_ERR to check it, and if this is true, we should use ERR_CAST handle it.
> 
> It's of the same type.  Why would it need casting?

Okay, Thanks for your comment.

Apologies for the noise.

Thanks
Xiongwei
> 
> Thanks.
> 
> -- 
> tejun

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

end of thread, other threads:[~2018-01-22 23:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-22 13:38 [PATCH] cgroup: remove incorrect check on the return value of css_alloc Xiongwei Song
2018-01-22 15:55 ` Tejun Heo
2018-01-22 23:21   ` Xiongwei 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).