From patchwork Tue Jul 18 10:13:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 704047 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e4d:0:b0:314:25da:8dc4 with SMTP id r13csp1445492wrt; Tue, 18 Jul 2023 03:14:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlFQwqQt5fXL3HpI5ZOC5i/ystHVZgTuiKOOisaDjx897KIG7ymBMAYNhJYpL0XGXClXKFPU X-Received: by 2002:a05:620a:4144:b0:767:7d86:b7fe with SMTP id k4-20020a05620a414400b007677d86b7femr2323922qko.6.1689675241639; Tue, 18 Jul 2023 03:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689675241; cv=none; d=google.com; s=arc-20160816; b=ihbFttcDalvG3h4iDH+TzBSf11l3fgJy046d+/MnTzIqQ5qVq0yThSLZO+DuFaSAP7 H3f+lGPNd9t7YbeKvf2X66ElUxIMn/p6uhLrlMUW9L+yePCfp0F/Yw2LbG0NjkW+GhLp y7eN4oVeRTNlUuChlj3RL2Uc16lUnUrrA4+B8mOhc/0KyHmowFdBxdiFGamwnOGzt/Qx 1equveq9TTCzBe5ltNZ4VuPcM+gFz7FktIxkFL/8ehVxAoa9Iv1ijX8MyEj3uLZ1PZ2M CXfcwQBZ/kmP+H8khY+yi90/DQrW8/LNM4DMaF/YNeuY5qxusfIeQayc2jj4WalIUUY0 0oKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=SxF+adkG9POmfvABIs1cEVjtEat+n4+pscBvBaP5wS0=; fh=5BIIK8ltSxs/Tg+WOrF//X74bsaERYqIimNiu8iw7EI=; b=RIfb8IbJT2rfpkvOH1YO2OFBv15rAvISyQ2aJEfDwYynG++8ABc/+uRLUUnX3rWFpL sGK+BOmVhQvkIDVJAxMnCv7wMcwV8zmnQ0Oig68P8L+yquvHzVT5R1Jg096RfZjNc9HB iAA8i+CRqDmfz9qHbGqbBW4QtPDYnY7kgg4TDorLaWU26k+6Bom4+WkAuYIaDXaVee3b vOickjqISsTh1tZwyd9n/wMhgy8jnSJ9sSLMIqCPKBJqzDBgrPnJiS2rsqDbHYbC9Bcu ozGMgtSH3m+4Koa9Qi9BxMZOtK2A+xgSnGDXYAXWtG+psaZW4YyWYpleZb+NB8WjCdmr U60A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pX5sNz07; 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=pass (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 dy7-20020a05620a60c700b00767e822cfcdsi754378qkb.693.2023.07.18.03.14.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Jul 2023 03:14:01 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=pX5sNz07; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qLhiG-000212-Ho; Tue, 18 Jul 2023 06:13:48 -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 1qLhiE-00020f-QC for qemu-devel@nongnu.org; Tue, 18 Jul 2023 06:13:47 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qLhhy-0001fZ-Cl for qemu-devel@nongnu.org; Tue, 18 Jul 2023 06:13:44 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbc5d5746cso55701915e9.2 for ; Tue, 18 Jul 2023 03:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689675209; x=1692267209; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SxF+adkG9POmfvABIs1cEVjtEat+n4+pscBvBaP5wS0=; b=pX5sNz07+nrenfzof5N8GXZZ1+/CDLnEQTcqoEiMmt8kz+Izi7XDfyRFa8m9iHW7TP YbJM5mUweil7hj27UZU2WQU90nmE2pYMr5lkAmwQthZJklCtP8+9JzEqzseY0SounDXi +y1cm3vWUgkjFtMVFZDP1qoIiSlsFhiWpX+5U3BfAliVo2smXct2uUndxey8OIe2gs52 hHYoZpvsBhNgDug7qPTzR5PdrKR1DGoTih2mTwLgrNmG0Vp7qwoFOjIDxwB0+4AqvO+D OWWd98wNcngQgMqFixpf5iXu1jDtYr1R0I3PEiSjHaMG6HSSlTS1YX8c833tqyDWT7of YA5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689675209; x=1692267209; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SxF+adkG9POmfvABIs1cEVjtEat+n4+pscBvBaP5wS0=; b=a5vSmjvCgmZBUVU2FO/qJp6mbLOb5JL70QmId6uGHVJPasn+PDweV8QqbhQfOkZTuz Uaz8jj6MfxwZ1cO7QTXSKbFawgC8XGWxEsQLOcXw5r2knN7ciddEdIxIAmI1bfUsDzGU qFjp7igGtFCSh5IDJwUH5ztURqMBTzfHL9xEPWyezPZcmNyZNo4viytzGhRTluGVVqOz it3VwA2Rz/Lnyiu/m3iKbq6pCr/4LfoICjp7PLEG8IUncZU1sxJj6MtLm4UMX28T1kcG Ht9iHfKjL+f7QIAvVwN97hM+Q+YgHVrnEIsULyQwA+rBx3Eynk7Rwc6p5YEvg20mUGXo o5yA== X-Gm-Message-State: ABy/qLZn6Wc6aRSLuSeLPIXiGMKG1sRkwtYvJB7249MhvQodNJXQGvfU c4TmznQFFpR1oPHvqJ3CoS6S4cZnMm7OrATTnOc= X-Received: by 2002:adf:f452:0:b0:314:2e77:afec with SMTP id f18-20020adff452000000b003142e77afecmr12851551wrp.57.1689675208724; Tue, 18 Jul 2023 03:13:28 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id q4-20020adffec4000000b003144bfbd0b3sm1956529wrs.37.2023.07.18.03.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jul 2023 03:13:28 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Marcel Apfelbaum , Jonathan Cameron Subject: [PATCH for-8.1] hw/pci-bridge/cxl_upstream.c: Use g_new0() in build_cdat_table() Date: Tue, 18 Jul 2023 11:13:27 +0100 Message-Id: <20230718101327.1111374-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In build_cdat_table() we do: *cdat_table = g_malloc0(sizeof(*cdat_table) * CXL_USP_CDAT_NUM_ENTRIES); This is wrong because: - cdat_table has type CDATSubHeader *** - so *cdat_table has type CDATSubHeader ** - so the array we're allocating here should be items of type CDATSubHeader * - but we pass sizeof(*cdat_table), which is sizeof(CDATSubHeader **), implying that we're allocating an array of CDATSubHeader ** It happens that sizeof(CDATSubHeader **) == sizeof(CDATSubHeader *) so nothing blows up, but this should be sizeof(**cdat_table). Avoid this excessively hard-to-understand code by using g_new0() instead, which will do the type checking for us. While we're here, we can drop the useless check against failure, as g_malloc0() and g_new0() never fail. This fixes Coverity issue CID 1508120. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Jonathan Cameron --- Disclaimer: I have not tested this beyond any testing you get from 'make check' and 'make check-avocado'. --- hw/pci-bridge/cxl_upstream.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hw/pci-bridge/cxl_upstream.c b/hw/pci-bridge/cxl_upstream.c index ef47e5d6253..9159f48a8cb 100644 --- a/hw/pci-bridge/cxl_upstream.c +++ b/hw/pci-bridge/cxl_upstream.c @@ -274,10 +274,7 @@ static int build_cdat_table(CDATSubHeader ***cdat_table, void *priv) }; } - *cdat_table = g_malloc0(sizeof(*cdat_table) * CXL_USP_CDAT_NUM_ENTRIES); - if (!*cdat_table) { - return -ENOMEM; - } + *cdat_table = g_new0(CDATSubHeader *, CXL_USP_CDAT_NUM_ENTRIES); /* Header always at start of structure */ (*cdat_table)[CXL_USP_CDAT_SSLBIS_LAT] = g_steal_pointer(&sslbis_latency);