All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gavin Shan <gshan@redhat.com>
To: linux-arm-kernel@lists.infradead.org
Cc: mark.rutland@arm.com, catalin.marinas@arm.com,
	james.morse@arm.com, shan.gavin@gmail.com,
	Jonathan.Cameron@huawei.com, will@kernel.org
Subject: [PATCH v3 02/15] drivers/firmware/sdei: Common block for failing path in sdei_event_create()
Date: Tue, 28 Jul 2020 12:59:42 +1000	[thread overview]
Message-ID: <20200728025955.144913-3-gshan@redhat.com> (raw)
In-Reply-To: <20200728025955.144913-1-gshan@redhat.com>

There are multiple calls of kfree(event) in the failing path of
sdei_event_create() to free the SDEI event. It means we need to
call it again when adding more code in the failing path. It's
prone to miss doing that and introduce memory leakage.

This introduces common block for failing path in sdei_event_create()
to resolve the issue. This shouldn't cause functional changes.

Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/firmware/arm_sdei.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c
index be5367f839f2..67da02b3a06e 100644
--- a/drivers/firmware/arm_sdei.c
+++ b/drivers/firmware/arm_sdei.c
@@ -190,33 +190,31 @@ static struct sdei_event *sdei_event_create(u32 event_num,
 	lockdep_assert_held(&sdei_events_lock);
 
 	event = kzalloc(sizeof(*event), GFP_KERNEL);
-	if (!event)
-		return ERR_PTR(-ENOMEM);
+	if (!event) {
+		err = -ENOMEM;
+		goto fail;
+	}
 
 	INIT_LIST_HEAD(&event->list);
 	event->event_num = event_num;
 
 	err = sdei_api_event_get_info(event_num, SDEI_EVENT_INFO_EV_PRIORITY,
 				      &result);
-	if (err) {
-		kfree(event);
-		return ERR_PTR(err);
-	}
+	if (err)
+		goto fail;
 	event->priority = result;
 
 	err = sdei_api_event_get_info(event_num, SDEI_EVENT_INFO_EV_TYPE,
 				      &result);
-	if (err) {
-		kfree(event);
-		return ERR_PTR(err);
-	}
+	if (err)
+		goto fail;
 	event->type = result;
 
 	if (event->type == SDEI_EVENT_TYPE_SHARED) {
 		reg = kzalloc(sizeof(*reg), GFP_KERNEL);
 		if (!reg) {
-			kfree(event);
-			return ERR_PTR(-ENOMEM);
+			err = -ENOMEM;
+			goto fail;
 		}
 
 		reg->event_num = event_num;
@@ -231,8 +229,8 @@ static struct sdei_event *sdei_event_create(u32 event_num,
 
 		regs = alloc_percpu(struct sdei_registered_event);
 		if (!regs) {
-			kfree(event);
-			return ERR_PTR(-ENOMEM);
+			err = -ENOMEM;
+			goto fail;
 		}
 
 		for_each_possible_cpu(cpu) {
@@ -252,6 +250,10 @@ static struct sdei_event *sdei_event_create(u32 event_num,
 	spin_unlock(&sdei_list_lock);
 
 	return event;
+
+fail:
+	kfree(event);
+	return ERR_PTR(err);
 }
 
 static void sdei_event_destroy_llocked(struct sdei_event *event)
-- 
2.23.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-07-28  3:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-28  2:59 [PATCH v3 00/15] Refactor SDEI client driver Gavin Shan
2020-07-28  2:59 ` [PATCH v3 01/15] drivers/firmware/sdei: Remove sdei_is_err() Gavin Shan
2020-07-28  2:59 ` Gavin Shan [this message]
2020-07-28  2:59 ` [PATCH v3 03/15] drivers/firmware/sdei: Retrieve event number from event instance Gavin Shan
2020-07-28  2:59 ` [PATCH v3 04/15] drivers/firmware/sdei: Avoid nested statements in sdei_init() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 05/15] drivers/firmware/sdei: Unregister driver on error " Gavin Shan
2020-07-28  2:59 ` [PATCH v3 06/15] drivers/firmware/sdei: Remove duplicate check in sdei_get_conduit() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 07/15] drivers/firmware/sdei: Remove Drop redundant error message in sdei_probe() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 08/15] drivers/firmware/sdei: Remove while loop in sdei_event_register() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 09/15] drivers/firmware/sdei: Remove while loop in sdei_event_unregister() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 10/15] drivers/firmware/sdei: Cleanup on cross call function Gavin Shan
2020-07-28  2:59 ` [PATCH v3 11/15] drivers/firmware/sdei: Introduce sdei_do_local_call() Gavin Shan
2020-07-28 15:32   ` Jonathan Cameron
2020-07-29 23:31     ` Gavin Shan
2020-07-28  2:59 ` [PATCH v3 12/15] drivers/firmware/sdei: Remove _sdei_event_register() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 13/15] drivers/firmware/sdei: Remove _sdei_event_unregister() Gavin Shan
2020-07-28  2:59 ` [PATCH v3 14/15] drivers/firmware/sdei: Expose struct sdei_event Gavin Shan
2020-07-28 15:48   ` Jonathan Cameron
2020-07-30  0:34     ` Gavin Shan
2020-07-28  2:59 ` [PATCH v3 15/15] drivers/firmware/sdei: Identify event by " Gavin Shan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200728025955.144913-3-gshan@redhat.com \
    --to=gshan@redhat.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=shan.gavin@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.