All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: check the return value of kstrdup()
@ 2021-12-13  3:30 Xiaoke Wang
  2021-12-13  4:32 ` Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaoke Wang @ 2021-12-13  3:30 UTC (permalink / raw)
  To: tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel, Xiaoke Wang

kstrdup() returns NULL when some internal memory errors happen, it is
better to check the return value of it so to catch the memory error in
time.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 kernel/cgroup/cgroup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index ea08f01..47c7d58 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2228,6 +2228,9 @@ static int cpuset_init_fs_context(struct fs_context *fc)
 	struct cgroup_fs_context *ctx;
 	int err;
 
+	if (!agent)
+		return -ENOMEM;
+
 	err = cgroup_init_fs_context(fc);
 	if (err) {
 		kfree(agent);
-- 

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

* Re: [PATCH] cgroup: check the return value of kstrdup()
  2021-12-13  3:30 [PATCH] cgroup: check the return value of kstrdup() Xiaoke Wang
@ 2021-12-13  4:32 ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2021-12-13  4:32 UTC (permalink / raw)
  To: Xiaoke Wang, tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel

On Mon, 2021-12-13 at 11:30 +0800, Xiaoke Wang wrote:
> kstrdup() returns NULL when some internal memory errors happen, it is
> better to check the return value of it so to catch the memory error in
> time.
[]
> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
[]
> @@ -2228,6 +2228,9 @@ static int cpuset_init_fs_context(struct fs_context *fc)
>  	struct cgroup_fs_context *ctx;
>  	int err;
>  
> +	if (!agent)
> +		return -ENOMEM;
> +

Did you read all the other code that uses this?
Does it matter if it's NULL?
Why is it created with kstrdup in the first place?
Why should agent be anything other than const char *?
If it's const char * it shouldn't need to be used with
kstrdup/kfree.



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

end of thread, other threads:[~2021-12-13  4:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13  3:30 [PATCH] cgroup: check the return value of kstrdup() Xiaoke Wang
2021-12-13  4:32 ` Joe Perches

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.