2020-07-25 00:16:08

by Yi Wang

[permalink] [raw]
Subject: [PATCH] sh: sh4: Fix reference count leak in sq_dev_add

From: Liao Pingfang <[email protected]>

kobject_init_and_add() takes reference even when it fails. If this
function returns an error, kobject_put() must be called to properly
clean up the memory associated with the object.

Signed-off-by: Liao Pingfang <[email protected]>
Signed-off-by: Yi Wang <[email protected]>
---
arch/sh/kernel/cpu/sh4/sq.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index d432164..3fbd6fd 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -350,6 +350,8 @@ static int sq_dev_add(struct device *dev, struct subsys_interface *sif)
"%s", "sq");
if (!error)
kobject_uevent(kobj, KOBJ_ADD);
+ else
+ kobject_put(kobj);
return error;
}

--
2.9.5


2020-07-25 11:29:12

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] sh: sh4: Fix reference count leak in sq_dev_add

> kobject_init_and_add() takes reference even when it fails. If this
> function returns an error, kobject_put() must be called to properly
> clean up the memory associated with the object.

* An imperative wording can be preferred for the change description,
can't it?

* Would you like to add the tag “Fixes” to the commit message?

Regards,
Markus

2020-07-25 11:29:18

by Markus Elfring

[permalink] [raw]
Subject: Re: [PATCH] sh: sh4: Fix reference count leak in sq_dev_add

> kobject_init_and_add() takes reference even when it fails. If this
> function returns an error, kobject_put() must be called to properly
> clean up the memory associated with the object.

* An imperative wording can be preferred for the change description,
can't it?

* Would you like to add the tag “Fixes” to the commit message?

Regards,
Markus