From nobody Wed May 15 19:12:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1689675242; cv=none; d=zohomail.com; s=zohoarc; b=eTafoFbMdD/q1kSLwyW09XaCAk6DpGkWUTZpXyRZ1mVqETmx/qIgVsQehXzDqW4F6BSVQUz2387v8KKhpkTXT4eh7ZnU1l5peonszQ8P8Zi+21X0+P+tCcoB3WJHTGhT0JV8Xu8qbky4h/yafqQnVVeLP4JZWfSPbWUE04cbUxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689675242; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=SxF+adkG9POmfvABIs1cEVjtEat+n4+pscBvBaP5wS0=; b=HiXJwXeUHhg9F0k/n4eOJvy/ZgoNEOqxZbqr4roSZUuGurhW6KJfFkauuKx1QAeNERUuE/jNqhRpD7UF1QxWtY6QlAXxiZ/a2bkn7gKMjp+X2RGI7HZ4hj6KasB5taBIi4z7NF7FgP69NBnmYBRwhl4nLti4+L1frsvigd661zM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1689675242027420.56391218748035; Tue, 18 Jul 2023 03:14:02 -0700 (PDT) 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) 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) 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-Google-Smtp-Source: APBJJlHYD5rlhNoq8y/xJtONXF6Wi45wbeckvcODwRaJ9KcNVxLwsrr0mQqiVmFxSRheK3RMEcQ4tw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1689675243786100003 Content-Type: text/plain; charset="utf-8" In build_cdat_table() we do: *cdat_table =3D 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 **) =3D=3D 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: Jonathan Cameron Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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_tabl= e, void *priv) }; } =20 - *cdat_table =3D g_malloc0(sizeof(*cdat_table) * CXL_USP_CDAT_NUM_ENTRI= ES); - if (!*cdat_table) { - return -ENOMEM; - } + *cdat_table =3D g_new0(CDATSubHeader *, CXL_USP_CDAT_NUM_ENTRIES); =20 /* Header always at start of structure */ (*cdat_table)[CXL_USP_CDAT_SSLBIS_LAT] =3D g_steal_pointer(&sslbis_lat= ency); --=20 2.34.1