From patchwork Sat Feb 26 18:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 546184 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp1376167imf; Sat, 26 Feb 2022 10:11:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzM1zfYCqHhvN8O1F4xeEuvFJupt0fdNGBPyuX91ylo8Sbqy24dMCljoWPEx86lwbg0Dt5S X-Received: by 2002:a25:d314:0:b0:624:6c1a:6f2d with SMTP id e20-20020a25d314000000b006246c1a6f2dmr12551348ybf.189.1645899113638; Sat, 26 Feb 2022 10:11:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645899113; cv=none; d=google.com; s=arc-20160816; b=M/vwyZIdHACA1/37O+JyS5XlmtVlGzk1HIzWgQI4nAOz4zOnybiGP/NgKWH6nnkxEP Sr3h1NQ1e+pTgDMLg7Wj2n40o1A2an6sT6vXT0uf5orv3HCLee9i9NQfgp0Wdd50wdYE lU4fDU2qVSA5aUMcWPaOvqkByvKHusL6CRkkrBgneh3Eu081WJzpxV9vbiyNQ885wTuq rsm+dEuSSSGChd0sQPzIEBkAw9Sr9o/A/MmZOiQyuMDZNETHif7E+wbN+8QlrmJ0aIyc RJ3KIX+zQ3SCR6j1g6WpKDmNpIPJq+4nzjOBSJLLXsgSVIhDVql+zGir8+8dFkW5ZeQz bulg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=uPrIPUtrD7DVBHc6YiS8HprIW42ya5uWba9xJ+v1w9U=; b=tmprmsVEsT2dv8S95uAK5o60RYIgQqiCTg3n5p2dIZ/HFWzsxPTz75ztIuJnoKfpx6 Gak8m0QHA5844JHGxNAC2QXkXRGgxF6EOtW0EOyIjwWeon83j6YW7zQgKIs0PYEp+9I1 Ppz6SEIDTtbkwHBHW6dmvw/zehr7tqb/uktVzB8fEu9Z4ZDZ6ardqlNJwwHMo/St96CZ YDSA3SsfRNX/jDu1N+w1sqiWFQMxdBsQyOIOdf4j8qMlcNgIW6PEYrs0y8HuafK35gJs niUKbIHozqNTXOzTm1gHS3ihScmr8P0JKEkIWaKQOPbYsDYp2Spj6DisX5J1au+twPG6 jAQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SAQmO2ob; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c82-20020a813555000000b002d693f423adsi5216136ywa.533.2022.02.26.10.11.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Feb 2022 10:11:53 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SAQmO2ob; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nO1Xt-0003qw-5N for patch@linaro.org; Sat, 26 Feb 2022 13:11:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nO1Th-0005Ye-QQ for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:34 -0500 Received: from [2a00:1450:4864:20::431] (port=36642 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nO1Tc-0004NH-OO for qemu-devel@nongnu.org; Sat, 26 Feb 2022 13:07:31 -0500 Received: by mail-wr1-x431.google.com with SMTP id r10so9201913wrp.3 for ; Sat, 26 Feb 2022 10:07:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uPrIPUtrD7DVBHc6YiS8HprIW42ya5uWba9xJ+v1w9U=; b=SAQmO2obJJRRwjizDWZ10WP2vySBnCuGbbC2Sv7eYjyyppe57zfWwAjNwWMIqOus19 FBVlp5hiVK58+Ygx70TtPFxlPmSXTRyWah73+kiOEl7doMohjIw+6l1FBX6mgkUAcqCc Fm6oUuHHWcCUrCoWyVYjHF2Eohl3bInT6gr+sMch+d3uQL9bDQSufcI5j7EkSN1bX5Ki UdBp7OudDNykDEU4fqCbVC025YEL4yRlOQ8qXhe6W3Hu7qmAQc47UaJJG/b0Yvk100RQ 33dj9pEiWmhEvQn/Sk6AYAz4/kJMf78MmG1gWtPCvn1gM6Y6m/4fXQb8gjNVqy6KJz5L DvXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uPrIPUtrD7DVBHc6YiS8HprIW42ya5uWba9xJ+v1w9U=; b=LmK+akDUBr+6Ogack93ylScFgDlGxvQzcDZnTDFKgCNdDG5zd+klYb4R+e+KbD8wWX Ker+tS+n5mVAFYZg3ATkHcfts6kP91WlYDOC0h5lSI4NeD11UyzWMfcY4OCBuo7v9cp9 C6yd7B0ezzF7LFw/ZD2G18FpwGifgjew26mk4soaEbGT0F6Z87SyAQqD9y2hkA7HvGkm 9u+aaolrkfM7RdD5GFKrtfPcGajJNCTFfq1xtSyWTizdZr4BokGljWvVFb+NzE6drQV/ fPNyW5DeNtZD0hYYZ9pczMqmb3lvULlMQt1loLJU5hCGEq+xbEXEDButboR35NOXtCO1 DX+A== X-Gm-Message-State: AOAM533HYKNE5Hdf+GZTHMFSfibMxsoo5GwpfTPLaHdkKPXJBXHaI9sJ +botGYT4GuBow5QPX+l36BtPeVSaWUmcBA== X-Received: by 2002:a5d:4892:0:b0:1ed:beaa:778a with SMTP id g18-20020a5d4892000000b001edbeaa778amr10095459wrq.35.1645898847282; Sat, 26 Feb 2022 10:07:27 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b15-20020adfe64f000000b001e60965a5d4sm5622409wrn.44.2022.02.26.10.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Feb 2022 10:07:26 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PATCH 1/9] hw/usb/redirect.c: Stop using qemu_oom_check() Date: Sat, 26 Feb 2022 18:07:15 +0000 Message-Id: <20220226180723.1706285-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220226180723.1706285-1-peter.maydell@linaro.org> References: <20220226180723.1706285-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Paolo Bonzini , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" qemu_oom_check() is a function which essentially says "if you pass me a NULL pointer then print a message then abort()". On POSIX systems the message includes strerror(errno); on Windows it includes the GetLastError() error value printed as an integer. Other than in the implementation of qemu_memalign(), we use this function only in hw/usb/redirect.c, for three checks: * on a call to usbredirparser_create() * on a call to usberedirparser_serialize() * on a call to malloc() The usbredir library API functions make no guarantees that they will set errno on errors, let alone that they might set the Windows-specific GetLastError string. malloc() is documented as setting errno, not GetLastError -- and in any case the only thing it might set errno to is ENOMEM. So qemu_oom_check() isn't the right thing for any of these. Replace them with straightforward error-checking code. This will allow us to get rid of qemu_oom_check(). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Eric Blake --- I have left all of these errors as fatal, since that's what they were previously. Possibly somebody with a better understanding of the usbredir code might be able to make them theoretically non-fatal, but we make malloc failures generally fatal anyway. --- hw/usb/redirect.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 5f0ef9cb3b0..8692ea25610 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -1239,7 +1239,11 @@ static void usbredir_create_parser(USBRedirDevice *dev) DPRINTF("creating usbredirparser\n"); - dev->parser = qemu_oom_check(usbredirparser_create()); + dev->parser = usbredirparser_create(); + if (!dev->parser) { + error_report("usbredirparser_create() failed"); + exit(1); + } dev->parser->priv = dev; dev->parser->log_func = usbredir_log; dev->parser->read_func = usbredir_read; @@ -2239,7 +2243,10 @@ static int usbredir_put_parser(QEMUFile *f, void *priv, size_t unused, } usbredirparser_serialize(dev->parser, &data, &len); - qemu_oom_check(data); + if (!data) { + error_report("usbredirparser_serialize failed"); + exit(1); + } qemu_put_be32(f, len); qemu_put_buffer(f, data, len); @@ -2330,7 +2337,11 @@ static int usbredir_get_bufpq(QEMUFile *f, void *priv, size_t unused, bufp->len = qemu_get_be32(f); bufp->status = qemu_get_be32(f); bufp->offset = 0; - bufp->data = qemu_oom_check(malloc(bufp->len)); /* regular malloc! */ + bufp->data = malloc(bufp->len); /* regular malloc! */ + if (!bufp->data) { + error_report("usbredir_get_bufpq: out of memory"); + exit(1); + } bufp->free_on_destroy = bufp->data; qemu_get_buffer(f, bufp->data, bufp->len); QTAILQ_INSERT_TAIL(&endp->bufpq, bufp, next);