From patchwork Mon Feb 25 15:43:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 10828859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51CC11805 for ; Mon, 25 Feb 2019 16:22:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41A402BB58 for ; Mon, 25 Feb 2019 16:22:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FA232BB10; Mon, 25 Feb 2019 16:22:04 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 71DA92BD0C for ; Mon, 25 Feb 2019 16:22:02 +0000 (UTC) Received: from localhost ([127.0.0.1]:40006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyJ0z-0008H6-NG for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Feb 2019 11:22:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyIVM-0006B3-1O for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:49:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyIVL-0005RF-6K for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:49:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46868) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyIVK-0005Q3-Gs for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:49:18 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 207E730039B4 for ; Mon, 25 Feb 2019 15:43:43 +0000 (UTC) Received: from fziglio.remote.csb (unknown [10.33.32.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE0160BF4; Mon, 25 Feb 2019 15:43:39 +0000 (UTC) From: Frediano Ziglio To: Gerd Hoffmann Date: Mon, 25 Feb 2019 15:43:34 +0000 Message-Id: <20190225154335.11397-1-fziglio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 25 Feb 2019 15:43:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] audio: Use g_strdup_printf instead of manual building a string 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-devel@nongnu.org, Frediano Ziglio Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of using lot of low level function and manually allocate the temporary string in audio_process_options use more high level GLib function. The function is not used in hot path but to read some initial setting. Signed-off-by: Frediano Ziglio --- audio/audio.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index d163ffbc88..472721a7a9 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -454,9 +454,7 @@ static void audio_print_options (const char *prefix, static void audio_process_options (const char *prefix, struct audio_option *opt) { - char *optname; - const char qemu_prefix[] = "QEMU_"; - size_t preflen, optlen; + gchar *prefix_upper; if (audio_bug(__func__, !prefix)) { dolog ("prefix = NULL\n"); @@ -468,10 +466,10 @@ static void audio_process_options (const char *prefix, return; } - preflen = strlen (prefix); + prefix_upper = g_utf8_strup(prefix, -1); for (; opt->name; opt++) { - size_t len, i; + char *optname; int def; if (!opt->valp) { @@ -480,21 +478,7 @@ static void audio_process_options (const char *prefix, continue; } - len = strlen (opt->name); - /* len of opt->name + len of prefix + size of qemu_prefix - * (includes trailing zero) + zero + underscore (on behalf of - * sizeof) */ - optlen = len + preflen + sizeof (qemu_prefix) + 1; - optname = g_malloc (optlen); - - pstrcpy (optname, optlen, qemu_prefix); - - /* copy while upper-casing, including trailing zero */ - for (i = 0; i <= preflen; ++i) { - optname[i + sizeof (qemu_prefix) - 1] = qemu_toupper(prefix[i]); - } - pstrcat (optname, optlen, "_"); - pstrcat (optname, optlen, opt->name); + optname = g_strdup_printf("QEMU_%s_%s", prefix_upper, opt->name); def = 1; switch (opt->tag) { @@ -532,6 +516,7 @@ static void audio_process_options (const char *prefix, *opt->overriddenp = !def; g_free (optname); } + g_free(prefix_upper); } static void audio_print_settings (struct audsettings *as) From patchwork Mon Feb 25 15:43:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 10828865 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0641017EF for ; Mon, 25 Feb 2019 16:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5BBC2A370 for ; Mon, 25 Feb 2019 16:25:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3D942AA07; Mon, 25 Feb 2019 16:25:07 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 79FD82A370 for ; Mon, 25 Feb 2019 16:25:07 +0000 (UTC) Received: from localhost ([127.0.0.1]:40064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyJ3y-0002OA-LR for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Feb 2019 11:25:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyIX7-0007ZG-C0 for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:51:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyIX6-0006YQ-7c for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:51:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyIX5-0006LJ-Sr for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:51:08 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8111730014CC for ; Mon, 25 Feb 2019 15:43:44 +0000 (UTC) Received: from fziglio.remote.csb (unknown [10.33.32.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76F1160BE7; Mon, 25 Feb 2019 15:43:43 +0000 (UTC) From: Frediano Ziglio To: Gerd Hoffmann Date: Mon, 25 Feb 2019 15:43:35 +0000 Message-Id: <20190225154335.11397-2-fziglio@redhat.com> In-Reply-To: <20190225154335.11397-1-fziglio@redhat.com> References: <20190225154335.11397-1-fziglio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 25 Feb 2019 15:43:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] audio: Do not check for audio_calloc failure 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-devel@nongnu.org, Frediano Ziglio Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP audio_calloc uses g_malloc0 which never returns in case of memory failure. Signed-off-by: Frediano Ziglio --- audio/audio.c | 48 ++++++------------------------------------------ 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 472721a7a9..909c817103 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -811,12 +811,7 @@ static int audio_attach_capture (HWVoiceOut *hw) SWVoiceOut *sw; HWVoiceOut *hw_cap = &cap->hw; - sc = audio_calloc(__func__, 1, sizeof(*sc)); - if (!sc) { - dolog ("Could not allocate soft capture voice (%zu bytes)\n", - sizeof (*sc)); - return -1; - } + sc = g_malloc0(sizeof(*sc)); sc->cap = cap; sw = &sc->sw; @@ -1960,15 +1955,10 @@ CaptureVoiceOut *AUD_add_capture ( if (audio_validate_settings (as)) { dolog ("Invalid settings were passed when trying to add capture\n"); audio_print_settings (as); - goto err0; + return NULL; } - cb = audio_calloc(__func__, 1, sizeof(*cb)); - if (!cb) { - dolog ("Could not allocate capture callback information, size %zu\n", - sizeof (*cb)); - goto err0; - } + cb = g_malloc0(sizeof(*cb)); cb->ops = *ops; cb->opaque = cb_opaque; @@ -1981,12 +1971,7 @@ CaptureVoiceOut *AUD_add_capture ( HWVoiceOut *hw; CaptureVoiceOut *cap; - cap = audio_calloc(__func__, 1, sizeof(*cap)); - if (!cap) { - dolog ("Could not allocate capture voice, size %zu\n", - sizeof (*cap)); - goto err1; - } + cap = g_malloc0(sizeof(*cap)); hw = &cap->hw; QLIST_INIT (&hw->sw_head); @@ -1994,23 +1979,11 @@ CaptureVoiceOut *AUD_add_capture ( /* XXX find a more elegant way */ hw->samples = 4096 * 4; - hw->mix_buf = audio_calloc(__func__, hw->samples, - sizeof(struct st_sample)); - if (!hw->mix_buf) { - dolog ("Could not allocate capture mix buffer (%d samples)\n", - hw->samples); - goto err2; - } + hw->mix_buf = g_new0(struct st_sample, hw->samples); audio_pcm_init_info (&hw->info, as); - cap->buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift); - if (!cap->buf) { - dolog ("Could not allocate capture buffer " - "(%d samples, each %d bytes)\n", - hw->samples, 1 << hw->info.shift); - goto err3; - } + cap->buf = g_malloc0_n(hw->samples, 1 << hw->info.shift); hw->clip = mixeng_clip [hw->info.nchannels == 2] @@ -2025,15 +1998,6 @@ CaptureVoiceOut *AUD_add_capture ( audio_attach_capture (hw); } return cap; - - err3: - g_free (cap->hw.mix_buf); - err2: - g_free (cap); - err1: - g_free (cb); - err0: - return NULL; } }