mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jorge Lopez <jorgealtxwork@gmail.com>
To: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, thomas@t-8ch.de,
	ilpo.jarvinen@linux.intel.com
Subject: [PATCH 5/5] hp-bioscfg: Fix memory leaks in password_elements_from_package()
Date: Tue, 25 Jul 2023 17:00:56 -0500	[thread overview]
Message-ID: <20230725220056.25560-6-jorge.lopez2@hp.com> (raw)
In-Reply-To: <20230725220056.25560-1-jorge.lopez2@hp.com>

Address memory leaks in hp_populate_password_elements_from_package()
and uninitialized variable errors.

Signed-off-by: Jorge Lopez <jorge.lopez2@hp.com>

---
Based on the latest platform-drivers-x86.git/for-next
---
 .../platform/x86/hp/hp-bioscfg/passwdobj-attributes.c  | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c b/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
index 52e4d346b529..5e833ea0c5e3 100644
--- a/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
+++ b/drivers/platform/x86/hp/hp-bioscfg/passwdobj-attributes.c
@@ -227,7 +227,7 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor
 	int value_len;
 	int ret;
 	u32 size;
-	u32 int_value;
+	u32 int_value = 0;
 	int elem;
 	int reqs;
 	int eloc;
@@ -264,6 +264,7 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor
 		if (expected_password_types[eloc] != password_obj[elem].type) {
 			pr_err("Error expected type %d for elem %d, but got type %d instead\n",
 			       expected_password_types[eloc], elem, password_obj[elem].type);
+			kfree(str_value);
 			return -EIO;
 		}
 
@@ -318,6 +319,8 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor
 					sizeof(password_data->common.prerequisites[reqs]));
 
 				kfree(str_value);
+				str_value = NULL;
+
 			}
 			break;
 		case SECURITY_LEVEL:
@@ -356,6 +359,8 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor
 					str_value,
 					sizeof(password_data->encodings[pos_values]));
 				kfree(str_value);
+				str_value = NULL;
+
 			}
 			break;
 		case PSWD_IS_SET:
@@ -365,6 +370,9 @@ static int hp_populate_password_elements_from_package(union acpi_object *passwor
 			pr_warn("Invalid element: %d found in Password attribute or data may be malformed\n", elem);
 			break;
 		}
+
+		kfree(str_value);
+		str_value = NULL;
 	}
 
 exit_package:
-- 
2.34.1


  parent reply	other threads:[~2023-07-25 22:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 22:00 [PATCH 0/5] hp-bioscfg: Address memory leaks and uninitialized variable errors Jorge Lopez
2023-07-25 22:00 ` [PATCH 1/5] hp-bioscfg: Fix memory leaks in string_elements_from_package() Jorge Lopez
2023-07-25 22:00 ` [PATCH 2/5] hp-bioscfg: Fix memory leaks in ordered_list_elements_from_package Jorge Lopez
2023-07-27  6:21   ` Dan Carpenter
2023-07-31 16:03     ` Jorge Lopez
2023-07-31 16:16       ` Dan Carpenter
2023-07-31 16:35         ` Jorge Lopez
2023-08-01  5:54           ` Dan Carpenter
2023-08-01 13:24             ` Jorge Lopez
2023-07-25 22:00 ` [PATCH 3/5] hp-bioscfg: Fix memory leaks in integer_elements_from_package Jorge Lopez
2023-07-25 22:00 ` [PATCH 4/5] hp-bioscfg: Fix memory leaks in enumeration_elements_from_package() Jorge Lopez
2023-07-25 22:00 ` Jorge Lopez [this message]
2023-07-26 14:28 ` [PATCH 0/5] hp-bioscfg: Address memory leaks and uninitialized variable errors Hans de Goede

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=20230725220056.25560-6-jorge.lopez2@hp.com \
    --to=jorgealtxwork@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=thomas@t-8ch.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®