From patchwork Fri Mar 4 14:21:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 548124 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp95842mag; Fri, 4 Mar 2022 07:03:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfOfPrhqxxl3Eggh6g9QtIA8kH8b9K9CCQszQbe+7YGjgZkXf3A3OIdqERdNK0bnq+hTof X-Received: by 2002:a25:ab08:0:b0:628:c3b6:220b with SMTP id u8-20020a25ab08000000b00628c3b6220bmr7300830ybi.257.1646406182956; Fri, 04 Mar 2022 07:03:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646406182; cv=none; d=google.com; s=arc-20160816; b=N2sk2xW0XKKaL3w4dhWVbPYwJt/jPVlRlez73k9rYlOnvhbjuVKK6nJo6RrARAj1t9 WHE4TLxkz28bFcpnbokP0NeRHENKJUANi8qNkcms/U7WcUZMOEQez6HbqwL+QCH83GD/ L1GpAkGEMofPNu0RtV93WwqCvkm+2X/sike8dI64lTU2V7Vjt66c9V8cSXz0AGr66MQS 0deLUYT7gIoF/whEw2F9Gn2oJDlsnmERd1hRMAv3s4IMzUgMyTOBlIZFY5/sZ1PUxhDO NXPc4MJcQFPuhojY145OFHjSEcsJXc4U7R5HUh29DIzQSNsITaxu9qu9BsO8wzeOCr8g 48wg== 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=1jIMKVjJSErsCeq5u/YaMwoi1VPhyRsihv2AV/JvcoI=; b=Kw5eq6XC1nz7WEyCoL/C7jE51gVyq9/iHPfzbAw5iuRsjaR0e7JFAIMw68LJWhuDxE MRTTb25QqI1ARCrE7+ev7ajUu4DvgG0bFD++DRLL+pH/v2As2Vh437+NZf8UfYVw+Elz RCXVrndVxUHgBTl8JKywGLmDi6pgsvd39or0dx7KOGShOj0AAJ9qNyvMJ0R3ffxl0NfO FEU70oGA3e74ikb2XSi7CFRy4sqpgqZ9Zb1nWBzgTbcP2su47SyR/mNZ421iUriOEdEF QhUot91brcvdwe4+n6Mvu4CrYZPr2fad8xe0UnlGb7SVwKve0CbljDYekKmNEH+Wk6p5 J1CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=YZE++aTQ; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r31-20020a25ac5f000000b00628bbf926besi4475999ybd.289.2022.03.04.07.03.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 04 Mar 2022 07:03:02 -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=@redhat.com header.s=mimecast20190719 header.b=YZE++aTQ; 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=redhat.com Received: from localhost ([::1]:32894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQ9SQ-0008GM-DP for patch@linaro.org; Fri, 04 Mar 2022 10:03:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ8rB-0005DE-D9 for qemu-devel@nongnu.org; Fri, 04 Mar 2022 09:24:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32335) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQ8r7-0002D7-7B for qemu-devel@nongnu.org; Fri, 04 Mar 2022 09:24:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646403868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1jIMKVjJSErsCeq5u/YaMwoi1VPhyRsihv2AV/JvcoI=; b=YZE++aTQaRnciBBaw8cW2/lbbfIoG7MqN28Xz57VJ2blGpCpJYgN5hSQ4jyTRMCwn9JYAY BH5mfyEdzqTgFvM8Aw5G/mO3eXb7hTLyhyarUgcRYpnWHnuJ9Lw8ENIe3jNC0QBzKbUtX9 +rl6V41LGLCNaybUqfDfqfBvwhCmq4Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-511-E_cQH8c9PECnC5kW_TfQ4w-1; Fri, 04 Mar 2022 09:24:25 -0500 X-MC-Unique: E_cQH8c9PECnC5kW_TfQ4w-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D547E1854E26; Fri, 4 Mar 2022 14:24:23 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.99]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7FF9C866EE; Fri, 4 Mar 2022 14:24:23 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 164BF18009B5; Fri, 4 Mar 2022 15:21:25 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 23/35] hw/usb/redirect.c: Stop using qemu_oom_check() Date: Fri, 4 Mar 2022 15:21:11 +0100 Message-Id: <20220304142123.956171-24-kraxel@redhat.com> In-Reply-To: <20220304142123.956171-1-kraxel@redhat.com> References: <20220304142123.956171-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kraxel@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.129.124; envelope-from=kraxel@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: Eduardo Habkost , Peter Maydell , =?utf-8?q?Daniel_P=2E_Berrang?= =?utf-8?q?=C3=A9?= , Akihiko Odaki , "Michael S. Tsirkin" , Thomas Huth , Richard Henderson , Christian Schoenebeck , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Gerd Hoffmann , Paolo Bonzini , Eric Blake Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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: Eric Blake Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-Id: <20220226180723.1706285-2-peter.maydell@linaro.org> Signed-off-by: Gerd Hoffmann --- 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 5f0ef9cb3b0f..8692ea256109 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);