From nobody Wed May 15 18:14:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1690522364750922.4239239032055; Thu, 27 Jul 2023 22:32:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPFnA-0006ai-J9; Fri, 28 Jul 2023 01:13:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qPFn7-0006aY-Lo for qemu-devel@nongnu.org; Fri, 28 Jul 2023 01:13:29 -0400 Received: from cmccmta4.chinamobile.com ([111.22.67.137] helo=cmccmta1.chinamobile.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qPFn4-0005Fd-Ce for qemu-devel@nongnu.org; Fri, 28 Jul 2023 01:13:29 -0400 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app04-12004 (RichMail) with SMTP id 2ee464c34e6b3dc-2e54f; Fri, 28 Jul 2023 13:13:16 +0800 (CST) Received: from localhost.localdomain (unknown[223.108.79.99]) by rmsmtp-syy-appsvr08-12008 (RichMail) with SMTP id 2ee864c34e623f6-94852; Fri, 28 Jul 2023 13:13:16 +0800 (CST) X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee464c34e6b3dc-2e54f X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee864c34e623f6-94852 From: dinglimin To: peter.maydell@linaro.org, mjt@tls.msk.ru, richard.henderson@linaro.org Cc: qemu-devel@nongnu.org, dinglimin Subject: [PATCH] semihosting/uaccess.c: Replaced a malloc call with g_malloc. Date: Fri, 28 Jul 2023 13:12:52 +0800 Message-Id: <20230728051253.551-1-dinglimin@cmss.chinamobile.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=111.22.67.137; envelope-from=dinglimin@cmss.chinamobile.com; helo=cmccmta1.chinamobile.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1690522367572100003 Content-Type: text/plain; charset="utf-8" Replaced a call to malloc() and its respective call to free() with g_malloc= () and g_free(). Signed-off-by: dinglimin v4 -> V5:Use g_try_malloc() instead of malloc() V3 -> V4:Delete null checks after g malloc(). V2 -> V3:softmmu_unlock_user changes free to g free. V1 -> V2:if cpu_memory_rw_debug failed, still need to set p=3DNULL Signed-off-by: dinglimin --- semihosting/uaccess.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 8018828069..35fdcd69db 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -14,13 +14,20 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, target_ulong len, bool copy) { - void *p =3D malloc(len); - if (p && copy) { + void *p =3D g_try_malloc(len); + + if (!p) { + p =3D NULL; + return p; + } + + if (copy) { if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); + g_free(p); p =3D NULL; } } + return p; } =20 @@ -87,5 +94,5 @@ void softmmu_unlock_user(CPUArchState *env, void *p, if (len) { cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); } - free(p); + g_free(p); } --=20 2.30.0.windows.2