All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiasheng Jiang <jiashengjiangcool@outlook.com>
To: rafael@kernel.org, lenb@kernel.org, lv.zheng@intel.com,
	rui.zhang@intel.com
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiasheng Jiang <jiashengjiangcool@outlook.com>
Subject: [PATCH] ACPI: scan: Add missing check for kstrdup()
Date: Sat, 11 May 2024 19:35:53 +0000	[thread overview]
Message-ID: <BYAPR03MB4168E7E5A2616EB82D3883E8ADE02@BYAPR03MB4168.namprd03.prod.outlook.com> (raw)

Add check for the return value of kstrdup() in order to gurantee
the success of allocation.
Moreover, move the code forward to simplify the error handling.

Fixes: ccf78040265b ("ACPI: Add _UID support for ACPI devices.")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@outlook.com>
---
 drivers/acpi/scan.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index d1464324de95..59246757a207 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1385,6 +1385,15 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 			return;
 		}
 
+		if (info->valid & ACPI_VALID_UID) {
+			pnp->unique_id = kstrdup(info->unique_id.string,
+							GFP_KERNEL);
+			if (!pnp->unique_id) {
+				kfree(info);
+				return;
+			}
+		}
+
 		if (info->valid & ACPI_VALID_HID) {
 			acpi_add_id(pnp, info->hardware_id.string);
 			pnp->type.platform_id = 1;
@@ -1398,9 +1407,6 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 			pnp->bus_address = info->address;
 			pnp->type.bus_address = 1;
 		}
-		if (info->valid & ACPI_VALID_UID)
-			pnp->unique_id = kstrdup(info->unique_id.string,
-							GFP_KERNEL);
 		if (info->valid & ACPI_VALID_CLS)
 			acpi_add_id(pnp, info->class_code.string);
 
-- 
2.25.1


             reply	other threads:[~2024-05-11 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-11 19:35 Jiasheng Jiang [this message]
2024-05-14 13:03 ` [PATCH] ACPI: scan: Add missing check for kstrdup() Rafael J. Wysocki

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=BYAPR03MB4168E7E5A2616EB82D3883E8ADE02@BYAPR03MB4168.namprd03.prod.outlook.com \
    --to=jiashengjiangcool@outlook.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    /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.