From nobody Sun May 19 16:58:46 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 1690355322993698.064990131549; Wed, 26 Jul 2023 00:08:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOYcY-0005mq-63; Wed, 26 Jul 2023 03:07:42 -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 1qOYcU-0005mf-Ot for qemu-devel@nongnu.org; Wed, 26 Jul 2023 03:07:38 -0400 Received: from cmccmta6.chinamobile.com ([111.22.67.139] helo=cmccmta1.chinamobile.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOYcR-0000CG-M4 for qemu-devel@nongnu.org; Wed, 26 Jul 2023 03:07:38 -0400 Received: from spf.mail.chinamobile.com (unknown[10.188.0.87]) by rmmx-syy-dmz-app01-12001 (RichMail) with SMTP id 2ee164c0c62ff08-1efe1; Wed, 26 Jul 2023 15:07:28 +0800 (CST) Received: from localhost.localdomain (unknown[223.108.79.99]) by rmsmtp-syy-appsvr04-12004 (RichMail) with SMTP id 2ee464c0c62c302-64bdb; Wed, 26 Jul 2023 15:07:27 +0800 (CST) X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee164c0c62ff08-1efe1 X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 X-RM-TRANSID: 2ee464c0c62c302-64bdb 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: Wed, 26 Jul 2023 15:07:15 +0800 Message-Id: <20230726070715.409-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.139; 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: 1690355323994100001 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 V3 -> V4:Delete null checks after g malloc(). g_malloc() is preferred more than g_try_* functions, which return NULL on e= rror, when the size of the requested allocation is small. This is because allocating few bytes should not be a problem in a healthy s= ystem. Otherwise, the system is already in a critical state. 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 8018828069..81a0f80e9f 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -14,10 +14,10 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, target_ulong len, bool copy) { - void *p =3D malloc(len); + void *p =3D g_malloc(len); if (p && copy) { if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); + g_free(p); p =3D NULL; } } @@ -87,5 +87,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