From patchwork Mon May 8 18:00:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 9716517 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 104D3602A0 for ; Mon, 8 May 2017 18:02:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A6521FF29 for ; Mon, 8 May 2017 18:02:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2506223A6; Mon, 8 May 2017 18:02:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE84C1FF29 for ; Mon, 8 May 2017 18:02:16 +0000 (UTC) Received: from localhost ([::1]:60776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7mz7-0006Jb-RV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 May 2017 14:02:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7myF-0006Ih-LR for qemu-devel@nongnu.org; Mon, 08 May 2017 14:01:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7myA-0003vD-Rn for qemu-devel@nongnu.org; Mon, 08 May 2017 14:01:19 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:36037) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d7myA-0003ux-L8; Mon, 08 May 2017 14:01:14 -0400 Received: by mail-wr0-x244.google.com with SMTP id v42so9744760wrc.3; Mon, 08 May 2017 11:01:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EK3UStvTbHb0GLOr/S0OVuh+3HqmJipnnHupQ2xoRHY=; b=hQ7hIFbhDTgYYxiCbifGw1xtnT/qa+e0r9yRPnBSOQTQWDd929aERa3Dr9B1klsIfc fXxYUol/zwpkD1c+QttU9fIjJKxcdLsUuwornV1ahcmUCxn/9DyJ7MBRSGPpNzY2tlKN zgpXF8G41o44P8OavYT/KRD72AM+Woo/Bqh2Rth7xYyNZgOzyA+5D8j/losUvg4h514L jfmlFUhioAunax7+NlTR9c2EdPXNooZPlAYUVSzefGrRGd/bR1CsZUN5k85K99DvLbmX i0eydjXyWDA5qxuenbylc2q3PwR3My/OR/0XsFgShfjQJCS1ROVlUE6tPyTO5Wc6TIHT 7Elw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EK3UStvTbHb0GLOr/S0OVuh+3HqmJipnnHupQ2xoRHY=; b=l6EGwS0CAUFwbvGa5Vv4cjg2yI2rNOXlS1qkF0eE58sNN3AHYU9UxIaCKuDbwr+shk t7kMIrrdGtyVSpPJ6jaQNBC0xqrZX3KmBIMG+T6G4TLAyQ1qnKv1C5aN85jc2vOQG6p4 VnHxuNJxAO2Dk9DUk+56zhkLkS7AcX/Aqk7ph1ocz2W3x9RBtm64h8ynmIboMR0qyhq3 opnId1UWiKZvzvRSwXwi+U67Rrw1UEHZQm/pDK1p258Mg0hgq27ndZdGJ48gbYL6ffUF BHlgMM1Lpkg5e5p22cAfZ3Qg5VP/moxVY/xgeYEkkiTcftZeONP0YPaiv8IbzgmarF8Z BNlA== X-Gm-Message-State: AODbwcAsW7hacGWqSoiDINAgNc4y1vA39h+u1RSvSb2c0kUuXldE6jdJ C7ZK/jVbmTED8A== X-Received: by 10.46.69.66 with SMTP id s63mr6851800lja.88.1494266473443; Mon, 08 May 2017 11:01:13 -0700 (PDT) Received: from octofox.metropolis ([5.19.183.212]) by smtp.gmail.com with ESMTPSA id s126sm1645874lja.43.2017.05.08.11.01.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 11:01:12 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Mon, 8 May 2017 11:00:56 -0700 Message-Id: <1494266456-2251-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PATCH] hw/xtensa: sim: use g_string/g_new X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU Trivial , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Replace malloc/free/sprintf with g_string/g_string_printf/g_string_free. Replace g_malloc with g_new when allocating the MemoryRegion to get more type safety. Suggested-by: Alex Bennée Signed-off-by: Max Filippov Reviewed-by: Philippe Mathieu-Daudé --- hw/xtensa/sim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c index d2d1d3a..b27e28d 100644 --- a/hw/xtensa/sim.c +++ b/hw/xtensa/sim.c @@ -41,21 +41,21 @@ static void xtensa_create_memory_regions(const XtensaMemory *memory, const char *name) { unsigned i; - char *num_name = malloc(strlen(name) + sizeof(i) * 3 + 1); + GString *num_name = g_string_new(NULL); for (i = 0; i < memory->num; ++i) { MemoryRegion *m; - sprintf(num_name, "%s%u", name, i); - m = g_malloc(sizeof(*m)); - memory_region_init_ram(m, NULL, num_name, + g_string_printf(num_name, "%s%u", name, i); + m = g_new(MemoryRegion, 1); + memory_region_init_ram(m, NULL, num_name->str, memory->location[i].size, &error_fatal); vmstate_register_ram_global(m); memory_region_add_subregion(get_system_memory(), memory->location[i].addr, m); } - free(num_name); + g_string_free(num_name, true); } static uint64_t translate_phys_addr(void *opaque, uint64_t addr)